To Go Back to Source Code Page, click here.

import java.applet.Applet;
import java.awt.*;
import gjt.Box;
import gjt.Border;
import gjt.ThreeDBorder;
import gjt.Separator;
import gjt.Etching;

/**
 * This class will display boarded gjt components in a frame in order to present
        the results.
        Version 1 will use the default boarder layout manager to display the gjt boarded components; version
        2 and maybe 3 will deal with a more sophisticated layout
        Version 3 will display the results of difference thresholds.
        Version 4 finishes Ponzo--results window is complete.
        Version 6 implements printing and saving capability
   


 * @version 6.00 January 20, 1997
 * @author Christopher Currie
 * @see myTextField
 * @see myList
 * @see Output
 */
public class Results7 extends Frame {

private Button finished, printsave;
private Ponzo7 myApplet;
private Output output;
private double [][] ascTrials;
private double [][] decTrials;
private double avgLTAsc, avgUTAsc, avgPSEAsc;
private double avgLTDec, avgUTDec, avgPSEDec;
private double avgLT, avgUT, avgPSE;
private int n; // number of asc or dec trials

    /**
      * This constructor collects all DVs and initializes various objects used
             to display results in a java window.

      * @param asc holds individual ascending trial data: lower & upper threshold & PSE
      * @param meanLTAsc holds average lower threshold for ascending type of data.
      * @param meanUTAsc holds average upper threshold for ascending type of data.
      * @param meanPSEAsc average point of subjective equality for ascending type of data.
      * @param dec holds individual decending trial data: lower & upper threshold & PSE
      * @param meanLTDec holds average lower threshold for decending type of data.
      * @param meanUTDec holds average upper threshold for decending type of data.
      * @param meanPSEDec average point of subjective equality for decending type of data.
      * @param meanLT lower threshold for all trials.
      * @param meanUT upper threshold for all trials.
      * @param meanPSE point of subjective equality for all trials.
    */
    public Results7(double asc[][], double meanLTAsc, double meanUTAsc, double meanPSEAsc,
                    double dec[][], double meanLTDec, double meanUTDec, double meanPSEDec,
                    double meanLT, double meanUT, double meanPSE, int totalNumTrials, Ponzo7 a) {
    /* Start local variables */

       Panel northPanel, southPanel;
       GridBagLayout gbl = new GridBagLayout();
       GridBagConstraints gbc = new GridBagConstraints();
       Label dv, top;
       Separator separator = new Separator(Etching.OUT);

    /* End local variables */

       //myApplet = a;
       output = new Output(a);

       // copy DVs into class variables
       n = totalNumTrials/2;
       ascTrials = new double [n][4];
       decTrials = new double [n][4];
       for ( int i = 0; i < (totalNumTrials/2); i++ ){
            ascTrials[i][0] = asc[i][0];
            ascTrials[i][1] = asc[i][1];
            ascTrials[i][2] = asc[i][2];
            ascTrials[i][3] = asc[i][3];
            decTrials[i][0] = dec[i][0];
            decTrials[i][1] = dec[i][1];
            decTrials[i][2] = dec[i][2];
            decTrials[i][3] = dec[i][3];
       }
       avgLTAsc = meanLTAsc;
       avgUTAsc = meanUTAsc;
       avgPSEAsc = meanPSEAsc;
       avgLTDec = meanLTDec;
       avgUTDec = meanUTDec;
       avgPSEDec = meanPSEDec;
       avgLT = meanLT;
       avgUT = meanUT;
       avgPSE = meanPSE;

       // top level layout manager (for top level container: this frame)
       // this manager will layout the 2 panels
       setLayout( gbl );

       top = new Label("THRESHOLD RESULTS:");
       dv = new Label(", Point of Subjective Equality");
       //gbc.weightx = gbc.weighty = 100;
       gbc.gridwidth = GridBagConstraints.REMAINDER; // place labels in one colunm
       gbc.anchor = GridBagConstraints.CENTER; // position label in center of grid cell (as of 11/26/96, this doesn't work)
       gbl.setConstraints(top,gbc); // attach constraint settings to dv
       add(top);
       gbl.setConstraints(dv,gbc); // attach constraint settings to dv
       add(dv);

       gbc.insets = new Insets(0,0,10,0); // add space between bottom of separator and next label
       gbc.fill = GridBagConstraints.HORIZONTAL; // fill in horizontally
       // separator will be anchored in the CENTER--gcb is a "state machine"
       gbl.setConstraints(separator,gbc); // attach constraint settings to separator
       add(separator);

       gbc.insets = new Insets(5,0,5,0); // (t,l,b,r) add space between panels
       gbc.gridwidth = GridBagConstraints.REMAINDER; // place panels in one colunm
       gbc.anchor = GridBagConstraints.CENTER; // position panels in center of grid cell (as of 11/26/96, this doesn't work)

       // northPanel--title of window and thresholds for individual trials
       northPanel = MakeNorthPanel(asc, dec, totalNumTrials/2);
       gbl.setConstraints(northPanel,gbc);
       add(northPanel);

       // southPanel--mean ascending, descending, and absolute threshold values
       southPanel = MakeSouthPanel(meanLTAsc, meanUTAsc, meanPSEAsc, meanLTDec, meanUTDec, meanPSEDec, meanLT, meanUT, meanPSE);
       gbl.setConstraints(southPanel,gbc);
       add(southPanel);

       finished = new Button("Finished");
       gbc.fill = GridBagConstraints.VERTICAL; // fill in vertical
       gbl.setConstraints(finished,gbc);
       add(finished);
       printsave = new Button("Print/Save");
       gbl.setConstraints(printsave,gbc);
       add(printsave);



    }

    private Panel MakeSouthPanel(double meanLTAsc, double meanUTAsc, double meanPSEAsc,
                                 double meanLTDec, double meanUTDec, double meanPSEDec,
                                 double meanLT, double meanUT, double meanPSE){
    /* Start local variables */

       Box ascTextBox, desTextBox, allTextBox;
       ThreeDBorder ascendText, descendText, allText;
       Label meanA, meanD, mean;
       Panel southPanel = new Panel();
       GridBagLayout gbl = new GridBagLayout();
       GridBagConstraints gbc = new GridBagConstraints();
       Separator separator = new Separator(Etching.OUT);
       String mA, mD, m, forSettingWidth;

    /* End local variables */

       southPanel.setLayout( gbl );

       forSettingWidth = "<9999%, 9999%>, 9999%"; // longest possible list entry

       mA = "  <" + Double.toString(meanLTAsc) + "%, " + Double.toString(meanUTAsc) + "%>, " + Double.toString(meanPSEAsc) + "%";
       mD = "  <" + Double.toString(meanLTDec) + "%, " + Double.toString(meanUTDec) + "%>, " + Double.toString(meanPSEDec) + "%";
       m = "  <" + Double.toString(meanLT) + "%, " + Double.toString(meanUT) + "%>, " + Double.toString(meanPSE) + "%";

      // make bordered components

       ascendText = new ThreeDBorder(new myTextField(mA,forSettingWidth),3,4);
       descendText = new ThreeDBorder(new myTextField(mD,forSettingWidth),3,4);
       allText = new ThreeDBorder(new myTextField(m,forSettingWidth),3,4);
       ascendText.inset();descendText.inset();allText.inset();  // set to display as inset
       ascTextBox = new Box(ascendText,"Ascending Trials");
       desTextBox = new Box(descendText,"Descending Trials");
       allTextBox = new Box(allText,"All Trials");
       mean = new Label("TRIAL TYPE RESULTS AND OVERALL RESULTS:");

       // place label
       gbc.anchor = GridBagConstraints.CENTER; // position them in the center of grid cell
       gbc.gridwidth = GridBagConstraints.REMAINDER;
       gbl.setConstraints(mean, gbc);
       southPanel.add(mean);

       // place bordered textfields
       gbc.gridwidth = GridBagConstraints.RELATIVE; // place the 2 text fields in a row
       gbl.setConstraints(ascTextBox, gbc);
       southPanel.add(ascTextBox);
       gbc.gridwidth = GridBagConstraints.REMAINDER; // place the result box below ascTextBox & desTextBox
       gbl.setConstraints(desTextBox, gbc);
       southPanel.add(desTextBox);
       gbl.setConstraints(allTextBox,gbc);
       southPanel.add(allTextBox);

       return southPanel;
    }

    private Panel MakeNorthPanel(double asc[][], double dec[][], int numTrials){
    /* Start local variables */

       Label list_t1;
       Panel northPanel = new Panel();
       GridBagLayout gbl = new GridBagLayout();
       GridBagConstraints gbc = new GridBagConstraints();
       ThreeDBorder ascendBorder, descendBorder;
       Box ascendBox, descendBox;

    /* End local variables */

       northPanel.setLayout(gbl);

       gbc.gridwidth = GridBagConstraints.REMAINDER; // place components in one colunm
       gbc.anchor = GridBagConstraints.CENTER; // position components in center of grid cell (as of 11/26/96, this doesn't work)

       list_t1 = new Label("RESULTS FROM INDIVIDUAL TRIALS:");
       gbc.insets = new Insets(0,0,0,0); // reset
       //label will be centered
       // the previous fill needs to be over-ridden or the label will NOT centered--as of 11/26/96, I don't understand this
       gbc.fill = GridBagConstraints.NONE;
       gbl.setConstraints(list_t1,gbc); // attach constraint settings to list_t1
       northPanel.add(list_t1);


       //make a place lists
       ascendBorder = (ThreeDBorder)makeThreeDBorderedList(asc, numTrials);
       descendBorder = (ThreeDBorder)makeThreeDBorderedList(dec, numTrials);
       //ascendBorder.setLineColor(Color.blue);
       //descendBorder.setLineColor(Color.red);
       ascendBox = new Box(ascendBorder,"Ascending Trials");
       descendBox = new Box(descendBorder,"Descending Trials");
       gbc.gridwidth = GridBagConstraints.RELATIVE; // place labels in one colunm
       // position of list will be in center of grid cell
       gbl.setConstraints(ascendBox,gbc);
       gbl.setConstraints(descendBox,gbc);
       northPanel.add(ascendBox);
       northPanel.add(descendBox);

       return northPanel;
    }

    private Border makeThreeDBorderedList(double array[][], int index) {
    /* Start local variables */

       int i;
       String trialField;

    /* End local variables */

        trialField = "Trial 9999: <9999%, 9999%>, 9999%"; // longest possible list entry--assuming scoll bars

        myList list = new myList(5, true, trialField);

        for ( i = 0; i < index; i++ ){
             trialField = "Trial " + Integer.toString((int)array[i][3]) + ": <" + Double.toString(array[i][0]) + "%, "
                                                             + Double.toString(array[i][1]) + "%>, "
                                                             + Double.toString(array[i][2]) + "%";
             list.addItem( trialField );
        }

        return new ThreeDBorder(list,5);
    }

    /**
       The method shows the results window. It first moves to position (50,50)
       in order to somewhat center the results window

     * @param NULL no parameters
     * @return void
    */
    public synchronized void show() {
      move(50, 50);
          super.show();
    }

    /**
      * Event handler--hides window and captures event to open a browser window.

     * @param Event event object attached to the components in the results window
     * @return boolean true if event is handled here, else the parent object will handle the event
    */
    public boolean handleEvent(Event event) {

      if (event.id == Event.WINDOW_DESTROY) {
            hide();
          return true;
      }
      if (event.id == Event.ACTION_EVENT && event.target == finished) {
            hide();
            return true;
      }
      if (event.id == Event.ACTION_EVENT && event.target == printsave) {
            output.OpenBrowserWindow(); // open a browser window
            output.WriteToBrowserWindow(ascTrials, avgLTAsc, avgUTAsc, avgPSEAsc,
                                        decTrials, avgLTDec, avgUTDec, avgPSEDec,
                                        avgLT, avgUT, avgPSE, n);
            output.CloseBrowserWindow();

            return true;
      }

      return super.handleEvent(event);
    }




}

/**
 *  This class extends the List class.  This is required because the width of the list
   window needs to be a function of the list items.  This class over-rides the minimumSize()
   method to specify the size of the list window.
   


 * @version 1.00 January 3, 1997
 * @author Christopher Currie
 */
class myList extends List {
    private FontMetrics fm; // all components have a FontMetrics class assoicated with them.
    private String testString; // width of list window is a function of the width (in pixels) of this string
    private int rows;

    /**
      * This construction instanciates a List object and saves information needed to set the size of the
        list window.

    * @param r specifies the number of visual rows
    * @param v specifies whether or not items can be selected in the list
    * @param s is used to determine the width of the list window.
    */
    public myList( int r, boolean v, String s ){
           super( r, v );
           testString = s;
           rows = r;
    }

    /**
       Over-riding the default minimumSize method in order to set my own size.  Specifically,
      the width of the testString is determined via the the FontMetrics class, as well as it's
      height. The layout manager will call this when it places the List.

    * @param null no parameters
    * @return Dimension is the size in pixels of the list window (including any vertical scroll bar)
    */
    public Dimension minimumSize(){
        int width, len;
        fm = getFontMetrics(getFont()); // get metrics of whatever font is being used

        width = fm.stringWidth(testString); // width in pixels
        len = rows * fm.getHeight(); // rows is the number of visible rows

        Dimension d = new Dimension( width, len );

        return d;
    }
}
/**
 *  This class extends the TextField class.  This is required because the width of this component
   window needs to be a function of the string it displays.  This class over-rides the minimumSize()
   method to specify the size of the display window.
   


 * @version 1.00 January 3, 1997
 * @author Christopher Currie
 */
class myTextField extends TextField {
    private FontMetrics fm;
    private String test;

    /**
      * This construction instanciates a TextField object and saves information needed to set the size of the
        display window.

    * @param dv is the text to be displayed in the display window.
    * @param t is the string used to determine the size of the display window.
    */
    public myTextField( String dv, String t ){
        super( dv, 0 );  // the 0 value will be overriden when the layout manager calls minimunSize()
        test = t;
        super.setEditable(false); // fields should not be editable
    }

    /**
       Over-riding the default minimumSize method in order to set my own size.  Specifically,
      the width of the testString is determined via the the FontMetrics class, as well as it's
      height.  The layout manager will call this when it places the TextField.

    * @param null no parameters
    * @return Dimension is the size in pixels of the display window.
    */
    public Dimension minimumSize(){
        int width, len;
        fm = getFontMetrics(getFont());

        width = fm.stringWidth(test);
        len = 2*fm.getHeight();

        Dimension d = new Dimension( width, len );

        return d;
    }

}