Diff for /capa/capa51/JavaTools/TScore.java between versions 1.1 and 1.2

version 1.1, 1999/11/29 19:45:13 version 1.2, 1999/11/29 19:56:28
Line 84  public void init() { Line 84  public void init() {
        S[idx]=(p==null)?1:Float.valueOf(p).floatValue();         S[idx]=(p==null)?1:Float.valueOf(p).floatValue();
        p=getParameter("F"+idx);         p=getParameter("F"+idx);
        F[idx] =(p==null)?1:Float.valueOf(p).floatValue();         F[idx] =(p==null)?1:Float.valueOf(p).floatValue();
        SF_ratio[idx] = (float) ((float)S[idx] / (float)F[idx]);         if ((float)F[idx] < 0.00000001) {
      SF_ratio[idx] = (float) 0.0;
          } else {
      SF_ratio[idx] = (float) ((float)S[idx] / (float)F[idx]);
          }
        int tmp_i = (int) (10000 * SF_ratio[idx] );         int tmp_i = (int) (10000 * SF_ratio[idx] );
        SF_percent[idx]= (float)tmp_i / (float)100.0;         SF_percent[idx]= (float)tmp_i / (float)100.0;
        if( idx == (Entry_cnt - 1) ) {         // final exam         if( idx == (Entry_cnt - 1) ) {         // final exam
Line 240  public void start() { Line 244  public void start() {
 public void stop()  {  }  public void stop()  {  }
   
 }  }
   class ExpPanel extends Panel
                        implements ActionListener,
                                    AdjustmentListener {
       TScore     controller;
       TextField  exT;
       Scrollbar  sB;
       Label      sumL;
       int        max = 100;
       int        block = 1;
       float      ff,ss;
       int        rr,cc;
   
       ExpPanel(TScore u,String t,
                int x,float a,float b,int m,int n) {
           GridBagConstraints   c = new GridBagConstraints();
           GridBagLayout        gridbag = new GridBagLayout();
           setLayout(gridbag);
           int tmp_i;
   
           controller = u;
           ss = a; ff = b; cc = m; rr = n;
           float sf_ratio =  (float)ss / (float)ff;
           tmp_i = (int)(10000 * sf_ratio);
           float sf_percent =  (float)tmp_i / (float)100.0;
           float sum_ratio = (float)(ss + ((float)rr*ff*sf_ratio/(float)cc)) / (float)(ff*(1.0 + (float)rr/(float)cc));
           tmp_i = (int)(10000 * sum_ratio);
           float sum_percent =  (float)tmp_i / (float)100.0;
   
           String cs = " " + ss + "/"  + ff; 
           cs = cs + " = " + sf_percent + "%";
           String r = "remaining " + rr + " sets at (%) ";
           String s = " " + sum_percent + "%";
   
           //Set up default layout constraints.
           c.fill = GridBagConstraints.NONE;
   
           Label tL = new Label(t, Label.LEFT);
           // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
           c.gridwidth = 1;
           c.gridx = 0;
           c.gridy = 0;
           gridbag.setConstraints(tL, c);
           add(tL);
           
           Label cL = new Label(cs, Label.CENTER);
           c.gridwidth = 2;
           c.gridx = 1;
           c.gridy = 0;
           gridbag.setConstraints(cL, c);
           add(cL);
   
           Label sL = new Label("subtotal=", Label.RIGHT);
           c.gridwidth = 1;
           c.gridx = 3;
           c.gridy = 0;
           gridbag.setConstraints(sL, c);
           add(sL);
   
           sumL = new Label(s, Label.RIGHT);
           c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
           c.gridx = 4;
           c.gridy = 0;
           gridbag.setConstraints(sumL, c);
           add(sumL);
           if(x==1) { 
             Label rL = new Label(r, Label.RIGHT);
             c.gridwidth = 2;
             c.gridx = 0;
             c.gridy = 1;
             gridbag.setConstraints(rL, c);
             add(rL);
   
             exT = new TextField("0", 3);
             c.anchor = GridBagConstraints.EAST;
             c.gridwidth = 1; //The default value.
             c.gridx = 2;
             c.gridy = 1;
             gridbag.setConstraints(exT, c);
             add(exT);
             exT.addActionListener(this);
             c.anchor = GridBagConstraints.CENTER;  // default
   
           //Add the slider.  It's horizontal, and it has the maximum
           //value specified by the instance variable max.  Its initial
           //and minimum values are the default (0).  A click increments
           //the value by block units.
             sB = new Scrollbar(Scrollbar.HORIZONTAL);
             sB.setMaximum(max + 10);
             sB.setBlockIncrement(block);
             // c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
             c.fill = GridBagConstraints.HORIZONTAL;
             c.gridwidth = 2;
             c.gridx = 3;
             c.gridy = 1;
             gridbag.setConstraints(sB, c);
             add(sB);
             sB.addAdjustmentListener(this);
             exT.setText(String.valueOf(sf_percent));
             sB.setValue((int)sf_percent);
           }
   
       }
       // Draws a box around this panel. 
       public void paint(Graphics g) {
           Dimension d = getSize();
           g.drawRect(0,0, d.width - 1, d.height - 1);
       }
       public Insets getInsets() {
           return new Insets(5,5,5,8);
       }
       float  getSubTotal() {
           String s_str = sumL.getText().replace('%','\0').trim();
           float  s_real = Float.valueOf(s_str).floatValue();
           return (s_real);
       }
       double getValue() {
           double f;
           try {
               f = (double)Double.valueOf(exT.getText()).doubleValue();
           } catch (java.lang.NumberFormatException e) {
               f = 0.0;
           }
           return f;
       }
       // entered into exT
       public void actionPerformed(ActionEvent e) {
           int tf = (int) getValue();
           if (tf > max)
               tf = max;
           if (tf < 0)
               tf = 0;
           sB.setValue(tf);
           exT.setText(String.valueOf((int)tf));
           recalcSumm(tf);
       }    
       //  slider sB changed
       public void adjustmentValueChanged(AdjustmentEvent e) {
           Scrollbar source = (Scrollbar)e.getSource();
              int   my_i =  (int)source.getValue();
              exT.setText(String.valueOf(e.getValue()));
              recalcSumm(my_i);
       }
       void  recalcSumm(int tf) {
           float my_r = (float) tf / (float)100.0;
           int  tmp_i= (int)(10000*(ss+(rr*ff*my_r/cc))/(float)(ff*(1.0+rr/cc)));
           float sum  = (float)tmp_i / (float)100.0;
           sumL.setText(sum + "%");
           controller.recalcTermScore();
       }
       // Set the values in the slider and text field. 
       void setValue(double f) {
           setSliderValue(f);
           exT.setText(String.valueOf((float)f));
       }
       void setSliderValue(double f) {
           int sliderValue = (int)f;
   
           if (sliderValue > max)
                  sliderValue = max;
           if (sliderValue < 0)
               sliderValue = 0;
           sB.setValue(sliderValue);
           
       }
   }
   class ExmPanel extends Panel
                        implements ActionListener,
                                   AdjustmentListener {
       TScore     controller;
       TextField  exT_ex, exT_pc;
       Scrollbar  sB_ex,  sB_pc;
       Label      sumL;
       int        max = 100;
       int        block = 1;
       int        show_pc, exam_ex, epc_ex;
       float      s_ex, f_ex, s_pc, f_pc;
       float      c_factor;
   
       // exam_type  0  Final
       //            1, 2, 3, 4 
       ExmPanel(TScore u,int exam_type,int exam_x,int show_epc,int epc_x,
                float a,float b,float w,float m,float n,float ex_default) {
           GridBagConstraints   c = new GridBagConstraints();
           GridBagLayout        gridbag = new GridBagLayout();
           setLayout(gridbag);
           Label  tL;
           float  exam_ratio, epc_ratio;
           float  sum;
           int    tmp_i;
   
           controller = u; 
           c_factor   = w;
           show_pc = show_epc;
           exam_ex = exam_x;
           epc_ex  = epc_x;
           s_ex = a; f_ex = b; s_pc = m; f_pc = n;
           //Set up default layout constraints.
           c.fill = GridBagConstraints.NONE;
   
           //Add the label.  It displays this panel's title, centered.
           if(exam_type == 0 ) { // Final exam
              tL = new Label("Final", Label.LEFT);
           } else {
              tL = new Label("Exam " + exam_type, Label.LEFT);
           }
           c.anchor = GridBagConstraints.WEST;
           c.gridwidth = 1;
           c.gridx = 0;
           c.gridy = 0;
           gridbag.setConstraints(tL, c);
           add(tL);
           c.anchor = GridBagConstraints.CENTER;
   
           if( exam_x == 0 ) {
             // exam not extrapolated
             exam_ratio = (float)s_ex / (float)f_ex;
             tmp_i = (int) (10000 * exam_ratio );
             float percent = (float)tmp_i / (float)100.0;
             String cs =  " " + a + "/" + b + " = " + percent + " %";
             Label  cL = new Label(cs, Label.CENTER);
             c.gridwidth = 2;
             c.gridx = 1;
             c.gridy = 0;
             gridbag.setConstraints(cL, c);
             add(cL);
           } else {
             // extrapolate exam
             exam_ratio = ex_default;
             exT_ex = new TextField("0", 3);
             exT_ex.setName("EXAM");
             c.gridwidth = 1; //The default value.
             c.gridx = 2;
             c.gridy = 0;
             gridbag.setConstraints(exT_ex, c);
             add(exT_ex);
             exT_ex.addActionListener(this);
   
             sB_ex = new Scrollbar(Scrollbar.HORIZONTAL);
             sB_ex.setName("EXAMS");
             sB_ex.setMaximum(max + 10);
             sB_ex.setBlockIncrement(block);
             c.gridwidth = 2;
             c.gridx = 3;
             c.gridy = 0;
             gridbag.setConstraints(sB_ex, c);
             add(sB_ex);
             sB_ex.addAdjustmentListener(this);
           }
           epc_ratio = exam_ratio;
           if(show_pc == 1) {
             if(epc_x == 1) {
               epc_ratio = exam_ratio;
             } else {
               epc_ratio = (float)s_pc / (float)f_pc;
             }
             if( epc_ratio > exam_ratio ) {
               tmp_i= (int)(10000 * (exam_ratio + c_factor * (epc_ratio - exam_ratio)));
               sum  = (float)tmp_i / (float)100.0;
             } else {
               tmp_i= (int)(10000 * exam_ratio);
               sum  = (float)tmp_i / (float)100.0;
             }
           } else { 
             tmp_i= (int)(10000 * exam_ratio);
             sum  = (float)tmp_i / (float)100.0;
           }
   
           Label sL = new Label("subtotal=", Label.RIGHT);
           c.gridwidth = 1;
           c.gridx = 5;
           c.gridy = 0;
           gridbag.setConstraints(sL, c);
           add(sL);
   
           String  s = " " + sum + "%";
           sumL = new Label(s, Label.CENTER);
           c.anchor = GridBagConstraints.EAST; 
           c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
           c.gridx = 6;
           c.gridy = 0;
           gridbag.setConstraints(sumL, c);
           add(sumL);
           c.anchor = GridBagConstraints.CENTER; 
   
           if( show_epc == 1 ) {
              Label eL = new Label("Correction " + exam_type, Label.LEFT);
              c.gridwidth = 1;
              c.gridx = 0;
              c.gridy = 1;
              gridbag.setConstraints(eL, c);
              add(eL);
              if( epc_x == 0 ) {
                float ratio = (float) ( s_pc / f_pc);
                tmp_i = (int) (10000 * ratio );
                float percent = (float)tmp_i / (float)100.0;
                String cs =  " " + s_pc + "/" + f_pc + " = " + percent + " %";
                Label  cL = new Label(cs, Label.CENTER);
                c.gridwidth = 2;
                c.gridx = 1;
                c.gridy = 1;
                gridbag.setConstraints(cL, c);
                add(cL);
              } else {
                exT_pc = new TextField("0", 3);
                exT_pc.setName("PC");
                c.anchor = GridBagConstraints.EAST;
                c.gridwidth = 1; //The default value.
                c.gridx = 2;
                c.gridy = 1;
                gridbag.setConstraints(exT_pc, c);
                add(exT_pc);
                exT_pc.addActionListener(this);
   
                sB_pc = new Scrollbar(Scrollbar.HORIZONTAL);
                sB_pc.setName("PCS");
                sB_pc.setMaximum(max + 10);
                sB_pc.setBlockIncrement(block);
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.anchor = GridBagConstraints.CENTER;
                c.fill = GridBagConstraints.HORIZONTAL;
                // c.gridwidth = 2;
                c.gridx = 3;
                c.gridy = 1;
                gridbag.setConstraints(sB_pc, c);
                add(sB_pc);
                sB_pc.addAdjustmentListener(this);
              }
           }
           setExValue(exam_ratio,epc_ratio);
       }
       // Draws a box around this panel. 
       public void paint(Graphics g) {
           Dimension d = getSize();
           g.drawRect(0,0, d.width - 1, d.height - 1);
       }
       public Insets getInsets() {
           return new Insets(5,5,5,8);
       }
       float  getSubTotal() {
           String s_str = sumL.getText().replace('%','\0').trim();
           float  s_real = Float.valueOf(s_str).floatValue();
           return (s_real);
       }
       // entered into exT
       public void actionPerformed(ActionEvent e) {
           TextField source = (TextField)e.getSource();
           String name = source.getName();
           int tf = (int)Integer.valueOf(source.getText()).intValue();
           if (tf > max)
               tf = max;
           if (tf < 0)
               tf = 0;
           if( name.equals(String.valueOf("EXAM")) ) {
             sB_ex.setValue(tf);
             exT_ex.setText(String.valueOf((int)tf));
           } else {
             sB_pc.setValue(tf);
             exT_pc.setText(String.valueOf((int)tf));
           }
           recalcSumm();
       }    
       //  slider sB changed
       public void adjustmentValueChanged(AdjustmentEvent e) {
           Scrollbar source = (Scrollbar)e.getSource();
           String    name = source.getName();
              int    my_i =  (int)source.getValue();
           
           if( name.equals(String.valueOf("EXAMS")) ) {
             sB_ex.setValue(my_i);
             exT_ex.setText(String.valueOf((int)my_i));
           } else {
             sB_pc.setValue(my_i);
             exT_pc.setText(String.valueOf((int)my_i));
           }
           recalcSumm();
       }
       void  recalcSumm() {
           int   tmp_i;
           float exam , epc, sum;
           
           if( exam_ex == 1 ) {
              tmp_i = (int)Integer.valueOf(exT_ex.getText()).intValue();
              exam = (float) tmp_i / (float)100.0;
           } else {
              exam = (float)s_ex / (float)f_ex;
           }
           if( show_pc == 1 ) {
             if(epc_ex == 1) {
               tmp_i = (int)Integer.valueOf(exT_pc.getText()).intValue();
               epc = (float) tmp_i / (float)100.0;
             } else {
               epc = (float)s_pc / (float)f_pc;
             }
             if( epc > exam ) {
               tmp_i= (int)(10000 * (exam + c_factor * (epc - exam)));
               sum  = (float)tmp_i / (float)100.0;
             } else {
               tmp_i= (int)(10000 * exam);
               sum  = (float)tmp_i / (float)100.0;
             }
           } else {
             tmp_i= (int)(10000 * exam);
             sum  = (float)tmp_i / (float)100.0;
           }
           sumL.setText(sum + "%");
           controller.recalcTermScore();
       }
       void setExValue (float a, float b) {
           int  exm, epc;
           exm = (int) (a*100.0); 
           epc = (int) (b*100.0); 
           if (exm > max)
               exm = max;
           if (exm < 0)
               exm = 0;
           if (epc > max)
               epc = max;
           if (epc < 0)
               epc = 0;
           if( exam_ex ==1 ) {
             sB_ex.setValue(exm);
             exT_ex.setText(String.valueOf(exm));
           }
           if( (show_pc == 1) && (epc_ex==1) ) {
             sB_pc.setValue(epc);
             exT_pc.setText(String.valueOf(epc));
           }
        }
   }
   

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>