Annotation of capa/capa51/JavaTools/ExmPanel.java, revision 1.1
1.1 ! albertel 1: class ExmPanel extends Panel
! 2: implements ActionListener,
! 3: AdjustmentListener {
! 4: TScore controller;
! 5: TextField exT_ex, exT_pc;
! 6: Scrollbar sB_ex, sB_pc;
! 7: Label sumL;
! 8: int max = 100;
! 9: int block = 1;
! 10: int show_pc, exam_ex, epc_ex;
! 11: float s_ex, f_ex, s_pc, f_pc;
! 12: float c_factor;
! 13:
! 14: // exam_type 0 Final
! 15: // 1, 2, 3, 4
! 16: ExmPanel(TScore u,int exam_type,int exam_x,int show_epc,int epc_x,
! 17: float a,float b,float w,float m,float n,float ex_default) {
! 18: GridBagConstraints c = new GridBagConstraints();
! 19: GridBagLayout gridbag = new GridBagLayout();
! 20: setLayout(gridbag);
! 21: Label tL;
! 22: float exam_ratio, epc_ratio;
! 23: float sum;
! 24: int tmp_i;
! 25:
! 26: controller = u;
! 27: c_factor = w;
! 28: show_pc = show_epc;
! 29: exam_ex = exam_x;
! 30: epc_ex = epc_x;
! 31: s_ex = a; f_ex = b; s_pc = m; f_pc = n;
! 32: //Set up default layout constraints.
! 33: c.fill = GridBagConstraints.NONE;
! 34:
! 35: //Add the label. It displays this panel's title, centered.
! 36: if(exam_type == 0 ) { // Final exam
! 37: tL = new Label("Final", Label.LEFT);
! 38: } else {
! 39: tL = new Label("Exam " + exam_type, Label.LEFT);
! 40: }
! 41: c.anchor = GridBagConstraints.WEST;
! 42: c.gridwidth = 1;
! 43: c.gridx = 0;
! 44: c.gridy = 0;
! 45: gridbag.setConstraints(tL, c);
! 46: add(tL);
! 47: c.anchor = GridBagConstraints.CENTER;
! 48:
! 49: if( exam_x == 0 ) {
! 50: // exam not extrapolated
! 51: exam_ratio = (float)s_ex / (float)f_ex;
! 52: tmp_i = (int) (10000 * exam_ratio );
! 53: float percent = (float)tmp_i / (float)100.0;
! 54: String cs = " " + a + "/" + b + " = " + percent + " %";
! 55: Label cL = new Label(cs, Label.CENTER);
! 56: c.gridwidth = 2;
! 57: c.gridx = 1;
! 58: c.gridy = 0;
! 59: gridbag.setConstraints(cL, c);
! 60: add(cL);
! 61: } else {
! 62: // extrapolate exam
! 63: exam_ratio = ex_default;
! 64: exT_ex = new TextField("0", 3);
! 65: exT_ex.setName("EXAM");
! 66: c.gridwidth = 1; //The default value.
! 67: c.gridx = 2;
! 68: c.gridy = 0;
! 69: gridbag.setConstraints(exT_ex, c);
! 70: add(exT_ex);
! 71: exT_ex.addActionListener(this);
! 72:
! 73: sB_ex = new Scrollbar(Scrollbar.HORIZONTAL);
! 74: sB_ex.setName("EXAMS");
! 75: sB_ex.setMaximum(max + 10);
! 76: sB_ex.setBlockIncrement(block);
! 77: c.gridwidth = 2;
! 78: c.gridx = 3;
! 79: c.gridy = 0;
! 80: gridbag.setConstraints(sB_ex, c);
! 81: add(sB_ex);
! 82: sB_ex.addAdjustmentListener(this);
! 83: }
! 84: epc_ratio = exam_ratio;
! 85: if(show_pc == 1) {
! 86: if(epc_x == 1) {
! 87: epc_ratio = exam_ratio;
! 88: } else {
! 89: epc_ratio = (float)s_pc / (float)f_pc;
! 90: }
! 91: if( epc_ratio > exam_ratio ) {
! 92: tmp_i= (int)(10000 * (exam_ratio + c_factor * (epc_ratio - exam_ratio)));
! 93: sum = (float)tmp_i / (float)100.0;
! 94: } else {
! 95: tmp_i= (int)(10000 * exam_ratio);
! 96: sum = (float)tmp_i / (float)100.0;
! 97: }
! 98: } else {
! 99: tmp_i= (int)(10000 * exam_ratio);
! 100: sum = (float)tmp_i / (float)100.0;
! 101: }
! 102:
! 103: Label sL = new Label("subtotal=", Label.RIGHT);
! 104: c.gridwidth = 1;
! 105: c.gridx = 5;
! 106: c.gridy = 0;
! 107: gridbag.setConstraints(sL, c);
! 108: add(sL);
! 109:
! 110: String s = " " + sum + "%";
! 111: sumL = new Label(s, Label.CENTER);
! 112: c.anchor = GridBagConstraints.EAST;
! 113: c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row.
! 114: c.gridx = 6;
! 115: c.gridy = 0;
! 116: gridbag.setConstraints(sumL, c);
! 117: add(sumL);
! 118: c.anchor = GridBagConstraints.CENTER;
! 119:
! 120: if( show_epc == 1 ) {
! 121: Label eL = new Label("Correction " + exam_type, Label.LEFT);
! 122: c.gridwidth = 1;
! 123: c.gridx = 0;
! 124: c.gridy = 1;
! 125: gridbag.setConstraints(eL, c);
! 126: add(eL);
! 127: if( epc_x == 0 ) {
! 128: float ratio = (float) ( s_pc / f_pc);
! 129: tmp_i = (int) (10000 * ratio );
! 130: float percent = (float)tmp_i / (float)100.0;
! 131: String cs = " " + s_pc + "/" + f_pc + " = " + percent + " %";
! 132: Label cL = new Label(cs, Label.CENTER);
! 133: c.gridwidth = 2;
! 134: c.gridx = 1;
! 135: c.gridy = 1;
! 136: gridbag.setConstraints(cL, c);
! 137: add(cL);
! 138: } else {
! 139: exT_pc = new TextField("0", 3);
! 140: exT_pc.setName("PC");
! 141: c.anchor = GridBagConstraints.EAST;
! 142: c.gridwidth = 1; //The default value.
! 143: c.gridx = 2;
! 144: c.gridy = 1;
! 145: gridbag.setConstraints(exT_pc, c);
! 146: add(exT_pc);
! 147: exT_pc.addActionListener(this);
! 148:
! 149: sB_pc = new Scrollbar(Scrollbar.HORIZONTAL);
! 150: sB_pc.setName("PCS");
! 151: sB_pc.setMaximum(max + 10);
! 152: sB_pc.setBlockIncrement(block);
! 153: c.gridwidth = GridBagConstraints.REMAINDER;
! 154: c.anchor = GridBagConstraints.CENTER;
! 155: c.fill = GridBagConstraints.HORIZONTAL;
! 156: // c.gridwidth = 2;
! 157: c.gridx = 3;
! 158: c.gridy = 1;
! 159: gridbag.setConstraints(sB_pc, c);
! 160: add(sB_pc);
! 161: sB_pc.addAdjustmentListener(this);
! 162: }
! 163: }
! 164: setExValue(exam_ratio,epc_ratio);
! 165: }
! 166: // Draws a box around this panel.
! 167: public void paint(Graphics g) {
! 168: Dimension d = getSize();
! 169: g.drawRect(0,0, d.width - 1, d.height - 1);
! 170: }
! 171: public Insets getInsets() {
! 172: return new Insets(5,5,5,8);
! 173: }
! 174: float getSubTotal() {
! 175: String s_str = sumL.getText().replace('%','\0').trim();
! 176: float s_real = Float.valueOf(s_str).floatValue();
! 177: return (s_real);
! 178: }
! 179: // entered into exT
! 180: public void actionPerformed(ActionEvent e) {
! 181: TextField source = (TextField)e.getSource();
! 182: String name = source.getName();
! 183: int tf = (int)Integer.valueOf(source.getText()).intValue();
! 184: if (tf > max)
! 185: tf = max;
! 186: if (tf < 0)
! 187: tf = 0;
! 188: if( name.equals(String.valueOf("EXAM")) ) {
! 189: sB_ex.setValue(tf);
! 190: exT_ex.setText(String.valueOf((int)tf));
! 191: } else {
! 192: sB_pc.setValue(tf);
! 193: exT_pc.setText(String.valueOf((int)tf));
! 194: }
! 195: recalcSumm();
! 196: }
! 197: // slider sB changed
! 198: public void adjustmentValueChanged(AdjustmentEvent e) {
! 199: Scrollbar source = (Scrollbar)e.getSource();
! 200: String name = source.getName();
! 201: int my_i = (int)source.getValue();
! 202:
! 203: if( name.equals(String.valueOf("EXAMS")) ) {
! 204: sB_ex.setValue(my_i);
! 205: exT_ex.setText(String.valueOf((int)my_i));
! 206: } else {
! 207: sB_pc.setValue(my_i);
! 208: exT_pc.setText(String.valueOf((int)my_i));
! 209: }
! 210: recalcSumm();
! 211: }
! 212: void recalcSumm() {
! 213: int tmp_i;
! 214: float exam , epc, sum;
! 215:
! 216: if( exam_ex == 1 ) {
! 217: tmp_i = (int)Integer.valueOf(exT_ex.getText()).intValue();
! 218: exam = (float) tmp_i / (float)100.0;
! 219: } else {
! 220: exam = (float)s_ex / (float)f_ex;
! 221: }
! 222: if( show_pc == 1 ) {
! 223: if(epc_ex == 1) {
! 224: tmp_i = (int)Integer.valueOf(exT_pc.getText()).intValue();
! 225: epc = (float) tmp_i / (float)100.0;
! 226: } else {
! 227: epc = (float)s_pc / (float)f_pc;
! 228: }
! 229: if( epc > exam ) {
! 230: tmp_i= (int)(10000 * (exam + c_factor * (epc - exam)));
! 231: sum = (float)tmp_i / (float)100.0;
! 232: } else {
! 233: tmp_i= (int)(10000 * exam);
! 234: sum = (float)tmp_i / (float)100.0;
! 235: }
! 236: } else {
! 237: tmp_i= (int)(10000 * exam);
! 238: sum = (float)tmp_i / (float)100.0;
! 239: }
! 240: sumL.setText(sum + "%");
! 241: controller.recalcTermScore();
! 242: }
! 243: void setExValue (float a, float b) {
! 244: int exm, epc;
! 245: exm = (int) (a*100.0);
! 246: epc = (int) (b*100.0);
! 247: if (exm > max)
! 248: exm = max;
! 249: if (exm < 0)
! 250: exm = 0;
! 251: if (epc > max)
! 252: epc = max;
! 253: if (epc < 0)
! 254: epc = 0;
! 255: if( exam_ex ==1 ) {
! 256: sB_ex.setValue(exm);
! 257: exT_ex.setText(String.valueOf(exm));
! 258: }
! 259: if( (show_pc == 1) && (epc_ex==1) ) {
! 260: sB_pc.setValue(epc);
! 261: exT_pc.setText(String.valueOf(epc));
! 262: }
! 263: }
! 264: }
! 265:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>