400 * called on the event thread.
401 */
402 private void selectIndex(int index) {
403 leftList.setSelectedIndex(index);
404
405 // update right panel
406 selectedFilter = (TestFilter)(listModel.elementAt(index));
407 if (selectedFilter instanceof ConfigurableTestFilter) {
408 if (mode == -1 || mode == UNEDITABLE) {
409 nameCards.show(namePanel, NAMING_ACTIVE);
410 //deleteBut.setEnabled(true);
411 //createBut.setEnabled(true);
412 applyBut.setEnabled(true);
413 resetBut.setEnabled(true);
414 mode = EDITABLE;
415 }
416
417 ConfigurableTestFilter ctf = (ConfigurableTestFilter)selectedFilter;
418 namingName.setText(ctf.getName());
419
420 String cardKey = (String)(configPanelHash.get(ctf));
421 configCards.show(configPanel, cardKey);
422 }
423 else if (selectedFilter instanceof TestFilter) {
424 if (mode == -1 || mode == EDITABLE) {
425 nameCards.show(namePanel, NAMING_EMPTY);
426 configCards.show(configPanel, CONFIG_EMPTY);
427 //createBut.setEnabled(false);
428 //deleteBut.setEnabled(false);
429 applyBut.setEnabled(false);
430 resetBut.setEnabled(false);
431 mode = UNEDITABLE;
432 }
433 }
434 else {
435 // hummm
436 }
437
438 fillInfo(selectedFilter);
439 leftList.requestFocus();
440 }
487 body.setPreferredSize(new Dimension(7 * dpi, 5 * dpi));
488 setBody(body);
489
490 initButtons();
491
492 setComponentListener(listener);
493
494 //leftList.setNextFocusableComponent(rightPanel.getNextFocusableComponent());
495 //rightPanel.setNextFocusableComponent(applyBut);
496 //helpBut.setNextFocusableComponent(leftList);
497
498 mode = -1;
499
500 // process any stored state
501 if (selectedFilter != null)
502 setSelectedFilter(selectedFilter);
503 else
504 selectIndex(0); // the default
505 }
506
507 private ListModel createListModel() {
508 listModel = new DefaultListModel();
509
510 for (int i = 0; i < filters.length; i++)
511 listModel.addElement(filters[i]);
512
513 return listModel;
514 }
515
516 private JComponent createRightPanel() {
517 EMPTY_CONFIG = createEmptyItem("fconfig.empt.conf");
518 EMPTY_NAMING = createEmptyItem("fconfig.empt.name");
519
520 EMPTY_CONFIG.setName("config");
521 EMPTY_NAMING.setName("naming");
522
523 JPanel pan = new JPanel(new GridBagLayout());
524 pan.setName("rightFilter");
525 GridBagConstraints gbc = new GridBagConstraints();
526 gbc.gridx = 0;
527 gbc.gridy = GridBagConstraints.RELATIVE;
528 gbc.fill = GridBagConstraints.BOTH;
671 lab.setHorizontalAlignment(SwingConstants.RIGHT);
672
673 // row 1
674 // label in first column
675 pan.add(lab, gbc);
676
677 gbc.gridx = 1;
678 gbc.fill = GridBagConstraints.HORIZONTAL;
679 pan.add(namingName, gbc);
680
681 namePanel.add(NAMING_ACTIVE, pan);
682 namePanel.add(NAMING_EMPTY, EMPTY_NAMING);
683 nameCards.show(namePanel, NAMING_EMPTY);
684
685 return namePanel;
686 }
687
688 private JPanel createConfigPanel() {
689 configCards = new CardLayout();
690 configPanel = new JPanel(configCards);
691 configPanelHash = new Hashtable();
692
693 // insert panels?
694 configPanel.add(CONFIG_EMPTY, EMPTY_CONFIG);
695
696 for (int i = 0; i < listModel.getSize(); i++) {
697 if (listModel.getElementAt(i) instanceof ConfigurableTestFilter) {
698 ConfigurableTestFilter ctf =
699 (ConfigurableTestFilter)listModel.getElementAt(i);
700 addConfigurableFilter(ctf);
701 }
702 } // for
703
704 return configPanel;
705 }
706
707 private void initButtons() {
708 applyBut = uif.createButton("fconfig.edit.apply", this);
709 resetBut = uif.createButton("fconfig.edit.reset", this);
710 cancelBut = uif.createCancelButton("fconfig.edit.cancel", this);
711 doneBut = uif.createButton("fconfig.edit.done", this);
793 * @return The position of the invalid character.
794 */
795 private int validateName(String text) {
796 for (int i = 0; i < text.length(); i++) {
797 char c = text.charAt(i);
798 if (Character.isLetterOrDigit(c) ||
799 c == '-' ||
800 c == '_' ||
801 c == '.' ||
802 c == ' ' ||
803 c == ',')
804 continue;
805 else
806 return i;
807 } // for
808
809 return -1;
810 }
811
812 private JSplitPane split;
813 private JList leftList;
814 private DefaultListModel listModel;
815 private int lastSelected = -1;
816 private TestFilter selectedFilter;
817
818 // just to help track current state
819 private int mode;
820 //private boolean focusSet;
821 private static final int EDITABLE = 0;
822 private static final int UNEDITABLE = 1;
823
824 // dialog buttons
825 private JButton applyBut;
826 private JButton helpBut;
827 private JButton doneBut;
828 private JButton cancelBut;
829 private JButton createBut;
830 private JButton deleteBut;
831 private JButton resetBut;
832
833 // info panel components
834 private JTextArea infoDesc;
835 private JTextField infoName;
836 //private JTextArea infoReason;
837
838 // naming panel
839 private CardLayout nameCards;
840 private JPanel namePanel;
841 private JTextField namingName;
842
843 // config panel
844 private CardLayout configCards;
845 private JPanel configPanel;
846 private Hashtable configPanelHash;
847 private int configCounter; // to make a unique string
848
849 private JComponent EMPTY_CONFIG;
850 private JComponent EMPTY_NAMING;
851 private JComponent EMPTY_INFO;
852
853 private int NUMBER;
854
855 private static final String CONFIG_ACTIVE = "configa";
856 private static final String CONFIG_EMPTY = "confige";
857 private static final String NAMING_ACTIVE = "naminga";
858 private static final String NAMING_EMPTY = "naminge";
859 private static final String INFO_ACTIVE = "infoa";
860 private static final String INFO_EMPTY = "infoe";
861 }
862
863 }
|
400 * called on the event thread.
401 */
402 private void selectIndex(int index) {
403 leftList.setSelectedIndex(index);
404
405 // update right panel
406 selectedFilter = (TestFilter)(listModel.elementAt(index));
407 if (selectedFilter instanceof ConfigurableTestFilter) {
408 if (mode == -1 || mode == UNEDITABLE) {
409 nameCards.show(namePanel, NAMING_ACTIVE);
410 //deleteBut.setEnabled(true);
411 //createBut.setEnabled(true);
412 applyBut.setEnabled(true);
413 resetBut.setEnabled(true);
414 mode = EDITABLE;
415 }
416
417 ConfigurableTestFilter ctf = (ConfigurableTestFilter)selectedFilter;
418 namingName.setText(ctf.getName());
419
420 String cardKey = configPanelHash.get(ctf);
421 configCards.show(configPanel, cardKey);
422 }
423 else if (selectedFilter instanceof TestFilter) {
424 if (mode == -1 || mode == EDITABLE) {
425 nameCards.show(namePanel, NAMING_EMPTY);
426 configCards.show(configPanel, CONFIG_EMPTY);
427 //createBut.setEnabled(false);
428 //deleteBut.setEnabled(false);
429 applyBut.setEnabled(false);
430 resetBut.setEnabled(false);
431 mode = UNEDITABLE;
432 }
433 }
434 else {
435 // hummm
436 }
437
438 fillInfo(selectedFilter);
439 leftList.requestFocus();
440 }
487 body.setPreferredSize(new Dimension(7 * dpi, 5 * dpi));
488 setBody(body);
489
490 initButtons();
491
492 setComponentListener(listener);
493
494 //leftList.setNextFocusableComponent(rightPanel.getNextFocusableComponent());
495 //rightPanel.setNextFocusableComponent(applyBut);
496 //helpBut.setNextFocusableComponent(leftList);
497
498 mode = -1;
499
500 // process any stored state
501 if (selectedFilter != null)
502 setSelectedFilter(selectedFilter);
503 else
504 selectIndex(0); // the default
505 }
506
507 private ListModel<TestFilter> createListModel() {
508 listModel = new DefaultListModel<>();
509
510 for (int i = 0; i < filters.length; i++)
511 listModel.addElement(filters[i]);
512
513 return listModel;
514 }
515
516 private JComponent createRightPanel() {
517 EMPTY_CONFIG = createEmptyItem("fconfig.empt.conf");
518 EMPTY_NAMING = createEmptyItem("fconfig.empt.name");
519
520 EMPTY_CONFIG.setName("config");
521 EMPTY_NAMING.setName("naming");
522
523 JPanel pan = new JPanel(new GridBagLayout());
524 pan.setName("rightFilter");
525 GridBagConstraints gbc = new GridBagConstraints();
526 gbc.gridx = 0;
527 gbc.gridy = GridBagConstraints.RELATIVE;
528 gbc.fill = GridBagConstraints.BOTH;
671 lab.setHorizontalAlignment(SwingConstants.RIGHT);
672
673 // row 1
674 // label in first column
675 pan.add(lab, gbc);
676
677 gbc.gridx = 1;
678 gbc.fill = GridBagConstraints.HORIZONTAL;
679 pan.add(namingName, gbc);
680
681 namePanel.add(NAMING_ACTIVE, pan);
682 namePanel.add(NAMING_EMPTY, EMPTY_NAMING);
683 nameCards.show(namePanel, NAMING_EMPTY);
684
685 return namePanel;
686 }
687
688 private JPanel createConfigPanel() {
689 configCards = new CardLayout();
690 configPanel = new JPanel(configCards);
691 configPanelHash = new Hashtable<>();
692
693 // insert panels?
694 configPanel.add(CONFIG_EMPTY, EMPTY_CONFIG);
695
696 for (int i = 0; i < listModel.getSize(); i++) {
697 if (listModel.getElementAt(i) instanceof ConfigurableTestFilter) {
698 ConfigurableTestFilter ctf =
699 (ConfigurableTestFilter)listModel.getElementAt(i);
700 addConfigurableFilter(ctf);
701 }
702 } // for
703
704 return configPanel;
705 }
706
707 private void initButtons() {
708 applyBut = uif.createButton("fconfig.edit.apply", this);
709 resetBut = uif.createButton("fconfig.edit.reset", this);
710 cancelBut = uif.createCancelButton("fconfig.edit.cancel", this);
711 doneBut = uif.createButton("fconfig.edit.done", this);
793 * @return The position of the invalid character.
794 */
795 private int validateName(String text) {
796 for (int i = 0; i < text.length(); i++) {
797 char c = text.charAt(i);
798 if (Character.isLetterOrDigit(c) ||
799 c == '-' ||
800 c == '_' ||
801 c == '.' ||
802 c == ' ' ||
803 c == ',')
804 continue;
805 else
806 return i;
807 } // for
808
809 return -1;
810 }
811
812 private JSplitPane split;
813 private JList<TestFilter> leftList;
814 private DefaultListModel<TestFilter> listModel;
815 private int lastSelected = -1;
816 private TestFilter selectedFilter;
817
818 // just to help track current state
819 private int mode;
820 //private boolean focusSet;
821 private static final int EDITABLE = 0;
822 private static final int UNEDITABLE = 1;
823
824 // dialog buttons
825 private JButton applyBut;
826 private JButton helpBut;
827 private JButton doneBut;
828 private JButton cancelBut;
829 private JButton createBut;
830 private JButton deleteBut;
831 private JButton resetBut;
832
833 // info panel components
834 private JTextArea infoDesc;
835 private JTextField infoName;
836 //private JTextArea infoReason;
837
838 // naming panel
839 private CardLayout nameCards;
840 private JPanel namePanel;
841 private JTextField namingName;
842
843 // config panel
844 private CardLayout configCards;
845 private JPanel configPanel;
846 private Hashtable<ConfigurableTestFilter, String> configPanelHash;
847 private int configCounter; // to make a unique string
848
849 private JComponent EMPTY_CONFIG;
850 private JComponent EMPTY_NAMING;
851 private JComponent EMPTY_INFO;
852
853 private int NUMBER;
854
855 private static final String CONFIG_ACTIVE = "configa";
856 private static final String CONFIG_EMPTY = "confige";
857 private static final String NAMING_ACTIVE = "naminga";
858 private static final String NAMING_EMPTY = "naminge";
859 private static final String INFO_ACTIVE = "infoa";
860 private static final String INFO_EMPTY = "infoe";
861 }
862
863 }
|