001: /*
002: * This file is part of JGAP.
003: *
004: * JGAP offers a dual license model containing the LGPL as well as the MPL.
005: *
006: * For licensing information please see the file license.txt included with JGAP
007: * or have a look at the top of class org.jgap.Chromosome which representatively
008: * includes the JGAP license policy applicable for any file delivered with JGAP.
009: */
010: package org.jgap.gui;
011:
012: import java.util.*;
013:
014: import java.awt.Dimension;
015: import java.awt.event.*;
016: import javax.swing.*;
017: import javax.swing.event.*;
018:
019: import org.jgap.data.config.*;
020:
021: import info.clearthought.layout.*;
022:
023: /**
024: * GUI for the JGAP Configurator.
025: *
026: * @author Siddhartha Azad
027: * @since 2.3
028: */
029: public class ConfigFrame extends JFrame implements IConfigInfo {
030: /** String containing the CVS revision. Read out via reflection!*/
031: private final static String CVS_REVISION = "$Revision: 1.19 $";
032:
033: // data members of class ConfigFrame
034: private Object m_conHandler;
035:
036: private boolean m_isRoot;
037:
038: // list of JPanel objects added in this frame
039: private List m_panels;
040:
041: // ListBox properties
042: private List m_listProps;
043:
044: // TextBox properties
045: private List m_textProps;
046:
047: // list of ListGroups
048: private List m_listGroups;
049:
050: // list of TextGroups
051: private List m_textGroups;
052:
053: private JPanel m_listPanel;
054:
055: private JPanel m_textPanel;
056:
057: private JPanel m_configPanel;
058:
059: private JButton m_configButton;
060:
061: private ConfigButtonListener m_cbl;
062:
063: private JTextField m_fileName;
064:
065: private JButton m_configureButton;
066:
067: private JTextField m_configItem;
068:
069: private Configurable m_conObj;
070:
071: // the parent frame of this frame
072: private ConfigFrame m_parent;
073:
074: // default name for the config file
075: private static final String m_defaultConfigFile = "jgap.con";
076:
077: /**
078: * Constructor
079: * @param a_parent
080: * @param a_title the title of the frame
081: * @param a_isRoot
082: *
083: * @author Siddhartha Azad
084: * @since 2.3
085: */
086: ConfigFrame(final ConfigFrame a_parent, final String a_title,
087: final boolean a_isRoot) {
088: super (a_title);
089: m_panels = Collections.synchronizedList(new ArrayList());
090: m_textProps = Collections.synchronizedList(new ArrayList());
091: m_listProps = Collections.synchronizedList(new ArrayList());
092: m_listGroups = Collections.synchronizedList(new ArrayList());
093: m_textGroups = Collections.synchronizedList(new ArrayList());
094: m_cbl = new ConfigButtonListener(this );
095: m_isRoot = a_isRoot;
096: m_parent = a_parent;
097: }
098:
099: /**
100: * Does the initial setup of the JFrame and shows it.
101: * @param a_conHandler the configuration handler from which this ConfigFrame
102: * would get information
103: *
104: * @author Siddhartha Azad
105: * @since 2.3
106: */
107: public void createAndShowGUI(final Object a_conHandler) {
108: JFrame.setDefaultLookAndFeelDecorated(true);
109: m_conHandler = a_conHandler;
110: // display
111: pack();
112: setVisible(true);
113: setBounds(100, 100, 300, 300);
114: setSize(500, 300);
115: try {
116: MetaConfig mt = MetaConfig.getInstance();
117: } catch (MetaConfigException mcEx) {
118: JOptionPane.showMessageDialog(null,
119: "Exception while parsing JGAP Meta"
120: + " Config file " + mcEx.getMessage(),
121: "Meta Config Exception", JOptionPane.ERROR_MESSAGE);
122: } catch (Exception ex) {
123: JOptionPane.showMessageDialog(null,
124: "Exception while parsing JGAP Meta Config"
125: + " file " + ex.getMessage(),
126: "Meta Config Exception", JOptionPane.ERROR_MESSAGE);
127: }
128: setup();
129: show();
130: if (m_isRoot) {
131: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132: } else {
133: setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
134: }
135: }
136:
137: /**
138: * Getter for the Configuration Information on this frame.
139: * @return The ConfigData object containing the configuration
140: * information on this frame
141: *
142: * @author Siddhartha Azad
143: * @since 2.3
144: */
145: public ConfigData getConfigData() {
146: ConfigData cd = new ConfigData();
147: cd.setNS(m_conHandler.getClass().getName());
148: // add lists
149: List values;
150: try {
151: Iterator lIter = m_listGroups.iterator();
152: while (lIter.hasNext()) {
153: ListGroup lg = (ListGroup) lIter.next();
154: values = Collections.synchronizedList(new ArrayList());
155: Enumeration e = lg.getOutListModel().elements();
156: while (e.hasMoreElements()) {
157: String val = (String) e.nextElement();
158: values.add(val);
159: }
160: cd.addListData(lg.getProp().getName(), values);
161: }
162: // add textFields
163: TextGroup tg;
164: Iterator tIter = m_textGroups.iterator();
165: while (tIter.hasNext()) {
166: tg = (TextGroup) tIter.next();
167: cd.addTextData(tg.getProp().getName(), tg
168: .getTextField().getText());
169: }
170: } catch (ClassCastException cex) {
171: JOptionPane
172: .showMessageDialog(null, cex.getMessage(),
173: "ConfigFrame.getConfigData():Configuration"
174: + " Error",
175: JOptionPane.INFORMATION_MESSAGE);
176: }
177: return cd;
178: }
179:
180: /**
181: * Get the config file to write to.
182: * @return the config file name to write to
183: *
184: * @author Siddhartha Azad
185: * @since 2.3
186: */
187: public String getFileName() {
188: // only the root frame has the text box for the filename
189: if (m_isRoot) {
190: String fName = m_fileName.getText();
191: // use a default file name
192: if (fName.equals("")) {
193: fName = ConfigFrame.m_defaultConfigFile;
194: }
195: return fName;
196: } else {
197: return m_parent.getFileName();
198: }
199: }
200:
201: /**
202: * Setup the GUI.
203: * There are 3 maximum panels at this time. The first one contains JLists if
204: * there are configurable values that can be choosen from a list of items.
205: * The second panel contains all values configurable via a JTextField. The
206: * third panel contains the filename and configure button.
207: *
208: * @author Siddhartha Azad
209: * @since 2.3
210: */
211: private void setup() {
212: int numLists = 0, numTexts = 0;
213: List props = null;
214: try {
215: /** @todo find a better way to get the classname than getNS() */
216: props = MetaConfig.getInstance().getConfigProperty(
217: m_conHandler.getClass().getName());
218: } catch (Exception ex) {
219: JOptionPane.showMessageDialog(null, ex.getMessage(),
220: "Configuration Error: Could not get"
221: + " properties for class "
222: + m_conHandler.getClass().getName(),
223: JOptionPane.INFORMATION_MESSAGE);
224: }
225: if (props == null) {
226: JOptionPane.showMessageDialog(null,
227: "setup():No Configurable Properties in"
228: + " this Configuration",
229: "Configuration Message",
230: JOptionPane.INFORMATION_MESSAGE);
231: return;
232: }
233: Iterator iter = props.iterator();
234: while (iter.hasNext()) {
235: try {
236: ConfigProperty prop = (ConfigProperty) iter.next();
237: if (prop.getWidget().equals("JList")) {
238: numLists++;
239: m_listProps.add(prop);
240: } else if (prop.getWidget().equals("JTextField")) {
241: numTexts++;
242: m_textProps.add(prop);
243: } else {
244: // Only JLists and JTextFields allowed at this point
245: JOptionPane.showMessageDialog(null,
246: "Unknown Widget " + prop.getWidget(),
247: "Configuration Error",
248: JOptionPane.INFORMATION_MESSAGE);
249: }
250: } catch (ClassCastException cex) {
251: JOptionPane.showMessageDialog(null, cex.getMessage(),
252: "ConfigError.setup():Configuration Error:"
253: + " Invalid cast",
254: JOptionPane.INFORMATION_MESSAGE);
255: }
256: }
257: // If no known widgets are present, a GUI cannot be rendered
258: if (numLists == 0 && numTexts == 0) {
259: JOptionPane.showMessageDialog(null,
260: "No Configurable Properties in this"
261: + " Configuration",
262: "Configuration Information",
263: JOptionPane.INFORMATION_MESSAGE);
264: return;
265: }
266: // 2 panels at least, 1 for the widgets and 1 in the end for the
267: // Frame specific buttons
268: int numPanels = 2;
269: if (numLists > 0 && numTexts > 0) {
270: numPanels = 3;
271: }
272: // add the appropriate number of panels
273: addWidgets(numPanels, numLists, numTexts);
274: }
275:
276: /**
277: * Add the widgets to the frame.
278: *
279: * @param a_numPanels Number of panels to add
280: * @param a_numLists Number of lists to add
281: * @param a_numTexts Number of text boxes to add
282: *
283: * @author Siddhartha Azad
284: * @since 2.3
285: */
286: private void addWidgets(int a_numPanels, final int a_numLists,
287: final int a_numTexts) {
288: try {
289: a_numPanels = 3;
290: // TableLayout setup for the panels on the frame
291: double[][] tableArray = new double[2][a_numPanels];
292: double perPanel = (double) (1.0 / (double) a_numPanels);
293: int i = 0;
294: for (i = 0; i < a_numPanels - 1; i++) {
295: tableArray[1][i] = perPanel;
296: }
297: // give the remaining space to the last row
298: tableArray[1][i] = TableLayout.FILL;
299: // single column can take all the space available
300: tableArray[0][0] = TableLayout.FILL;
301: getContentPane().setLayout(new TableLayout(tableArray));
302: // add the panels to the frame now
303: int panelsAdded = 0;
304: // if we have lists to add
305: if (a_numLists > 0) {
306: double[][] panelSize;
307: // for every input list there's an output list and the buttons
308: // hence 3 columns for every list
309: int numCols = 3 * a_numLists;
310: // TableLayout setup for the list panel
311: panelSize = new double[2][numCols];
312: double space = (double) (1.0 / (double) a_numLists);
313: // 40% space to the lists, 20% to the buttons
314: double listSpace = space * 0.4;
315: double buttonSpace = space * 0.2;
316: for (int itr = 0; itr < a_numLists; itr++) {
317: panelSize[0][3 * itr] = listSpace;
318: panelSize[0][3 * itr + 1] = buttonSpace;
319: panelSize[0][3 * itr + 2] = listSpace;
320: }
321: // single row can take all the space
322: panelSize[1][0] = TableLayout.FILL;
323: m_listPanel = new JPanel();
324: m_panels.add(m_listPanel);
325: m_listPanel.setLayout(new TableLayout(panelSize));
326: getContentPane().add(
327: m_listPanel,
328: new TableLayoutConstraints(0, panelsAdded, 0,
329: panelsAdded, TableLayout.FULL,
330: TableLayout.FULL));
331: // increment number of panels added
332: panelsAdded++;
333: // add the lists to the panel
334: Iterator iter = m_listProps.iterator(), valIter;
335: ConfigProperty prop;
336: ListGroup lg;
337: for (int itr1 = 0; itr1 < a_numLists && iter.hasNext(); itr1++) {
338: lg = new ListGroup(this );
339: m_listGroups.add(lg);
340: prop = (ConfigProperty) iter.next();
341: lg.setProp(prop);
342: m_listPanel.add(lg.getListScroller(),
343: new TableLayoutConstraints(3 * itr1, 0,
344: 3 * itr1, 0, TableLayout.CENTER,
345: TableLayout.CENTER));
346: // add the button to move data from outlist back to list
347: m_listPanel
348: .add(lg.getLButton(),
349: new TableLayoutConstraints(
350: 3 * itr1 + 1, 0,
351: 3 * itr1 + 1, 0,
352: TableLayout.CENTER,
353: TableLayout.TOP));
354: // add the button to move data from list to outlist
355: m_listPanel.add(lg.getRButton(),
356: new TableLayoutConstraints(3 * itr1 + 1, 0,
357: 3 * itr1 + 1, 0,
358: TableLayout.CENTER,
359: TableLayout.BOTTOM));
360: // added the item values to the list
361: valIter = prop.getValuesIter();
362: while (valIter.hasNext()) {
363: lg.getListModel().addElement(valIter.next());
364: }
365: m_listPanel.add(lg.getOutListScroller(),
366: new TableLayoutConstraints(3 * itr1 + 2, 0,
367: 3 * itr1 + 2, 0,
368: TableLayout.CENTER,
369: TableLayout.CENTER));
370: }
371: }
372: // add the textFields
373: if (a_numTexts > 0) {
374: double[][] panelSize;
375: int numCols = a_numTexts * 2;
376: panelSize = new double[2][numCols];
377: // TableLayout setup for the JTextFields panel
378: double perText = (double) (1.0 / (double) numCols);
379: int itr = 0;
380: // add the panel for the texts fields
381: for (itr = 0; itr < numCols - 1; itr++) {
382: panelSize[0][itr] = perText;
383: }
384: panelSize[0][itr] = TableLayout.FILL;
385: // single row
386: panelSize[1][0] = TableLayout.FILL;
387: m_textPanel = new JPanel();
388: m_panels.add(m_textPanel);
389: m_textPanel.setLayout(new TableLayout(panelSize));
390: getContentPane().add(
391: m_textPanel,
392: new TableLayoutConstraints(0, panelsAdded, 0,
393: panelsAdded, TableLayout.FULL,
394: TableLayout.FULL));
395: panelsAdded++;
396: // add the text fields to the panel
397: TextGroup tg;
398: Iterator iter = m_textProps.iterator(), valIter;
399: ConfigProperty prop;
400: for (int itr1 = 0; itr1 < a_numTexts && iter.hasNext(); itr1++) {
401: tg = new TextGroup();
402: m_textGroups.add(tg);
403: prop = (ConfigProperty) iter.next();
404: tg.setProp(prop);
405: JLabel label = tg.getLabel();
406: label.setText(prop.getName());
407: m_textPanel.add(label, new TableLayoutConstraints(
408: itr1, 0, itr1, 0, TableLayout.RIGHT,
409: TableLayout.CENTER));
410: m_textPanel.add(tg.getTextField(),
411: new TableLayoutConstraints(itr1 + 1, 0,
412: itr1 + 1, 0, TableLayout.LEFT,
413: TableLayout.CENTER));
414: }
415: }
416: // add the configure button
417: double[][] panelSize;
418: panelSize = new double[2][4];
419: // percentage per column for the tablelayout
420: panelSize[0][0] = .25;
421: panelSize[0][1] = .25;
422: panelSize[0][2] = .25;
423: panelSize[0][3] = .25;
424: // single row
425: panelSize[1][0] = TableLayout.FILL;
426: m_configPanel = new JPanel();
427: m_panels.add(m_configPanel);
428: m_configPanel.setLayout(new TableLayout(panelSize));
429: getContentPane().add(
430: m_configPanel,
431: new TableLayoutConstraints(0, panelsAdded, 0,
432: panelsAdded, TableLayout.FULL,
433: TableLayout.FULL));
434: // add the textfield for the config file name
435: m_configItem = new JTextField(50);
436: m_configPanel.add(m_configItem, new TableLayoutConstraints(
437: 0, 0, 0, 0, TableLayout.RIGHT, TableLayout.CENTER));
438: m_configureButton = new JButton("Configure");
439: m_configureButton.addActionListener(m_cbl);
440: m_configPanel.add(m_configureButton,
441: new TableLayoutConstraints(1, 0, 1, 0,
442: TableLayout.LEFT, TableLayout.CENTER));
443: if (m_isRoot) {
444: m_fileName = new JTextField("jgap.con");
445: m_configPanel.add(m_fileName,
446: new TableLayoutConstraints(2, 0, 2, 0,
447: TableLayout.RIGHT, TableLayout.CENTER));
448: m_configButton = new JButton("Generate");
449: m_configButton.addActionListener(m_cbl);
450: m_configPanel.add(m_configButton,
451: new TableLayoutConstraints(3, 0, 3, 0,
452: TableLayout.LEFT, TableLayout.CENTER));
453: } else {
454: m_configButton = new JButton("Save Configuration");
455: m_configButton.addActionListener(m_cbl);
456: m_configPanel.add(m_configButton,
457: new TableLayoutConstraints(3, 0, 3, 0,
458: TableLayout.LEFT, TableLayout.CENTER));
459: }
460: } catch (Exception ex) {
461: JOptionPane.showMessageDialog(null, "Exception"
462: + ex.toString(), "This is the title",
463: JOptionPane.INFORMATION_MESSAGE);
464: }
465: }
466:
467: /**
468: * This class groups the property data structure along with the JLists
469: * associated with it.
470: *
471: * @author Siddhartha Azad
472: * @since 2.3
473: */
474: public class ListGroup {
475: // list that will display the available items
476: private JList m_list;
477:
478: // model for list
479: private DefaultListModel m_listModel;
480:
481: private JScrollPane m_listScroller;
482:
483: // list that will display the selected items
484: private JList m_outList;
485:
486: // model for outList
487: private DefaultListModel m_outListModel;
488:
489: private JScrollPane m_outListScroller;
490:
491: private ConfigListSelectionListener m_outListListener;
492:
493: // buttons to move data to/from lists
494: private JButton m_lButton;
495:
496: private JButton m_rButton;
497:
498: // property object associated with this ListGroup
499: private ConfigProperty m_prop;
500:
501: private ListButtonListener m_listBL;
502:
503: private ConfigFrame m_frame;
504:
505: /**
506: * Constructor responsible for creating all items that go on the list
507: * panel.
508: *
509: * @author Siddhartha Azad
510: * @since 2.3
511: */
512: ListGroup(final ConfigFrame a_frame) {
513: m_frame = a_frame;
514: // create the List of values
515: m_listModel = new DefaultListModel();
516: m_list = new JList(m_listModel);
517: m_list
518: .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
519: m_list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
520: m_list.setVisibleRowCount(-1);
521: m_listScroller = new JScrollPane(m_list);
522: m_listScroller.setPreferredSize(new Dimension(250, 80));
523: // create the output list
524: m_outListModel = new DefaultListModel();
525: m_outList = new JList(m_outListModel);
526: m_outList
527: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
528: m_outList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
529: m_outList.setVisibleRowCount(-1);
530: m_outListScroller = new JScrollPane(m_outList);
531: m_outListListener = new ConfigListSelectionListener(
532: m_frame, m_outList);
533: m_outList.getSelectionModel().addListSelectionListener(
534: m_outListListener);
535: m_outListScroller.setPreferredSize(new Dimension(250, 80));
536: // The buttons to move data to/from outList
537: m_listBL = new ListButtonListener(this );
538: m_lButton = new JButton("<-");
539: m_lButton.addActionListener(m_listBL);
540: m_rButton = new JButton("->");
541: m_rButton.addActionListener(m_listBL);
542: }
543:
544: /**
545: * Getter for the ConfigProperty object associated with this ListGroup.
546: * @return the ConfigProperty object associated with this ListGroup
547: *
548: * @author Siddhartha Azad
549: * @since 2.3
550: */
551: public ConfigProperty getProp() {
552: return m_prop;
553: }
554:
555: /**
556: * Setter for the ConfigProperty object associated with this ListGroup.
557: * This object is used to retrieve the values that the list is initialized
558: * with.
559: * @param a_prop the ConfigProperty object associated with this ListGroup
560: *
561: * @author Siddhartha Azad
562: * @since 2.3
563: */
564: public void setProp(final ConfigProperty a_prop) {
565: m_prop = a_prop;
566: }
567:
568: /**
569: * @return the JList containing the items to select from
570: *
571: * @author Siddhartha Azad
572: * @since 2.3
573: */
574: public JList getList() {
575: return m_list;
576: }
577:
578: /**
579: * @return DefaultListModel for the list
580: *
581: * @author Siddhartha Azad
582: * @since 2.3
583: */
584: public DefaultListModel getListModel() {
585: return m_listModel;
586: }
587:
588: /**
589: * @return scroller for the list
590: *
591: * @author Siddhartha Azad
592: * @since 2.3
593: */
594: public JScrollPane getListScroller() {
595: return m_listScroller;
596: }
597:
598: /**
599: * @return Output JList
600: *
601: * @author Siddhartha Azad
602: * @since 2.3
603: */
604: public JList getOutList() {
605: return m_outList;
606: }
607:
608: /**
609: * Getter for the output list's associated model.
610: * @return DefaultListModel for the output list
611: *
612: * @author Siddhartha Azad
613: * @since 2.3
614: */
615: public DefaultListModel getOutListModel() {
616: return m_outListModel;
617: }
618:
619: /**
620: * @return scroller for the output list
621: *
622: * @author Siddhartha Azad
623: * @since 2.3
624: */
625: public JScrollPane getOutListScroller() {
626: return m_outListScroller;
627: }
628:
629: /**
630: * @return the button to move items from outlist to list
631: *
632: * @author Siddhartha Azad
633: * @since 2.3
634: */
635: public JButton getLButton() {
636: return m_lButton;
637: }
638:
639: /**
640: * @return the button to move items from list to outlist
641: *
642: * @author Siddhartha Azad
643: * @since 2.3
644: */
645: public JButton getRButton() {
646: return m_rButton;
647: }
648:
649: /**
650: * Move selected items from the output list back to the list.
651: *
652: * @author Siddhartha Azad
653: * @since 2.3
654: */
655: public void leftButtonPressed() {
656: int[] indices = m_outList.getSelectedIndices();
657: for (int i = 0; i < indices.length; i++) {
658: String removed = (String) m_outListModel
659: .remove(indices[0]);
660: m_listModel.addElement(removed);
661: }
662: }
663:
664: /**
665: * Move selected items from list to the output list.
666: *
667: * @author Siddhartha Azad
668: * @since 2.3
669: */
670: public void rightButtonPressed() {
671: int[] indices = m_list.getSelectedIndices();
672: for (int i = 0; i < indices.length; i++) {
673: String removed = (String) m_listModel
674: .remove(indices[0]);
675: m_outListModel.addElement(removed);
676: }
677: }
678: }
679:
680: /**
681: * This class groups the property data structure along with the JLists
682: * associated with it.
683: *
684: * @author Siddhartha Azad
685: * @since 2.3
686: */
687: class TextGroup {
688: private JTextField m_textField;
689:
690: private JLabel m_label;
691:
692: private ConfigProperty m_prop;
693:
694: TextGroup() {
695: m_textField = new JTextField(20);
696: m_label = new JLabel();
697: }
698:
699: public ConfigProperty getProp() {
700: return m_prop;
701: }
702:
703: public void setProp(final ConfigProperty a_prop) {
704: m_prop = a_prop;
705: }
706:
707: public JTextField getTextField() {
708: return m_textField;
709: }
710:
711: public JLabel getLabel() {
712: return m_label;
713: }
714: }
715:
716: /**
717: * Listener for the Configure button.
718: *
719: * @author Siddhartha Azad
720: * @since 2.3
721: */
722: class ConfigButtonListener implements ActionListener {
723: private ConfigFrame m_frame;
724:
725: ConfigButtonListener(final ConfigFrame a_frame) {
726: m_frame = a_frame;
727: }
728:
729: public void actionPerformed(final ActionEvent a_e) {
730: // configButton is pressed
731: if (a_e.getActionCommand().equals("Configure")) {
732: String conStr = m_configItem.getText();
733: if (conStr.equals("")) {
734: JOptionPane.showMessageDialog(null,
735: "Configurable name is empty, cannot"
736: + " configure.",
737: "Configuration Error",
738: JOptionPane.INFORMATION_MESSAGE);
739: } else {
740: try {
741: Class conClass;
742: m_conObj = null;
743: try {
744: conClass = Class.forName(conStr);
745: } catch (ClassNotFoundException cnfEx) {
746: JOptionPane.showMessageDialog(null, cnfEx
747: .getMessage(),
748: "Configuration Error: Class not"
749: + " found",
750: JOptionPane.INFORMATION_MESSAGE);
751: return;
752: }
753: try {
754: m_conObj = (Configurable) conClass
755: .newInstance();
756: } catch (Exception ex) {
757: JOptionPane.showMessageDialog(null, ex
758: .getMessage(),
759: "Configuration Error:Could not"
760: + " create object",
761: JOptionPane.INFORMATION_MESSAGE);
762: return;
763: }
764: try {
765: SwingUtilities.invokeLater(new Runnable() {
766: public void run() {
767: try {
768: GUIManager.getInstance()
769: .showFrame(m_frame,
770: m_conObj);
771: } catch (Exception ex) {
772: JOptionPane
773: .showMessageDialog(
774: null,
775: ex.getMessage(),
776: "Configuration Error:Could"
777: + " not create new Frame",
778: JOptionPane.ERROR_MESSAGE);
779: }
780: }
781: });
782: } catch (Exception ex) {
783: JOptionPane.showMessageDialog(null, ex
784: .getMessage(),
785: "Configuration Error:Could not"
786: + " create new frame",
787: JOptionPane.ERROR_MESSAGE);
788: }
789: } catch (Exception ex) {
790: JOptionPane.showMessageDialog(null, ex
791: .getMessage(), "Configuration Error",
792: JOptionPane.INFORMATION_MESSAGE);
793: }
794: }
795: } else {
796: // generate the config file
797: ConfigWriter.getInstance().write(m_frame);
798: }
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 implements ActionListener {
809: private ListGroup m_lg;
810:
811: ListButtonListener(final ListGroup a_lg) {
812: m_lg = a_lg;
813: }
814:
815: public void actionPerformed(final ActionEvent a_e) {
816: // one of the list buttons is pressed
817: if (a_e.getActionCommand().equals("<-")) {
818: // from outList to list
819: m_lg.leftButtonPressed();
820: } else {
821: // from list to outList
822: m_lg.rightButtonPressed();
823: }
824: }
825: }
826:
827: /**
828: * Listener for changes in the list of items.
829: *
830: * @author Siddhartha Azad
831: * @since 2.3
832: */
833: public class ConfigListSelectionListener implements
834: ListSelectionListener {
835: private JList m_list;
836:
837: private ConfigFrame m_frame;
838:
839: public ConfigListSelectionListener(final ConfigFrame a_frame,
840: final JList a_list) {
841: m_list = a_list;
842: m_frame = a_frame;
843: }
844:
845: public void valueChanged(final ListSelectionEvent a_e) {
846: Object[] values = m_list.getSelectedValues();
847: if (values.length > 0) {
848: String value = (String) values[0];
849: notifySelection(value);
850: }
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 a_value) {
862: m_configItem.setText(a_value);
863: }
864: }
|