1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.reportcalculator.expression.*; 4 import com.calipso.reportgenerator.common.InfoException; 5 import com.calipso.reportgenerator.common.ShowExceptionMessageDialog; 6 7 import javax.swing.*; 8 import java.awt.*; 9 import java.awt.event.ActionListener ; 10 import java.awt.event.ActionEvent ; 11 import java.text.MessageFormat ; 12 import java.util.Vector ; 13 14 17 18 public class ChoosSemaphoreSelection extends javax.swing.JDialog { 19 private Color bgColor; 20 private ColorCondition resultColorCondition; 21 private JPanel jPanel4; 22 private JLabel colorjLabel; 23 private JLabel valuejLabel; 24 private JButton okjButton; 25 private JTextField fromjTextField; 26 private JRadioButton greaterOrEqualTojRadioButton; 27 private JRadioButton greaterThanjRadioButton; 28 private JPanel jPanel3; 29 private Color storedColor; 30 private JButton canceljButton; 31 private JTextField colorjTextField; 32 private JRadioButton lessThanjRadioButton; 33 private JPanel jPanel2; 34 private JPanel jPanel5; 35 private ButtonGroup operatorbuttonGroup; 36 private JTextField tojTextField; 37 private JButton colorjButton; 38 private JPanel jPanel7; 39 private JLabel tojLabel; 40 private JPanel jPanel1; 41 private JPanel jPanel6; 42 private JRadioButton lessOrEqualTojRadioButton; 43 private JLabel fromjLabel; 44 private JTextField valuejTextField; 45 private JRadioButton equalTojRadioButton; 46 private JTabbedPane tabPanel; 47 private int seleccionRadioButton; 48 private MetricState metricState; 49 50 51 57 public static ColorCondition newColorCondition(Frame owner, MetricState metricState, ColorCondition condition) { 58 ChoosSemaphoreSelection dialog = new ChoosSemaphoreSelection(owner, metricState, condition); 59 ColorCondition colorCondition = dialog.execute(); 60 dialog.dispose(); 61 return colorCondition; 62 } 63 64 68 public ColorCondition execute() { 69 this.setVisible(true); 70 return this.resultColorCondition; 71 } 72 73 78 public ChoosSemaphoreSelection(Frame owner, MetricState metricState, ColorCondition condition) { 79 super(owner, true); 80 this.metricState = metricState; 81 resultColorCondition = null; 82 initComponents(); 83 setValuesComponents(condition); 84 } 85 86 90 private void setValuesComponents(ColorCondition condition) { 91 if(condition != null) { 92 storedColor = condition.getColor(); 93 bgColor = storedColor; 94 Expression expression = condition.getExpression(); 95 colorjTextField.setBackground(storedColor); 96 if(expression instanceof GreaterThan) { 97 greaterThanjRadioButton.setSelected(true); 98 greaterThanjRadioButtonMousePressed(); 99 Float aFloat = Float.valueOf(expression.getArguments() [1].toString()); 100 valuejTextField.setText(String.valueOf(aFloat.intValue())); 101 } else if(expression instanceof GreaterOrEqualTo) { 102 greaterOrEqualTojRadioButton.setSelected(true); 103 greaterOrEqualTojRadioButtonMousePressed(); 104 Float aFloat = Float.valueOf(expression.getArguments() [1].toString()); 105 valuejTextField.setText(String.valueOf(aFloat.intValue())); 106 } else if(expression instanceof LessThan) { 107 lessThanjRadioButton.setSelected(true); 108 lessThanjRadioButtonMousePressed(); 109 Float aFloat = Float.valueOf(expression.getArguments() [1].toString()); 110 valuejTextField.setText(String.valueOf(aFloat.intValue())); 111 } else if(expression instanceof LessOrEqualTo) { 112 lessOrEqualTojRadioButton.setSelected(true); 113 lessOrEqualTojRadioButtonMousePressed(); 114 Float aFloat = Float.valueOf(expression.getArguments() [1].toString()); 115 valuejTextField.setText(String.valueOf(aFloat.intValue())); 116 } else if(expression instanceof EqualTo) { 117 equalTojRadioButton.setSelected(true); 118 equalTojRadioButtonMousePressed(); 119 Float aFloat = Float.valueOf(expression.getArguments() [1].toString()); 120 valuejTextField.setText(String.valueOf(aFloat.intValue())); 121 } else if(expression instanceof AndExp) { 122 tabPanel.setSelectedIndex(1); 123 Expression [] expressions = expression.getArguments(); 124 Expression greaterOrEqualTo = expressions [0]; 125 Expression lessOrEqualTo = expressions [1]; 126 Float aFloat = Float.valueOf(greaterOrEqualTo.getArguments() [1].toString()); 127 fromjTextField.setText(String.valueOf(aFloat.intValue())); 128 aFloat = Float.valueOf(lessOrEqualTo.getArguments() [1].toString()); 129 tojTextField.setText(String.valueOf(aFloat.intValue())); 130 } 131 } 132 } 133 134 137 private void initComponents() { 138 operatorbuttonGroup = new javax.swing.ButtonGroup (); 139 jPanel3 = new javax.swing.JPanel (); 140 jPanel4 = new javax.swing.JPanel (); 141 okjButton = new javax.swing.JButton (); 142 canceljButton = new javax.swing.JButton (); 143 jPanel6 = new javax.swing.JPanel (); 144 tabPanel = new javax.swing.JTabbedPane (); 145 jPanel2 = new javax.swing.JPanel (); 146 greaterThanjRadioButton = new javax.swing.JRadioButton (); 147 lessThanjRadioButton = new javax.swing.JRadioButton (); 148 greaterOrEqualTojRadioButton = new javax.swing.JRadioButton (); 149 lessOrEqualTojRadioButton = new javax.swing.JRadioButton (); 150 equalTojRadioButton = new javax.swing.JRadioButton (); 151 jPanel5 = new javax.swing.JPanel (); 152 valuejLabel = new javax.swing.JLabel (); 153 valuejTextField = new javax.swing.JTextField (); 154 jPanel1 = new javax.swing.JPanel (); 155 fromjLabel = new javax.swing.JLabel (); 156 tojLabel = new javax.swing.JLabel (); 157 fromjTextField = new javax.swing.JTextField (); 158 tojTextField = new javax.swing.JTextField (); 159 jPanel7 = new javax.swing.JPanel (); 160 colorjLabel = new javax.swing.JLabel (); 161 colorjTextField = new javax.swing.JTextField (); 162 colorjButton = new javax.swing.JButton (); 163 164 setResizable(false); 165 addWindowListener(new java.awt.event.WindowAdapter () { 166 public void windowClosing(java.awt.event.WindowEvent evt) { 167 setVisible(false); 168 } 169 }); 170 171 getContentPane().add(jPanel3, java.awt.BorderLayout.NORTH); 172 173 jPanel4.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.RIGHT)); 174 175 okjButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("112")); 176 okjButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 177 okjButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); 178 jPanel4.add(okjButton); 179 180 canceljButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("113")); 181 canceljButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 182 canceljButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); 183 jPanel4.add(canceljButton); 184 185 getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH); 186 jPanel6.setLayout(new java.awt.BorderLayout ()); 187 jPanel2.setLayout(new javax.swing.BoxLayout (jPanel2, javax.swing.BoxLayout.Y_AXIS)); 188 189 greaterThanjRadioButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("117") + "(>)"); 190 operatorbuttonGroup.add(greaterThanjRadioButton); 191 jPanel2.add(greaterThanjRadioButton); 192 seleccionRadioButton = 0; 193 greaterThanjRadioButton.setSelected(true); 194 195 lessThanjRadioButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("118") + "(<)"); 196 operatorbuttonGroup.add(lessThanjRadioButton); 197 jPanel2.add(lessThanjRadioButton); 198 199 greaterOrEqualTojRadioButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("119") + "(>=)"); 200 operatorbuttonGroup.add(greaterOrEqualTojRadioButton); 201 jPanel2.add(greaterOrEqualTojRadioButton); 202 203 lessOrEqualTojRadioButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("120") + "(<=)"); 204 lessOrEqualTojRadioButton.setToolTipText("null"); 205 operatorbuttonGroup.add(lessOrEqualTojRadioButton); 206 jPanel2.add(lessOrEqualTojRadioButton); 207 208 equalTojRadioButton.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("121") + "(=)"); 209 operatorbuttonGroup.add(equalTojRadioButton); 210 jPanel2.add(equalTojRadioButton); 211 212 jPanel5.setLayout(null); 213 214 valuejLabel.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("122") + ":"); 215 jPanel5.add(valuejLabel); 216 valuejLabel.setBounds(10, 8, 31, 16); 217 218 jPanel5.add(valuejTextField); 219 valuejTextField.setBounds(76, 4, 150, 20); 220 221 jPanel2.add(jPanel5); 222 223 tabPanel.addTab(com.calipso.reportgenerator.common.LanguageTraslator.traslate("123"), jPanel2); 224 225 jPanel1.setLayout(null); 226 227 fromjLabel.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("124") + ":"); 228 jPanel1.add(fromjLabel); 229 fromjLabel.setBounds(10, 20, 39, 16); 230 231 tojLabel.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("125") + ":"); 232 jPanel1.add(tojLabel); 233 tojLabel.setBounds(10, 50, 36, 16); 234 235 jPanel1.add(fromjTextField); 236 fromjTextField.setBounds(80, 20, 160, 20); 237 238 jPanel1.add(tojTextField); 239 tojTextField.setBounds(80, 50, 160, 20); 240 241 tabPanel.addTab(com.calipso.reportgenerator.common.LanguageTraslator.traslate("126"), jPanel1); 242 243 jPanel6.add(tabPanel, java.awt.BorderLayout.CENTER); 244 245 jPanel7.setLayout(null); 246 247 jPanel7.setBorder(new javax.swing.border.CompoundBorder (new javax.swing.border.SoftBevelBorder (javax.swing.border.BevelBorder.RAISED), null)); 248 jPanel7.setPreferredSize(new java.awt.Dimension (10, 30)); 249 colorjLabel.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("127") + ":"); 250 jPanel7.add(colorjLabel); 251 colorjLabel.setBounds(10, 6, 33, 16); 252 253 colorjTextField.setBackground(java.awt.Color.RED); 254 if(storedColor == null) { 255 bgColor = java.awt.Color.RED; 256 } else { 257 bgColor = storedColor; 258 } 259 colorjTextField.setEditable(false); 260 jPanel7.add(colorjTextField); 261 colorjTextField.setBounds(80, 6, 140, 20); 262 263 colorjButton.setText("..."); 264 colorjButton.addActionListener(new java.awt.event.ActionListener () { 265 public void actionPerformed(java.awt.event.ActionEvent evt) { 266 colorjButtonActionPerformed(); 267 } 268 }); 269 okjButton.addActionListener(new java.awt.event.ActionListener () { 270 public void actionPerformed(java.awt.event.ActionEvent evt) { 271 try { 272 doPaint(); 273 } 274 catch (Exception e) { 275 ShowExceptionMessageDialog.initExceptionDialogMessage(com.calipso.reportgenerator.common.LanguageTraslator.traslate("226"),e); 276 } 277 } 278 }); 279 280 greaterThanjRadioButton.addMouseListener(new java.awt.event.MouseAdapter () { 281 public void mousePressed(java.awt.event.MouseEvent evt) { 282 greaterThanjRadioButtonMousePressed(); 283 } 284 }); 285 286 lessThanjRadioButton.addMouseListener(new java.awt.event.MouseAdapter () { 287 public void mousePressed(java.awt.event.MouseEvent evt) { 288 lessThanjRadioButtonMousePressed(); 289 } 290 }); 291 292 greaterOrEqualTojRadioButton.addMouseListener(new java.awt.event.MouseAdapter () { 293 public void mousePressed(java.awt.event.MouseEvent evt) { 294 greaterOrEqualTojRadioButtonMousePressed(); 295 } 296 }); 297 lessOrEqualTojRadioButton.addMouseListener(new java.awt.event.MouseAdapter () { 298 public void mousePressed(java.awt.event.MouseEvent evt) { 299 lessOrEqualTojRadioButtonMousePressed(); 300 } 301 }); 302 equalTojRadioButton.addMouseListener(new java.awt.event.MouseAdapter () { 303 public void mousePressed(java.awt.event.MouseEvent evt) { 304 equalTojRadioButtonMousePressed(); 305 } 306 }); 307 308 canceljButton.addActionListener(new ActionListener () { 309 public void actionPerformed(ActionEvent e) { 310 closeChoosSemaphoreSelection(); 311 312 } 313 }); 314 315 316 jPanel7.add(colorjButton); 317 colorjButton.setBounds(220, 6, 20, 20); 318 319 jPanel6.add(jPanel7, java.awt.BorderLayout.SOUTH); 320 321 getContentPane().add(jPanel6, java.awt.BorderLayout.CENTER); 322 323 pack(); 324 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 325 setSize(new java.awt.Dimension (400, 300)); 326 setLocation((screenSize.width - 400) / 2, (screenSize.height - 300) / 2); 327 } 328 329 332 private void closeChoosSemaphoreSelection() { 333 this.setVisible(false); 334 } 335 336 339 private void equalTojRadioButtonMousePressed() { 340 seleccionRadioButton = 4; 341 } 342 343 346 private void lessOrEqualTojRadioButtonMousePressed() { 347 seleccionRadioButton = 3; 348 } 349 350 353 private void greaterOrEqualTojRadioButtonMousePressed() { 354 seleccionRadioButton = 2; 355 } 356 357 360 private void lessThanjRadioButtonMousePressed() { 361 seleccionRadioButton = 1; 362 } 363 364 367 private void greaterThanjRadioButtonMousePressed() { 368 seleccionRadioButton = 0; 369 } 370 371 374 private void doPaint() throws InfoException { 375 switch (tabPanel.getSelectedIndex()) { 376 case 0: 377 { 378 resultColorCondition = doPaintSimpleSelectionMode(); 379 break; 380 } 381 case 1: 382 { 383 resultColorCondition = doPaintRangoSeleccionMode(); 384 break; 385 } 386 } 387 if (resultColorCondition != null) { 388 setVisible(false); 389 } 390 } 391 392 396 private ColorCondition doPaintSimpleSelectionMode() throws InfoException { 397 switch (seleccionRadioButton) { 398 case 0: 399 { 400 return greaterThan(); 401 } 402 case 1: 403 { 404 return lessThan(); 405 } 406 case 2: 407 { 408 return greaterOrEqualTo(); 409 } 410 case 3: 411 { 412 return lessOrEqualTo(); 413 } 414 case 4: 415 { 416 return equalTo(); 417 } 418 } 419 return null; 420 } 421 422 426 private ColorCondition equalTo() throws InfoException { 427 Vector errors = new Vector (); 428 float value = 0; 429 try { 430 value = Float.parseFloat(this.valuejTextField.getText()); 431 } 432 catch (NumberFormatException e) { 433 errors.add(valuejTextField.getText()); 434 toString(); 435 } 436 if (errors.size() == 0) { 437 value = Float.parseFloat(this.valuejTextField.getText()); 438 Expression expression = (new VariableExp("VALUE")).newEqualTo(new ConstantExp(new Float (value))); 439 return newColorCondition(expression); 440 } 441 else { 442 if (errors.size() == 1) { 443 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{this.valuejTextField.getText()}); 444 throw new InfoException(message); 445 } 446 return null; 447 } 448 } 449 450 454 private ColorCondition newColorCondition(Expression expression) { 455 if (bgColor == null) { 456 458 bgColor = colorjTextField.getBackground(); 459 } 460 return new ColorCondition(expression, bgColor, metricState); 461 } 462 463 467 private ColorCondition lessOrEqualTo() throws InfoException { 468 Vector errors = new Vector (); 469 float value = 0; 470 try { 471 value = Float.parseFloat(this.valuejTextField.getText()); 472 } 473 catch (NumberFormatException e) { 474 errors.add(valuejTextField.getText()); 475 } 476 if (errors.size() == 0) { 477 value = Float.parseFloat(this.valuejTextField.getText()); 478 Expression expression = (new VariableExp("VALUE")).newLessOrEquealTo(new ConstantExp(new Float (value))); 479 return newColorCondition(expression); 480 } 481 else { 482 if (errors.size() == 1) { 483 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{this.valuejTextField.getText()}); 484 throw new InfoException(message); 485 } 486 return null; 487 } 488 } 489 490 494 private ColorCondition greaterOrEqualTo() throws InfoException { 495 Vector errors = new Vector (); 496 float value = 0; 497 try { 498 value = Float.parseFloat(this.valuejTextField.getText()); 499 } 500 catch (NumberFormatException e) { 501 errors.add(valuejTextField.getText()); 502 } 503 if (errors.size() == 0) { 504 value = Float.parseFloat(this.valuejTextField.getText()); 505 Expression expression = (new VariableExp("VALUE")).newGreaterOrEqualTo(new ConstantExp(new Float (value))); 506 return newColorCondition(expression); 507 } 508 else { 509 if (errors.size() == 1) { 510 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{this.valuejTextField.getText()}); 511 throw new InfoException(message); 512 } 513 return null; 514 } 515 } 516 517 521 private ColorCondition lessThan() throws InfoException { 522 Vector errors = new Vector (); 523 float value = 0; 524 try { 525 value = Float.parseFloat(this.valuejTextField.getText()); 526 } 527 catch (NumberFormatException e) { 528 errors.add(valuejTextField.getText()); 529 } 530 if (errors.size() == 0) { 531 value = Float.parseFloat(this.valuejTextField.getText()); 532 Expression expression = (new VariableExp("VALUE")).newLessThan(new ConstantExp(new Float (value))); 533 return newColorCondition(expression); 534 } 535 else { 536 if (errors.size() == 1) { 537 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{this.valuejTextField.getText()}); 538 throw new InfoException(message); 539 } 540 return null; 541 } 542 } 543 544 548 549 private ColorCondition greaterThan() throws InfoException { 550 Vector errors = new Vector (); 551 float value = 0; 552 try { 553 value = Float.parseFloat(this.valuejTextField.getText()); 554 } 555 catch (NumberFormatException e) { 556 errors.add(valuejTextField.getText()); 557 } 558 if (errors.size() == 0) { 559 value = Float.parseFloat(this.valuejTextField.getText()); 560 Expression expression = (new VariableExp("VALUE")).newGreaterThan(new ConstantExp(new Float (value))); 561 return newColorCondition(expression); 562 } 563 else { 564 if (errors.size() == 1) { 565 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{this.valuejTextField.getText()}); 566 throw new InfoException(message); 567 } 568 return null; 569 } 570 } 571 572 575 private void colorjButtonActionPerformed() { 576 this.executeJColorChooser(); 577 } 578 579 583 private ColorCondition doPaintRangoSeleccionMode() throws InfoException { 584 float desdeValue = 0; 585 float hastaValue = 0; 586 Vector errors = new Vector (); 587 Expression exp = null; 588 try { 589 desdeValue = Float.parseFloat(this.fromjTextField.getText()); 590 } 591 catch (NumberFormatException e) { 592 errors.add(fromjTextField.getText()); 593 } 594 try { 595 hastaValue = Float.parseFloat(this.tojTextField.getText()); 596 } 597 catch (NumberFormatException e) { 598 errors.add(tojTextField.getText()); 599 } 600 if (errors.size() == 0) { 601 Expression subexp1 = (new VariableExp("VALUE")).newGreaterOrEqualTo(new ConstantExp(new Float (desdeValue))); 602 Expression subexp2 = (new VariableExp("VALUE")).newLessOrEquealTo((new ConstantExp(new Float (hastaValue)))); 603 exp = subexp1.newAnd(subexp2); 604 return newColorCondition(exp); 605 } 606 else { 607 if (errors.size() == 1) { 608 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("128"), new Object []{errors.get(0)}); 609 throw new InfoException(message); 610 } 611 else { 612 String message = MessageFormat.format(com.calipso.reportgenerator.common.LanguageTraslator.traslate("129"), new Object []{errors.get(0), errors.get(1)}); 613 throw new InfoException(message); 614 } 615 } 616 } 617 618 621 private void executeJColorChooser() { 622 if(storedColor != null) { 623 bgColor = JColorChooser.showDialog(this, "", storedColor); 624 } else { 625 bgColor = JColorChooser.showDialog(this, "", getBackground()); 626 } 627 if (bgColor != null) { 628 colorjTextField.setBackground(bgColor); 629 } 630 } 631 } | Popular Tags |