< prev index next >

src/com/sun/javatest/mrep/OptionsPane.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 305                 if (box.isSelected()) {
 306                     customReps.add(customBoxes.get(box));
 307                 }
 308             }
 309         }
 310         return customReps;
 311     }
 312 
 313 
 314     /**
 315      * This listener changes options state against checkboxes
 316      */
 317     private class SelectListener extends MouseInputAdapter implements
 318             KeyListener, ListSelectionListener {
 319 
 320         /**
 321          * @param lst JList of checkboxes
 322          * @param p parent Panel
 323          * @param cardLayout The CardLayout for options
 324          */
 325         SelectListener(JList lst, JPanel p, CardLayout cardLayout) {
 326             list = lst;
 327             listModel = list.getModel();
 328             lastSelected = listModel.getElementAt(0);
 329             panel = p;
 330             cards = cardLayout;
 331         }
 332 
 333         public void keyTyped(KeyEvent e) {
 334             if (e.getKeyChar() == ' ') {
 335                 process(list.getSelectedIndex());
 336             }
 337         }
 338 
 339         public void mouseClicked(MouseEvent e) {
 340             if (e.getPoint().getX() <= emptyCBW) {
 341                 process(list.locationToIndex(e.getPoint()));
 342             }
 343         }
 344 
 345         public void valueChanged(ListSelectionEvent e) {
 346             int index = list.getSelectedIndex();
 347             JCheckBox box = (JCheckBox) (listModel.getElementAt(index));
 348 
 349             if (lastSelected != box) {
 350                 cards.show(panel, box.getName());
 351                 lastSelected = box;
 352             }
 353             enablePanel(box);
 354         }
 355 
 356         private void enablePanel(final JCheckBox box) {
 357             for (int i = 0; i < panel.getComponentCount(); i++) {
 358                 JComponent tab = (JComponent) panel.getComponent(i);
 359                 tab.setEnabled(box.isSelected());
 360             }
 361 
 362             if (box == cbXml) {
 363                 descriptionArea.setText(uif.getI18NString("opts.xmlDesc.txt"));
 364                 return;
 365             }
 366 
 367             if (customBoxes != null) {
 368                 CustomReport rep = customBoxes.get(box);
 369                 if(rep != null) {
 370                     if (rep.getOptionPanes() != null) {
 371                         for (int i = 0; i < rep.getOptionPanes().length; i++) {
 372                             rep.getOptionPanes()[i].setEnabled(box.isSelected());
 373                         }   // for
 374                     }
 375 
 376                     descriptionArea.setText(rep.getDescription());
 377                 }
 378             }
 379         }
 380 
 381         private void process(final int index) {
 382             JCheckBox box = (JCheckBox) (listModel.getElementAt(index));
 383 
 384             if (lastSelected == box) {
 385                 box.doClick();
 386                 list.repaint(); // important!
 387                 enablePanel(box);
 388             }
 389             lastSelected = box;
 390         }
 391 
 392         public void keyReleased(KeyEvent e) {
 393         }
 394 
 395         public void keyPressed(KeyEvent e) {
 396         }
 397 
 398         Object lastSelected;
 399         JList list;
 400         ListModel listModel;
 401         JPanel panel;
 402         CardLayout cards;
 403         double emptyCBW = new JCheckBox("").getPreferredSize().getWidth() + 2;
 404     }
 405 
 406     /*
 407      * PropertyChangeListener for enabling/disabling container's content
 408      */
 409     private class PanelEnableListener implements PropertyChangeListener {
 410         /**
 411          * @param container Container for controlling
 412          */
 413         PanelEnableListener(Container container) {
 414             theContainer = container;
 415         }
 416 
 417         /**
 418          * Catches changes of "enabled" property
 419          * and changes enabled status for all child components
 420          */


 452         /**
 453          * Recursively gathers all children components
 454          */
 455         private Collection<Component> collectChildren(Container comp, Collection<Component> c) {
 456             Component[] ch = comp.getComponents();
 457             for (int i = 0; i < ch.length; i++) {
 458                 c.add(ch[i]);
 459                 if (ch[i] instanceof Container) {
 460                     collectChildren((Container) ch[i], c);
 461                 }
 462             }
 463             return c;
 464         }
 465 
 466         private Container theContainer;
 467 
 468         private Set<Component> enabledComp;
 469     }
 470 
 471     private class CheckBoxListCellRenderer implements ListCellRenderer<JCheckBox> {
 472         public Component getListCellRendererComponent(JList list, JCheckBox comp,
 473                 int index, boolean isSelected, boolean cellHasFocus) {
 474             // assert: value is a JCheckBox
 475             if (isSelected) {
 476                 comp.setOpaque(true);
 477                 comp.setBackground(UIFactory.Colors.TEXT_HIGHLIGHT_COLOR.getValue());
 478             } else {
 479                 comp.setOpaque(false);
 480                 comp.setForeground(Color.black);
 481             }
 482 
 483             return comp;
 484         }
 485     }
 486 
 487     JButton[] getButtons() {
 488         return new JButton[] { backBtn, okBtn, cancelBtn, helpBtn };
 489     }
 490 
 491     private DefaultListModel<JCheckBox> listModel;
 492     private JList<JCheckBox> list;


 305                 if (box.isSelected()) {
 306                     customReps.add(customBoxes.get(box));
 307                 }
 308             }
 309         }
 310         return customReps;
 311     }
 312 
 313 
 314     /**
 315      * This listener changes options state against checkboxes
 316      */
 317     private class SelectListener extends MouseInputAdapter implements
 318             KeyListener, ListSelectionListener {
 319 
 320         /**
 321          * @param lst JList of checkboxes
 322          * @param p parent Panel
 323          * @param cardLayout The CardLayout for options
 324          */
 325         SelectListener(JList<JCheckBox> lst, JPanel p, CardLayout cardLayout) {
 326             list = lst;
 327             listModel = list.getModel();
 328             lastSelected = listModel.getElementAt(0);
 329             panel = p;
 330             cards = cardLayout;
 331         }
 332 
 333         public void keyTyped(KeyEvent e) {
 334             if (e.getKeyChar() == ' ') {
 335                 process(list.getSelectedIndex());
 336             }
 337         }
 338 
 339         public void mouseClicked(MouseEvent e) {
 340             if (e.getPoint().getX() <= emptyCBW) {
 341                 process(list.locationToIndex(e.getPoint()));
 342             }
 343         }
 344 
 345         public void valueChanged(ListSelectionEvent e) {
 346             int index = list.getSelectedIndex();
 347             JCheckBox box = (listModel.getElementAt(index));
 348 
 349             if (lastSelected != box) {
 350                 cards.show(panel, box.getName());
 351                 lastSelected = box;
 352             }
 353             enablePanel(box);
 354         }
 355 
 356         private void enablePanel(final JCheckBox box) {
 357             for (int i = 0; i < panel.getComponentCount(); i++) {
 358                 JComponent tab = (JComponent) panel.getComponent(i);
 359                 tab.setEnabled(box.isSelected());
 360             }
 361 
 362             if (box == cbXml) {
 363                 descriptionArea.setText(uif.getI18NString("opts.xmlDesc.txt"));
 364                 return;
 365             }
 366 
 367             if (customBoxes != null) {
 368                 CustomReport rep = customBoxes.get(box);
 369                 if(rep != null) {
 370                     if (rep.getOptionPanes() != null) {
 371                         for (int i = 0; i < rep.getOptionPanes().length; i++) {
 372                             rep.getOptionPanes()[i].setEnabled(box.isSelected());
 373                         }   // for
 374                     }
 375 
 376                     descriptionArea.setText(rep.getDescription());
 377                 }
 378             }
 379         }
 380 
 381         private void process(final int index) {
 382             JCheckBox box = (listModel.getElementAt(index));
 383 
 384             if (lastSelected == box) {
 385                 box.doClick();
 386                 list.repaint(); // important!
 387                 enablePanel(box);
 388             }
 389             lastSelected = box;
 390         }
 391 
 392         public void keyReleased(KeyEvent e) {
 393         }
 394 
 395         public void keyPressed(KeyEvent e) {
 396         }
 397 
 398         Object lastSelected;
 399         JList<JCheckBox> list;
 400         ListModel<JCheckBox> listModel;
 401         JPanel panel;
 402         CardLayout cards;
 403         double emptyCBW = new JCheckBox("").getPreferredSize().getWidth() + 2;
 404     }
 405 
 406     /*
 407      * PropertyChangeListener for enabling/disabling container's content
 408      */
 409     private class PanelEnableListener implements PropertyChangeListener {
 410         /**
 411          * @param container Container for controlling
 412          */
 413         PanelEnableListener(Container container) {
 414             theContainer = container;
 415         }
 416 
 417         /**
 418          * Catches changes of "enabled" property
 419          * and changes enabled status for all child components
 420          */


 452         /**
 453          * Recursively gathers all children components
 454          */
 455         private Collection<Component> collectChildren(Container comp, Collection<Component> c) {
 456             Component[] ch = comp.getComponents();
 457             for (int i = 0; i < ch.length; i++) {
 458                 c.add(ch[i]);
 459                 if (ch[i] instanceof Container) {
 460                     collectChildren((Container) ch[i], c);
 461                 }
 462             }
 463             return c;
 464         }
 465 
 466         private Container theContainer;
 467 
 468         private Set<Component> enabledComp;
 469     }
 470 
 471     private class CheckBoxListCellRenderer implements ListCellRenderer<JCheckBox> {
 472         public Component getListCellRendererComponent(JList<? extends JCheckBox> list, JCheckBox comp,
 473                 int index, boolean isSelected, boolean cellHasFocus) {
 474             // assert: value is a JCheckBox
 475             if (isSelected) {
 476                 comp.setOpaque(true);
 477                 comp.setBackground(UIFactory.Colors.TEXT_HIGHLIGHT_COLOR.getValue());
 478             } else {
 479                 comp.setOpaque(false);
 480                 comp.setForeground(Color.black);
 481             }
 482 
 483             return comp;
 484         }
 485     }
 486 
 487     JButton[] getButtons() {
 488         return new JButton[] { backBtn, okBtn, cancelBtn, helpBtn };
 489     }
 490 
 491     private DefaultListModel<JCheckBox> listModel;
 492     private JList<JCheckBox> list;
< prev index next >