KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.*;
15
16 import org.jgap.*;
17 import org.jgap.data.config.*;
18
19 /**
20  * Singleton GUIManager for the JGAP Configurator.
21  * Creates a ConfigFrame on request, for a Configurable. Currently it only
22  * creates a ConfigFrame for the root object, that is a Configuration itself.
23  * In the future it will do the same for objects on the Root ConfigFrame that
24  * are in turn Configurable.
25  *
26  * @author Siddhartha Azad
27  * @author Klaus Meffert
28  * @since 2.3
29  */

30 public class GUIManager {
31   /** String containing the CVS revision. Read out via reflection!*/
32   private final static String JavaDoc CVS_REVISION = "$Revision: 1.10 $";
33
34   // The root frame
35
private ConfigFrame m_frame;
36
37   // the children frames
38
private List m_childFrames;
39
40   // children configurables, one to one mapping with childFrames
41
private List m_childCons;
42
43   // The entity to configure
44
private Configurable m_con;
45
46   /**
47    * Singleton instance of GUIManager
48    */

49   private static GUIManager m_gm;
50
51   /**
52    * @return a singleton GUIManager instance
53    *
54    * @author Siddhartha Azad
55    * @since 2.3
56    */

57   public static GUIManager getInstance() {
58     if (m_gm == null) {
59       m_gm = new GUIManager();
60     }
61     return m_gm;
62   }
63
64   /**
65    * Constructor for the frame.
66    *
67    * @author Siddhartha Azad
68    * @since 2.3
69    */

70   private GUIManager() {
71     m_frame = null;
72     m_childFrames = Collections.synchronizedList(new ArrayList());
73     m_childCons = Collections.synchronizedList(new ArrayList());
74   }
75
76   /**
77    * Create and show a new frame for a Configurable.
78    * @param a_con configurable to use
79    *
80    * @author Siddhartha Azad
81    * @since 2.3
82    */

83   public void showFrame(final ConfigFrame a_parent, final Configurable a_con)
84       throws Exception JavaDoc {
85     try {
86       // TODO add edit-components for configurable properties
87

88       // create the frame
89
if (a_con.getClass() == Configuration.class) {
90         m_frame = new ConfigFrame(null, "JGAP Configurator: "
91                                   + "Configuration",
92                                   true);
93         m_con = a_con;
94         m_frame.createAndShowGUI(a_con);
95       }
96       else {
97         ConfigFrame tmpFrame =
98             new ConfigFrame(a_parent, "JGAP Configurator: "
99                             + "Unknown Title",
100                             false);
101         m_childCons.add(a_con);
102         m_childFrames.add(tmpFrame);
103         tmpFrame.createAndShowGUI(a_con);
104       }
105     }
106     catch (Exception JavaDoc ex) {
107       JOptionPane.showMessageDialog(null,
108                                     "Could not show configuration frame. This"
109                                     + " attribute may not be configurable.",
110                                     "Configuration Error",
111                                     JOptionPane.INFORMATION_MESSAGE);
112     }
113   }
114
115   /**
116    * Main method for the GUI
117    * @param args not used
118    * @throws Exception
119    *
120    * @author Siddhartha Azad
121    * @since 2.3
122    */

123   public static void main(String JavaDoc[] args) {
124     try {
125       SwingUtilities.invokeLater(new Runnable JavaDoc() {
126         public void run() {
127           Configuration con = new Configuration();
128           // parent is null for the root frame
129
try {
130             GUIManager.getInstance().showFrame(null, con);
131           }
132           catch (Exception JavaDoc ex) {
133           }
134         }
135       });
136     }
137     catch (Exception JavaDoc ex) {
138       ex.printStackTrace();
139     }
140   }
141 }
142
Popular Tags