1 23 package com.sun.enterprise.tools.verifier.gui; 24 25 26 import javax.help.CSH; 27 import javax.help.HelpBroker; 28 import javax.help.HelpSet; 29 import javax.swing.BorderFactory ; 30 import javax.swing.Box ; 31 import javax.swing.BoxLayout ; 32 import javax.swing.ButtonGroup ; 33 import javax.swing.DefaultListModel ; 34 import javax.swing.JButton ; 35 import javax.swing.JFileChooser ; 36 import javax.swing.JFrame ; 37 import javax.swing.JLabel ; 38 import javax.swing.JList ; 39 import javax.swing.JOptionPane ; 40 import javax.swing.JPanel ; 41 import javax.swing.JRadioButton ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.ListSelectionModel ; 44 import javax.swing.SwingConstants ; 45 46 import java.awt.BorderLayout ; 47 import java.awt.Color ; 48 import java.awt.Dimension ; 49 import java.awt.GridLayout ; 50 import java.awt.event.ActionEvent ; 51 import java.awt.event.ActionListener ; 52 import java.awt.event.KeyEvent ; 53 import java.io.File ; 54 import java.net.URL ; 55 import java.util.logging.Level ; 56 import java.util.logging.Logger ; 57 58 import com.sun.enterprise.logging.LogDomains; 59 import com.sun.enterprise.tools.verifier.StringManagerHelper; 60 import com.sun.enterprise.tools.verifier.util.VerifierConstants; 61 62 public class ControlPanel extends JPanel { 63 64 static com.sun.enterprise.util.LocalStringManagerImpl smh = 65 StringManagerHelper.getLocalStringsManager(); 66 static String allString = 67 (smh.getLocalString 68 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".AllRadioButton", "All Results")); static String failString = 72 (smh.getLocalString 73 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".FailuresOnlyRadioButton", "Failures Only")); static String warnString = 77 (smh.getLocalString 78 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".FailuresWarningRadioButton", "Failures and Warnings only")); 82 static String buttonName = 84 (smh.getLocalString 85 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".buttonName", "Button")); static String buttonDesc = 89 (smh.getLocalString 90 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".buttonDesc", "This is a button used to select an action")); static String radioButtonName = 94 (smh.getLocalString 95 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".radioButtonName", "Radio Button")); static String radioButtonDesc = 99 (smh.getLocalString 100 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".radioButtonDesc", "This is a radio button used to select one from option from many choices")); static String panelName = 104 (smh.getLocalString 105 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".panelName", "Panel")); static String panelDesc = 109 (smh.getLocalString 110 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".panelDesc", "This is a panel in the verifier window")); 114 static JRadioButton allButton = new JRadioButton (allString); 115 static JRadioButton failButton = new JRadioButton (failString); 116 static JRadioButton warnButton = new JRadioButton (warnString); 117 static final String helpsetName = "Help"; 119 120 private static Logger logger = LogDomains.getLogger(LogDomains.AVK_VERIFIER_LOGGER); 122 123 private static HelpBroker mainHB = null; 125 126 private static int reportLevel = VerifierConstants.ALL; 128 129 final DefaultListModel listModel; 131 JButton okButton; 132 JButton closeButton; 133 JButton helpButton; 134 135 JFrame parent; 136 HelpSet mainHS = null; 137 138 141 public ControlPanel(JFrame p) { 142 parent = p; 143 144 this.getAccessibleContext().setAccessibleName(panelName); 146 this.getAccessibleContext().setAccessibleDescription(panelDesc); 147 allButton.getAccessibleContext().setAccessibleName(radioButtonName); 148 allButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc); 149 failButton.getAccessibleContext().setAccessibleName(radioButtonName); 150 failButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc); 151 warnButton.getAccessibleContext().setAccessibleName(radioButtonName); 152 warnButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc); 153 154 setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), 156 (smh.getLocalString("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".ItemsToBeVerifierPanelLabel", "Items to be Verified")))); setLayout(new BoxLayout (this, BoxLayout.X_AXIS)); 160 161 163 JButton addButton = new JButton ((smh.getLocalString 165 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".AddButton", "Add..."))); JButton deleteButton = new JButton ((smh.getLocalString 169 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".DeleteButton", "Delete"))); 173 addButton.getAccessibleContext().setAccessibleName(buttonName); 175 addButton.getAccessibleContext().setAccessibleDescription(buttonDesc); 176 addButton.setMnemonic('A'); 177 deleteButton.getAccessibleContext().setAccessibleName(buttonName); 178 deleteButton.getAccessibleContext().setAccessibleDescription(buttonDesc); 179 deleteButton.setMnemonic('D'); 180 181 listModel = new DefaultListModel (); 183 final JList list = new JList (listModel); 184 list.getAccessibleContext().setAccessibleName(smh.getLocalString 186 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".listName", "List")); list.getAccessibleContext().setAccessibleDescription(smh.getLocalString 190 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".listDesc", "This is a list")); 194 list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 195 196 JScrollPane listScroller = new JScrollPane (list); 197 listScroller.getAccessibleContext().setAccessibleName(smh.getLocalString 199 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".scrName", "Scroll Pane")); listScroller.getAccessibleContext().setAccessibleDescription 203 (smh.getLocalString("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".scrDesc", "This is a scroll pane that helps to scroll the list")); listScroller.setPreferredSize(new Dimension (250, 80)); 207 listScroller.setMinimumSize(new Dimension (250, 80)); 210 listScroller.setAlignmentX(LEFT_ALIGNMENT); 211 212 JPanel listPane = new JPanel (); 217 listPane.getAccessibleContext().setAccessibleName(panelName); 219 listPane.getAccessibleContext().setAccessibleDescription(panelDesc); 220 listPane.setLayout(new BoxLayout (listPane, BoxLayout.Y_AXIS)); 221 listPane.add(Box.createRigidArea(new Dimension (0, 5))); 225 listPane.add(listScroller); 226 listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 227 228 JPanel buttonPane = new JPanel (); 230 buttonPane.getAccessibleContext().setAccessibleName(panelName); 232 buttonPane.getAccessibleContext().setAccessibleDescription(panelDesc); 233 buttonPane.setLayout(new BoxLayout (buttonPane, BoxLayout.X_AXIS)); 234 buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); 235 buttonPane.add(Box.createHorizontalGlue()); 236 buttonPane.add(addButton); 237 buttonPane.add(Box.createRigidArea(new Dimension (10, 0))); 238 buttonPane.add(deleteButton); 239 240 JPanel listPanel = new JPanel (); 242 listPanel.getAccessibleContext().setAccessibleName(panelName); 244 listPanel.getAccessibleContext().setAccessibleDescription(panelDesc); 245 listPanel.setLayout(new BorderLayout ()); 246 listPanel.add(listPane, BorderLayout.CENTER); 247 listPanel.add(buttonPane, BorderLayout.SOUTH); 248 249 final JFileChooser fileChooser = new JFileChooser (); 251 252 fileChooser.getAccessibleContext().setAccessibleName(smh.getLocalString 254 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".fcName", "FileChooser")); fileChooser.getAccessibleContext().setAccessibleDescription(smh.getLocalString 258 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".fcDesc", "This dialog box enables selection of files")); fileChooser.setApproveButtonMnemonic('O'); 262 263 fileChooser.setMultiSelectionEnabled(true); 264 fileChooser.addActionListener(new ActionListener () { 265 public void actionPerformed(ActionEvent e) { 266 if (e.getActionCommand().equals("ApproveSelection")) { File [] files = fileChooser.getSelectedFiles(); 268 for (int i = 0; i < files.length; i++) { 269 if (!listModel.contains(files[i])) { listModel.addElement(files[i]); 271 } 272 } 273 list.setSelectedIndex(listModel.getSize() - 1); 275 } 276 } 277 }); 278 279 addButton.addActionListener(new ActionListener () { 281 public void actionPerformed(ActionEvent e) { 282 fileChooser.rescanCurrentDirectory(); 283 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 284 fileChooser.showOpenDialog(null); 285 } 286 }); 287 288 deleteButton.addActionListener(new ActionListener () { 289 public void actionPerformed(ActionEvent e) { 290 if (!list.isSelectionEmpty()) { 291 Object [] selections = list.getSelectedValues(); 292 for (int i = 0; i < selections.length; i++) { 293 listModel.removeElement(selections[i]); 294 } 295 } else { 296 JOptionPane.showMessageDialog(parent, 297 (smh.getLocalString 298 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.deleteButtonNoFiles", "You must first select file to delete.")) + "\n" + (smh.getLocalString 303 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.deleteButtonNoFiles2", "Then click on the Delete button, to delete " + "file from list of files to be verified.")), (smh.getLocalString 308 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.deleteTitle", "ERROR")), JOptionPane.ERROR_MESSAGE); 312 } 313 } 314 }); 315 316 allButton.setMnemonic(KeyEvent.VK_L); 318 allButton.setActionCommand(allString); 319 allButton.setSelected(getReportLevel() == VerifierConstants.ALL); 320 321 failButton.setMnemonic(KeyEvent.VK_F); 322 failButton.setActionCommand(failString); 323 failButton.setSelected(getReportLevel() == VerifierConstants.FAIL); 324 325 warnButton.setMnemonic(KeyEvent.VK_W); 326 warnButton.setActionCommand(warnString); 327 warnButton.setSelected(getReportLevel() == VerifierConstants.WARN); 328 329 ButtonGroup group = new ButtonGroup (); 331 group.add(allButton); 332 group.add(failButton); 333 group.add(warnButton); 334 335 336 JPanel radioPanel = new JPanel (); 338 radioPanel.getAccessibleContext().setAccessibleName(panelName); 340 radioPanel.getAccessibleContext().setAccessibleDescription(panelDesc); 341 radioPanel.setLayout(new BoxLayout (radioPanel, BoxLayout.Y_AXIS)); 342 JLabel d = new JLabel ((smh.getLocalString 343 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".RadioButtonLabel", "Display:"))); d.setVerticalAlignment(SwingConstants.BOTTOM); 347 d.getAccessibleContext().setAccessibleName(smh.getLocalString 349 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".labelName", "Label")); d.getAccessibleContext().setAccessibleDescription(smh.getLocalString 353 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".labelDesc", "This is a label")); radioPanel.add(d); 357 radioPanel.add(allButton); 358 radioPanel.add(failButton); 359 radioPanel.add(warnButton); 360 361 okButton = 363 new JButton ((smh.getLocalString 364 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".OKButton", "OK"))); closeButton = 368 new JButton ((smh.getLocalString 369 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".CloseButton", "Close"))); helpButton = 373 new JButton ((smh.getLocalString 374 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".HelpButton", "Help"))); 378 okButton.getAccessibleContext().setAccessibleName(buttonName); 380 okButton.getAccessibleContext().setAccessibleDescription(buttonDesc); 381 okButton.setMnemonic('O'); 382 closeButton.getAccessibleContext().setAccessibleName(buttonName); 383 closeButton.getAccessibleContext().setAccessibleDescription(buttonDesc); 384 closeButton.setMnemonic('C'); 385 helpButton.getAccessibleContext().setAccessibleName(buttonName); 386 helpButton.getAccessibleContext().setAccessibleDescription(buttonDesc); 387 helpButton.setMnemonic('H'); 388 389 390 boolean mainHelpSetWoes = false; 391 boolean usingDeployTool = false; 392 393 if (!usingDeployTool) { 394 try { 396 ClassLoader cl = ControlPanel.class.getClassLoader(); 397 URL url = HelpSet.findHelpSet(cl, helpsetName); 398 mainHS = new HelpSet(cl, url); 399 } catch (Exception ee) { 400 logger.log(Level.WARNING, 401 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".debug.helpSetMissing", new Object []{helpsetName}); 404 JOptionPane.showMessageDialog(this, 405 (smh.getLocalString 406 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.helpSetMissing1", "Could not find Help Set for {0}.", new Object []{helpsetName})) + 410 "\n" + (smh.getLocalString 412 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.helpSetMissing2", "Please consult your host administrator. " + "Starting Verifier with JavaHelp disabled."))); mainHelpSetWoes = true; 417 } catch (ExceptionInInitializerError ex) { 418 logger.log(Level.WARNING, 419 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".debug.ExceptionInInitializerError"); JOptionPane.showMessageDialog(this, 422 (smh.getLocalString 423 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.helpSetMissing1", "Could not find Help Set for {0}.", new Object []{helpsetName})) + 427 "\n" + (smh.getLocalString 429 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.helpSetMissing2", "Please consult your host administrator. " + "Starting Verifier with JavaHelp disabled."))); mainHelpSetWoes = true; 434 } 435 436 if (!mainHelpSetWoes) { 437 mainHB = mainHS.createHelpBroker(); 438 setMainHelpBroker(mainHB); 439 440 mainHB.enableHelpKey(this, "Verifier", null); 443 CSH.setHelpIDString(helpButton, "Verifier"); 445 helpButton.addActionListener(new CSH.DisplayHelpFromSource(mainHB)); 447 } else { 448 helpButton.setEnabled(false); 450 } 451 } else { 452 helpButton.addActionListener(new ActionListener () { 454 public void actionPerformed(ActionEvent e) { 455 JOptionPane.showMessageDialog(parent, 456 (smh.getLocalString 457 ("com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".optionPane.helpDisabled", "Verifier online help disabled."))); } 461 }); 462 } 463 464 465 JPanel buttonPanel = new JPanel (); 467 buttonPanel.getAccessibleContext().setAccessibleName(panelName); 469 buttonPanel.getAccessibleContext().setAccessibleDescription(panelDesc); 470 GridLayout gl = new GridLayout (0, 1); 471 gl.setVgap(10); 472 gl.setHgap(5); 473 buttonPanel.setLayout(gl); 474 buttonPanel.add(okButton); 475 buttonPanel.add(closeButton); 476 buttonPanel.add(helpButton); 477 buttonPanel.add(new JLabel ("")); 478 479 add(listPanel); 481 add(radioPanel); 482 add(buttonPanel); 483 484 RadioListener myListener = new RadioListener(); 486 addRadioButtonListener((ActionListener ) myListener); 487 } 488 489 public static void setMainHelpBroker(HelpBroker hb) { 490 mainHB = hb; 491 Thread t = new Thread () { 492 public void run() { 493 if (mainHB != null) { 494 mainHB.initPresentation(); } 496 } 497 }; 498 t.setPriority(Thread.MIN_PRIORITY); 499 t.start(); 500 } 501 502 private static void setReportLevel(int rl) { 503 reportLevel = rl; 504 } 505 506 static int getReportLevel() { 507 return reportLevel; 508 } 509 510 class RadioListener implements ActionListener { 511 public void actionPerformed(ActionEvent e) { 512 if (e.getSource() == allButton) { 513 setReportLevel(VerifierConstants.ALL); 514 } 515 if (e.getSource() == failButton) { 516 setReportLevel(VerifierConstants.FAIL); 517 } 518 if (e.getSource() == warnButton) { 519 setReportLevel(VerifierConstants.WARN); 520 } 521 } 522 } 523 524 public static void addRadioButtonListener(ActionListener r) { 526 allButton.addActionListener(r); 527 failButton.addActionListener(r); 528 warnButton.addActionListener(r); 529 } 530 531 public void addJarFile(File jarFile) { 533 listModel.addElement(jarFile); 534 } 535 536 public void removeAllJarFiles() { 538 listModel.clear(); 539 } 540 } 541 542 | Popular Tags |