KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > gui > ConfigFrame


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.gui;
11
12 import java.util.*;
13
14 import java.awt.Dimension JavaDoc;
15 import java.awt.event.*;
16 import javax.swing.*;
17 import javax.swing.event.*;
18
19 import org.jgap.data.config.*;
20
21 import info.clearthought.layout.*;
22
23 /**
24  * GUI for the JGAP Configurator.
25  *
26  * @author Siddhartha Azad
27  * @since 2.3
28  */

29 public class ConfigFrame
30     extends JFrame
31     implements IConfigInfo {
32   /** String containing the CVS revision. Read out via reflection!*/
33   private final static String JavaDoc CVS_REVISION = "$Revision: 1.18 $";
34
35   // data members of class ConfigFrame
36
private Object JavaDoc m_conHandler;
37
38   private boolean m_isRoot;
39
40   // list of JPanel objects added in this frame
41
private List m_panels;
42
43   // ListBox properties
44
private List m_listProps;
45
46   // TextBox properties
47
private List m_textProps;
48
49   // list of ListGroups
50
private List m_listGroups;
51
52   // list of TextGroups
53
private List m_textGroups;
54
55   private JPanel m_listPanel;
56
57   private JPanel m_textPanel;
58
59   private JPanel m_configPanel;
60
61   private JButton m_configButton;
62
63   private ConfigButtonListener m_cbl;
64
65   private JTextField m_fileName;
66
67   private JButton m_configureButton;
68
69   private JTextField m_configItem;
70
71   private Configurable m_conObj;
72
73   // the parent frame of this frame
74
private ConfigFrame m_parent;
75
76   // default name for the config file
77
private static final String JavaDoc m_defaultConfigFile = "jgap.con";
78
79   /**
80    * Constructor
81    * @param a_parent
82    * @param a_title the title of the frame
83    * @param a_isRoot
84    *
85    * @author Siddhartha Azad
86    * @since 2.3
87    */

88   ConfigFrame(final ConfigFrame a_parent, final String JavaDoc a_title,
89               final boolean a_isRoot) {
90     super(a_title);
91     m_panels = Collections.synchronizedList(new ArrayList());
92     m_textProps = Collections.synchronizedList(new ArrayList());
93     m_listProps = Collections.synchronizedList(new ArrayList());
94     m_listGroups = Collections.synchronizedList(new ArrayList());
95     m_textGroups = Collections.synchronizedList(new ArrayList());
96     m_cbl = new ConfigButtonListener(this);
97     m_isRoot = a_isRoot;
98     m_parent = a_parent;
99   }
100
101   /**
102    * Does the initial setup of the JFrame and shows it.
103    * @param a_conHandler the configuration handler from which this ConfigFrame
104    * would get information
105    *
106    * @author Siddhartha Azad
107    * @since 2.3
108    */

109   public void createAndShowGUI(final Object JavaDoc a_conHandler) {
110     JFrame.setDefaultLookAndFeelDecorated(true);
111     m_conHandler = a_conHandler;
112     // display
113
pack();
114     setVisible(true);
115     setBounds(100, 100, 300, 300);
116     setSize(500, 300);
117     try {
118       MetaConfig mt = MetaConfig.getInstance();
119     }
120     catch (MetaConfigException mcEx) {
121       JOptionPane.showMessageDialog(null,
122                                     "Exception while parsing JGAP Meta"
123                                     + " Config file "
124                                     + mcEx.getMessage(),
125                                     "Meta Config Exception",
126                                     JOptionPane.ERROR_MESSAGE);
127     }
128     catch (Exception JavaDoc ex) {
129       JOptionPane.showMessageDialog(null,
130                                     "Exception while parsing JGAP Meta Config"
131                                     + " file "
132                                     + ex.getMessage(),
133                                     "Meta Config Exception",
134                                     JOptionPane.ERROR_MESSAGE);
135     }
136     setup();
137     show();
138     if (m_isRoot) {
139       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
140     }
141     else {
142       setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
143     }
144   }
145
146   /**
147    * Getter for the Configuration Information on this frame.
148    * @return The ConfigData object containing the configuration
149    * information on this frame
150    *
151    * @author Siddhartha Azad
152    * @since 2.3
153    */

154   public ConfigData getConfigData() {
155     ConfigData cd = new ConfigData();
156     cd.setNS(m_conHandler.getClass().getName());
157     // add lists
158
List values;
159     try {
160       Iterator lIter = m_listGroups.iterator();
161       while (lIter.hasNext()) {
162         ListGroup lg = (ListGroup) lIter.next();
163         values = Collections.synchronizedList(new ArrayList());
164         Enumeration e = lg.getOutListModel().elements();
165         while (e.hasMoreElements()) {
166           String JavaDoc val = (String JavaDoc) e.nextElement();
167           values.add(val);
168         }
169         cd.addListData(lg.getProp().getName(), values);
170       }
171       // add textFields
172
TextGroup tg;
173       Iterator tIter = m_textGroups.iterator();
174       while (tIter.hasNext()) {
175         tg = (TextGroup) tIter.next();
176         cd.addTextData(tg.getProp().getName(), tg.getTextField().getText());
177       }
178     }
179     catch (ClassCastException JavaDoc cex) {
180       JOptionPane.showMessageDialog(null, cex.getMessage(),
181                                     "ConfigFrame.getConfigData():Configuration"
182                                     + " Error",
183                                     JOptionPane.INFORMATION_MESSAGE);
184     }
185     return cd;
186   }
187
188   /**
189    * Get the config file to write to.
190    * @return the config file name to write to
191    *
192    * @author Siddhartha Azad
193    * @since 2.3
194    */

195   public String JavaDoc getFileName() {
196     // only the root frame has the text box for the filename
197
if (m_isRoot) {
198       String JavaDoc fName = m_fileName.getText();
199       // use a default file name
200
if (fName.equals("")) {
201         fName = ConfigFrame.m_defaultConfigFile;
202       }
203       return fName;
204     }
205     else {
206       return m_parent.getFileName();
207     }
208   }
209
210   /**
211    * Setup the GUI.
212    * There are 3 maximum panels at this time. The first one contains JLists if
213    * there are configurable values that can be choosen from a list of items.
214    * The second panel contains all values configurable via a JTextField. The
215    * third panel contains the filename and configure button.
216    *
217    * @author Siddhartha Azad
218    * @since 2.3
219    */

220   private void setup() {
221     int numLists = 0, numTexts = 0;
222     List props = null;
223     try {
224       /** @todo find a better way to get the classname than getNS() */
225       props = MetaConfig.getInstance().getConfigProperty(m_conHandler.getClass().getName());
226     }
227     catch (Exception JavaDoc ex) {
228       JOptionPane.showMessageDialog(null, ex.getMessage(),
229                                     "Configuration Error: Could not get"
230                                     + " properties for class "
231                                     + m_conHandler.getClass().getName(),
232                                     JOptionPane.INFORMATION_MESSAGE);
233     }
234     if (props == null) {
235       JOptionPane.showMessageDialog(null,
236                                     "setup():No Configurable Properties in"
237                                     + " this Configuration",
238                                     "Configuration Message",
239                                     JOptionPane.INFORMATION_MESSAGE);
240       return;
241     }
242     Iterator iter = props.iterator();
243     while (iter.hasNext()) {
244       try {
245         ConfigProperty prop = (ConfigProperty) iter.next();
246         if (prop.getWidget().equals("JList")) {
247           numLists++;
248           m_listProps.add(prop);
249         }
250         else if (prop.getWidget().equals("JTextField")) {
251           numTexts++;
252           m_textProps.add(prop);
253         }
254         else {
255           // Only JLists and JTextFields allowed at this point
256
JOptionPane.showMessageDialog(null,
257                                         "Unknown Widget " + prop.getWidget(),
258                                         "Configuration Error",
259                                         JOptionPane.INFORMATION_MESSAGE);
260         }
261       }
262       catch (ClassCastException JavaDoc cex) {
263         JOptionPane.showMessageDialog(null,
264                                       cex.getMessage(),
265                                       "ConfigError.setup():Configuration Error:"
266                                       + " Invalid cast",
267                                       JOptionPane.INFORMATION_MESSAGE);
268       }
269     }
270     // If no known widgets are present, a GUI cannot be rendered
271
if (numLists == 0 && numTexts == 0) {
272       JOptionPane.showMessageDialog(null,
273                                     "No Configurable Properties in this"
274                                     + " Configuration",
275                                     "Configuration Information",
276                                     JOptionPane.INFORMATION_MESSAGE);
277       return;
278     }
279     // 2 panels at least, 1 for the widgets and 1 in the end for the
280
// Frame specific buttons
281
int numPanels = 2;
282     if (numLists > 0 && numTexts > 0) {
283       numPanels = 3;
284     }
285     // add the appropriate number of panels
286
addWidgets(numPanels, numLists, numTexts);
287   }
288
289   /**
290    * Add the widgets to the frame.
291    *
292    * @param a_numPanels Number of panels to add
293    * @param a_numLists Number of lists to add
294    * @param a_numTexts Number of text boxes to add
295    *
296    * @author Siddhartha Azad
297    * @since 2.3
298    */

299   private void addWidgets(int a_numPanels, final int a_numLists,
300                           final int a_numTexts) {
301     try {
302       a_numPanels = 3;
303       // TableLayout setup for the panels on the frame
304
double[][] tableArray = new double[2][a_numPanels];
305       double perPanel = (double) (1.0 / (double) a_numPanels);
306       int i = 0;
307       for (i = 0; i < a_numPanels - 1; i++) {
308         tableArray[1][i] = perPanel;
309       }
310       // give the remaining space to the last row
311
tableArray[1][i] = TableLayout.FILL;
312       // single column can take all the space available
313
tableArray[0][0] = TableLayout.FILL;
314       getContentPane().setLayout(new TableLayout(tableArray));
315       // add the panels to the frame now
316
int panelsAdded = 0;
317       // if we have lists to add
318
if (a_numLists > 0) {
319         double[][] panelSize;
320         // for every input list there's an output list and the buttons
321
// hence 3 columns for every list
322
int numCols = 3 * a_numLists;
323         // TableLayout setup for the list panel
324
panelSize = new double[2][numCols];
325         double space = (double) (1.0 / (double) a_numLists);
326         // 40% space to the lists, 20% to the buttons
327
double listSpace = space * 0.4;
328         double buttonSpace = space * 0.2;
329         for (int itr = 0; itr < a_numLists; itr++) {
330           panelSize[0][3 * itr] = listSpace;
331           panelSize[0][3 * itr + 1] = buttonSpace;
332           panelSize[0][3 * itr + 2] = listSpace;
333         }
334         // single row can take all the space
335
panelSize[1][0] = TableLayout.FILL;
336         m_listPanel = new JPanel();
337         m_panels.add(m_listPanel);
338         m_listPanel.setLayout(new TableLayout(panelSize));
339         getContentPane().add(m_listPanel, new TableLayoutConstraints(
340             0, panelsAdded, 0, panelsAdded,
341             TableLayout.FULL, TableLayout.FULL));
342         // increment number of panels added
343
panelsAdded++;
344         // add the lists to the panel
345
Iterator iter = m_listProps.iterator(), valIter;
346         ConfigProperty prop;
347         ListGroup lg;
348         for (int itr1 = 0; itr1 < a_numLists && iter.hasNext(); itr1++) {
349           lg = new ListGroup(this);
350           m_listGroups.add(lg);
351           prop = (ConfigProperty) iter.next();
352           lg.setProp(prop);
353           m_listPanel.add(lg.getListScroller(),
354                           new TableLayoutConstraints(3 * itr1, 0, 3 * itr1, 0,
355               TableLayout.CENTER, TableLayout.CENTER));
356           // add the button to move data from outlist back to list
357
m_listPanel.add(lg.getLButton(),
358                           new TableLayoutConstraints(3 * itr1 + 1, 0,
359               3 * itr1 + 1, 0,
360               TableLayout.CENTER, TableLayout.TOP));
361           // add the button to move data from list to outlist
362
m_listPanel.add(lg.getRButton(),
363                           new TableLayoutConstraints(3 * itr1 + 1, 0,
364               3 * itr1 + 1, 0,
365               TableLayout.CENTER, TableLayout.BOTTOM));
366           // added the item values to the list
367
valIter = prop.getValuesIter();
368           while (valIter.hasNext()) {
369             lg.getListModel().addElement(valIter.next());
370           }
371           m_listPanel.add(lg.getOutListScroller(),
372                           new TableLayoutConstraints(3 * itr1 + 2, 0,
373               3 * itr1 + 2, 0,
374               TableLayout.CENTER, TableLayout.CENTER));
375         }
376       }
377       // add the textFields
378
if (a_numTexts > 0) {
379         double[][] panelSize;
380         int numCols = a_numTexts * 2;
381         panelSize = new double[2][numCols];
382         // TableLayout setup for the JTextFields panel
383
double perText = (double) (1.0 / (double) numCols);
384         int itr = 0;
385         // add the panel for the texts fields
386
for (itr = 0; itr < numCols - 1; itr++) {
387           panelSize[0][itr] = perText;
388         }
389         panelSize[0][itr] = TableLayout.FILL;
390         // single row
391
panelSize[1][0] = TableLayout.FILL;
392         m_textPanel = new JPanel();
393         m_panels.add(m_textPanel);
394         m_textPanel.setLayout(new TableLayout(panelSize));
395         getContentPane().add(m_textPanel, new TableLayoutConstraints(
396             0, panelsAdded, 0, panelsAdded,
397             TableLayout.FULL, TableLayout.FULL));
398         panelsAdded++;
399         // add the text fields to the panel
400
TextGroup tg;
401         Iterator iter = m_textProps.iterator(), valIter;
402         ConfigProperty prop;
403         for (int itr1 = 0; itr1 < a_numTexts && iter.hasNext(); itr1++) {
404           tg = new TextGroup();
405           m_textGroups.add(tg);
406           prop = (ConfigProperty) iter.next();
407           tg.setProp(prop);
408           JLabel label = tg.getLabel();
409           label.setText(prop.getName());
410           m_textPanel.add(label,
411                           new TableLayoutConstraints(itr1, 0, itr1, 0,
412               TableLayout.RIGHT, TableLayout.CENTER));
413           m_textPanel.add(tg.getTextField(),
414                           new TableLayoutConstraints(itr1 + 1, 0, itr1 + 1, 0,
415               TableLayout.LEFT, TableLayout.CENTER));
416         }
417       }
418       // add the configure button
419
double[][] panelSize;
420       panelSize = new double[2][4];
421       // percentage per column for the tablelayout
422
panelSize[0][0] = .25;
423       panelSize[0][1] = .25;
424       panelSize[0][2] = .25;
425       panelSize[0][3] = .25;
426       // single row
427
panelSize[1][0] = TableLayout.FILL;
428       m_configPanel = new JPanel();
429       m_panels.add(m_configPanel);
430       m_configPanel.setLayout(new TableLayout(panelSize));
431       getContentPane().add(m_configPanel, new TableLayoutConstraints(
432           0, panelsAdded, 0, panelsAdded,
433           TableLayout.FULL, TableLayout.FULL));
434       // add the textfield for the config file name
435
m_configItem = new JTextField(50);
436       m_configPanel.add(m_configItem,
437                         new TableLayoutConstraints(0, 0, 0, 0,
438           TableLayout.RIGHT,
439           TableLayout.CENTER));
440       m_configureButton = new JButton("Configure");
441       m_configureButton.addActionListener(m_cbl);
442       m_configPanel.add(m_configureButton,
443                         new TableLayoutConstraints(1, 0, 1, 0,
444           TableLayout.LEFT,
445           TableLayout.CENTER));
446       if (m_isRoot) {
447         m_fileName = new JTextField("jgap.con");
448         m_configPanel.add(m_fileName,
449                           new TableLayoutConstraints(2, 0, 2, 0,
450             TableLayout.RIGHT, TableLayout.CENTER));
451         m_configButton = new JButton("Generate");
452         m_configButton.addActionListener(m_cbl);
453         m_configPanel.add(m_configButton,
454                           new TableLayoutConstraints(3, 0, 3, 0,
455             TableLayout.LEFT, TableLayout.CENTER));
456       }
457       else {
458         m_configButton = new JButton("Save Configuration");
459         m_configButton.addActionListener(m_cbl);
460         m_configPanel.add(m_configButton,
461                           new TableLayoutConstraints(3, 0, 3, 0,
462             TableLayout.LEFT, TableLayout.CENTER));
463       }
464     }
465     catch (Exception JavaDoc ex) {
466       JOptionPane.showMessageDialog(null,
467                                     "Exception" + ex.toString(),
468                                     "This is the title",
469                                     JOptionPane.INFORMATION_MESSAGE);
470     }
471   }
472
473   /**
474    * This class groups the property data structure along with the JLists
475    * associated with it.
476    *
477    * @author Siddhartha Azad
478    * @since 2.3
479    */

480   public class ListGroup {
481     // list that will display the available items
482
private JList m_list;
483
484     // model for list
485
private DefaultListModel m_listModel;
486
487     private JScrollPane m_listScroller;
488
489     // list that will display the selected items
490
private JList m_outList;
491
492     // model for outList
493
private DefaultListModel m_outListModel;
494
495     private JScrollPane m_outListScroller;
496
497     private ConfigListSelectionListener m_outListListener;
498
499     // buttons to move data to/from lists
500
private JButton m_lButton;
501
502     private JButton m_rButton;
503
504     // property object associated with this ListGroup
505
private ConfigProperty m_prop;
506
507     private ListButtonListener m_listBL;
508
509     private ConfigFrame m_frame;
510
511     /**
512      * Constructor responsible for creating all items that go on the list
513      * panel.
514      *
515      * @author Siddhartha Azad
516      * @since 2.3
517      */

518     ListGroup(final ConfigFrame a_frame) {
519       m_frame = a_frame;
520       // create the List of values
521
m_listModel = new DefaultListModel();
522       m_list = new JList(m_listModel);
523       m_list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
524       m_list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
525       m_list.setVisibleRowCount( -1);
526       m_listScroller = new JScrollPane(m_list);
527       m_listScroller.setPreferredSize(new Dimension JavaDoc(250, 80));
528       // create the output list
529
m_outListModel = new DefaultListModel();
530       m_outList = new JList(m_outListModel);
531       m_outList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
532       m_outList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
533       m_outList.setVisibleRowCount( -1);
534       m_outListScroller = new JScrollPane(m_outList);
535       m_outListListener = new ConfigListSelectionListener(m_frame, m_outList);
536       m_outList.getSelectionModel().addListSelectionListener(m_outListListener);
537       m_outListScroller.setPreferredSize(new Dimension JavaDoc(250, 80));
538       // The buttons to move data to/from outList
539
m_listBL = new ListButtonListener(this);
540       m_lButton = new JButton("<-");
541       m_lButton.addActionListener(m_listBL);
542       m_rButton = new JButton("->");
543       m_rButton.addActionListener(m_listBL);
544     }
545
546     /**
547      * Getter for the ConfigProperty object associated with this ListGroup.
548      * @return the ConfigProperty object associated with this ListGroup
549      *
550      * @author Siddhartha Azad
551      * @since 2.3
552      */

553     public ConfigProperty getProp() {
554       return m_prop;
555     }
556
557     /**
558      * Setter for the ConfigProperty object associated with this ListGroup.
559      * This object is used to retrieve the values that the list is initialized
560      * with.
561      * @param a_prop the ConfigProperty object associated with this ListGroup
562      *
563      * @author Siddhartha Azad
564      * @since 2.3
565      */

566     public void setProp(final ConfigProperty a_prop) {
567       m_prop = a_prop;
568     }
569
570     /**
571      * @return the JList containing the items to select from
572      *
573      * @author Siddhartha Azad
574      * @since 2.3
575      */

576     public JList getList() {
577       return m_list;
578     }
579
580     /**
581      * @return DefaultListModel for the list
582      *
583      * @author Siddhartha Azad
584      * @since 2.3
585      */

586     public DefaultListModel getListModel() {
587       return m_listModel;
588     }
589
590     /**
591      * @return scroller for the list
592      *
593      * @author Siddhartha Azad
594      * @since 2.3
595      */

596     public JScrollPane getListScroller() {
597       return m_listScroller;
598     }
599
600     /**
601      * @return Output JList
602      *
603      * @author Siddhartha Azad
604      * @since 2.3
605      */

606     public JList getOutList() {
607       return m_outList;
608     }
609
610     /**
611      * Getter for the output list's associated model.
612      * @return DefaultListModel for the output list
613      *
614      * @author Siddhartha Azad
615      * @since 2.3
616      */

617     public DefaultListModel getOutListModel() {
618       return m_outListModel;
619     }
620
621     /**
622      * @return scroller for the output list
623      *
624      * @author Siddhartha Azad
625      * @since 2.3
626      */

627     public JScrollPane getOutListScroller() {
628       return m_outListScroller;
629     }
630
631     /**
632      * @return the button to move items from outlist to list
633      *
634      * @author Siddhartha Azad
635      * @since 2.3
636      */

637     public JButton getLButton() {
638       return m_lButton;
639     }
640
641     /**
642      * @return the button to move items from list to outlist
643      *
644      * @author Siddhartha Azad
645      * @since 2.3
646      */

647     public JButton getRButton() {
648       return m_rButton;
649     }
650
651     /**
652      * Move selected items from the output list back to the list.
653      *
654      * @author Siddhartha Azad
655      * @since 2.3
656      */

657     public void leftButtonPressed() {
658       int[] indices = m_outList.getSelectedIndices();
659       for (int i = 0; i < indices.length; i++) {
660         String JavaDoc removed = (String JavaDoc) m_outListModel.remove(indices[0]);
661         m_listModel.addElement(removed);
662       }
663     }
664
665     /**
666      * Move selected items from list to the output list.
667      *
668      * @author Siddhartha Azad
669      * @since 2.3
670      */

671     public void rightButtonPressed() {
672       int[] indices = m_list.getSelectedIndices();
673       for (int i = 0; i < indices.length; i++) {
674         String JavaDoc removed = (String JavaDoc) m_listModel.remove(indices[0]);
675         m_outListModel.addElement(removed);
676       }
677     }
678   }
679   /**
680    * This class groups the property data structure along with the JLists
681    * associated with it.
682    *
683    * @author Siddhartha Azad
684    * @since 2.3
685    */

686   class TextGroup {
687     private JTextField m_textField;
688
689     private JLabel m_label;
690
691     private ConfigProperty m_prop;
692
693     TextGroup() {
694       m_textField = new JTextField(20);
695       m_label = new JLabel();
696     }
697
698     public ConfigProperty getProp() {
699       return m_prop;
700     }
701
702     public void setProp(final ConfigProperty a_prop) {
703       m_prop = a_prop;
704     }
705
706     public JTextField getTextField() {
707       return m_textField;
708     }
709
710     public JLabel getLabel() {
711       return m_label;
712     }
713   }
714   /**
715    * Listener for the Configure button.
716    *
717    * @author Siddhartha Azad
718    * @since 2.3
719    */

720   class ConfigButtonListener
721       implements ActionListener {
722     private ConfigFrame m_frame;
723
724     ConfigButtonListener(final ConfigFrame a_frame) {
725       m_frame = a_frame;
726     }
727
728     public void actionPerformed(final ActionEvent a_e) {
729       // configButton is pressed
730
if (a_e.getActionCommand().equals("Configure")) {
731         String JavaDoc conStr = m_configItem.getText();
732         if (conStr.equals("")) {
733           JOptionPane.showMessageDialog(null,
734                                         "Configurable name is empty, cannot"
735                                         + " configure.",
736                                         "Configuration Error",
737                                         JOptionPane.INFORMATION_MESSAGE);
738         }
739         else {
740           try {
741             Class JavaDoc conClass;
742             m_conObj = null;
743             try {
744               conClass = Class.forName(conStr);
745             }
746             catch (ClassNotFoundException JavaDoc cnfEx) {
747               JOptionPane.showMessageDialog(null,
748                                             cnfEx.getMessage(),
749                                             "Configuration Error: Class not"
750                                             + " found",
751                                             JOptionPane.INFORMATION_MESSAGE);
752               return;
753             }
754             try {
755               m_conObj = (Configurable) conClass.
756                   newInstance();
757             }
758             catch (Exception JavaDoc ex) {
759               JOptionPane.showMessageDialog(null,
760                                             ex.getMessage(),
761                                             "Configuration Error:Could not"
762                                             + " create object",
763                                             JOptionPane.INFORMATION_MESSAGE);
764               return;
765             }
766             try {
767               SwingUtilities.invokeLater(new Runnable JavaDoc() {
768                 public void run() {
769                   try {
770                     GUIManager.getInstance().showFrame(m_frame, m_conObj);
771                   }
772                   catch (Exception JavaDoc ex) {
773                     JOptionPane.showMessageDialog(null, ex.getMessage(),
774                                                   "Configuration Error:Could"
775                                                   + " not create new Frame",
776                                                   JOptionPane.ERROR_MESSAGE);
777                   }
778                 }
779               });
780             }
781             catch (Exception JavaDoc ex) {
782               JOptionPane.showMessageDialog(null, ex.getMessage(),
783                                             "Configuration Error:Could not"
784                                             + " create new frame",
785                                             JOptionPane.ERROR_MESSAGE);
786             }
787           }
788           catch (Exception JavaDoc ex) {
789             JOptionPane.showMessageDialog(null,
790                                           ex.getMessage(),
791                                           "Configuration Error",
792                                           JOptionPane.INFORMATION_MESSAGE);
793           }
794         }
795       }
796       else {
797         // generate the config file
798
ConfigWriter.getInstance().write(m_frame);
799       }
800     }
801   }
802   /**
803    * Listener for list buttons to move items around.
804    *
805    * @author Siddhartha Azad
806    * @since 2.3
807    */

808   public class ListButtonListener
809       implements ActionListener {
810     private ListGroup m_lg;
811
812     ListButtonListener(final ListGroup a_lg) {
813       m_lg = a_lg;
814     }
815
816     public void actionPerformed(final ActionEvent a_e) {
817       // one of the list buttons is pressed
818
if (a_e.getActionCommand().equals("<-")) {
819         // from outList to list
820
m_lg.leftButtonPressed();
821       }
822       else {
823         // from list to outList
824
m_lg.rightButtonPressed();
825       }
826     }
827   }
828   /**
829    * Listener for changes in the list of items.
830    *
831    * @author Siddhartha Azad
832    * @since 2.3
833    */

834   public class ConfigListSelectionListener
835       implements ListSelectionListener {
836     private JList m_list;
837
838     private ConfigFrame m_frame;
839
840     public ConfigListSelectionListener(final ConfigFrame a_frame,
841                                        final JList a_list) {
842       m_list = a_list;
843       m_frame = a_frame;
844     }
845
846     public void valueChanged(final ListSelectionEvent a_e) {
847       Object JavaDoc[] values = m_list.getSelectedValues();
848       if (values.length > 0) {
849         String JavaDoc value = (String JavaDoc) values[0];
850         notifySelection(value);
851       }
852     }
853   }
854   /**
855    * Notify the frame that a value has been selected in the output list for
856    * further configuration.
857    *
858    * @author Siddhartha Azad
859    * @since 2.3
860    */

861   private void notifySelection(final String JavaDoc a_value) {
862     m_configItem.setText(a_value);
863   }
864 }
865
Popular Tags