1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.conient; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.util.*; |
6 |
import javax.swing.*; |
7 |
import java.awt.BorderLayout; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.ActionEvent; |
10 |
|
11 |
/** |
12 |
* This panel holds the toolbar at the top. |
13 |
* The tool bar dispatches events to the ConnectionHandler. |
14 |
* |
15 |
* It also creates and starts the ConnectionHandler which is the |
16 |
* main thread for this application |
17 |
* |
18 |
* @author $Author: ajm4 $ |
19 |
* @version $Id: ControlPanel.java,v 1.9 2001/02/27 03:09:59 ajm4 Exp $ |
20 |
*/ |
21 |
public class ControlPanel extends JPanel { |
22 |
|
23 |
//---FINAL ATTRIBUTES--- |
24 |
|
25 |
/** |
26 |
* The current CVS revision of this class |
27 |
*/ |
28 |
public final String REVISION = "$Revision: 1.9 $"; |
29 |
|
30 |
//---STATIC METHODS--- |
31 |
|
32 |
//---CONSTRUCTORS--- |
33 |
|
34 |
/** |
35 |
* Constructs a new ControlPanel. |
36 |
* |
37 |
* @param data the data panel to be passed to the ConnectionHandler |
38 |
*/ |
39 |
public ControlPanel(DataPanel data) { |
40 |
super(); |
41 |
setLayout(new BorderLayout()); |
42 |
_handler = new ConnectionHandler(data, _actionQueue); |
43 |
add(_toolBar, "North"); |
44 |
_handler.start(); |
45 |
} |
46 |
|
47 |
//---PUBLIC METHODS--- |
48 |
|
49 |
//---PRIVATE METHODS--- |
50 |
|
51 |
/** |
52 |
* Sets up the tool bar, adding action listeners |
53 |
* to dispatch events to the ConnectionHandler |
54 |
*/ |
55 |
private JToolBar setupToolBar() { |
56 |
JButton connectButton = new JButton("Connect", new ImageIcon("./uk/ac/ukc/iscream/conient/control16.gif")); |
57 |
connectButton.addActionListener(new ActionListener() { |
58 |
public void actionPerformed(ActionEvent e) { |
59 |
_actionQueue.add(new Integer(ConnectionHandler.CONNECT)); |
60 |
} |
61 |
}); |
62 |
JButton disconnectButton = new JButton("Disconnect", new ImageIcon("./uk/ac/ukc/iscream/conient/stop16.gif")); |
63 |
disconnectButton.addActionListener(new ActionListener() { |
64 |
public void actionPerformed(ActionEvent e) { |
65 |
_actionQueue.add(new Integer(ConnectionHandler.DISCONNECT)); |
66 |
} |
67 |
}); |
68 |
|
69 |
JButton startDataButton = new JButton("Start Data", new ImageIcon("./uk/ac/ukc/iscream/conient/data16.gif")); |
70 |
startDataButton.addActionListener(new ActionListener() { |
71 |
public void actionPerformed(ActionEvent e) { |
72 |
_actionQueue.add(new Integer(ConnectionHandler.STARTDATA)); |
73 |
} |
74 |
}); |
75 |
JButton stopDataButton = new JButton("Stop Data", new ImageIcon("./uk/ac/ukc/iscream/conient/stop16.gif")); |
76 |
stopDataButton.addActionListener(new ActionListener() { |
77 |
public void actionPerformed(ActionEvent e) { |
78 |
_actionQueue.add(new Integer(ConnectionHandler.STOPDATA)); |
79 |
} |
80 |
}); |
81 |
|
82 |
JToolBar bar = new JToolBar(JToolBar.HORIZONTAL); |
83 |
bar.add(connectButton); |
84 |
bar.add(disconnectButton); |
85 |
bar.addSeparator(); |
86 |
bar.add(startDataButton); |
87 |
bar.add(stopDataButton); |
88 |
|
89 |
bar.add(Box.createGlue()); |
90 |
JLabel image = new JLabel(new ImageIcon("./uk/ac/ukc/iscream/conient/i-scream.gif")); |
91 |
bar.add(image); |
92 |
return bar; |
93 |
} |
94 |
|
95 |
public JMenuBar setupMenuBar() { |
96 |
JMenuBar bar = new JMenuBar(); |
97 |
|
98 |
JMenu conientMenu = new JMenu("Conient"); |
99 |
JMenuItem modifiyConfig = new JMenuItem("Modifiy Configuration"); |
100 |
modifiyConfig.addActionListener(new ActionListener() { |
101 |
public void actionPerformed(ActionEvent e) { |
102 |
Configuration.getInstance().GUIReconfiguration(); |
103 |
} |
104 |
}); |
105 |
conientMenu.add(modifiyConfig); |
106 |
conientMenu.addSeparator(); |
107 |
JMenuItem saveConfig = new JMenuItem("Save Configuration"); |
108 |
saveConfig.addActionListener(new ActionListener() { |
109 |
public void actionPerformed(ActionEvent e) { |
110 |
if (Configuration.getInstance().getUsingSpecificConfig()) { |
111 |
Configuration.getInstance().saveConfiguration(); |
112 |
} else { |
113 |
Configuration.getInstance().saveNewConfiguration(); |
114 |
} |
115 |
} |
116 |
}); |
117 |
conientMenu.add(saveConfig); |
118 |
|
119 |
JMenuItem saveAsConfig = new JMenuItem("Save Configuration As..."); |
120 |
saveAsConfig.addActionListener(new ActionListener() { |
121 |
public void actionPerformed(ActionEvent e) { |
122 |
Configuration.getInstance().saveNewConfiguration(); |
123 |
} |
124 |
}); |
125 |
conientMenu.add(saveAsConfig); |
126 |
|
127 |
JMenuItem saveDefaultConfig = new JMenuItem("Save Configuration As Default"); |
128 |
saveDefaultConfig.addActionListener(new ActionListener() { |
129 |
public void actionPerformed(ActionEvent e) { |
130 |
Configuration.getInstance().saveDefaultConfiguration(); |
131 |
} |
132 |
}); |
133 |
conientMenu.add(saveDefaultConfig); |
134 |
|
135 |
JMenuItem loadConfig = new JMenuItem("Load Configuration..."); |
136 |
loadConfig.addActionListener(new ActionListener() { |
137 |
public void actionPerformed(ActionEvent e) { |
138 |
Configuration.getInstance().loadConfiguration(); |
139 |
} |
140 |
}); |
141 |
conientMenu.add(loadConfig); |
142 |
conientMenu.addSeparator(); |
143 |
JMenuItem quit = new JMenuItem("Quit"); |
144 |
quit.addActionListener(new ActionListener() { |
145 |
public void actionPerformed(ActionEvent e) { |
146 |
_actionQueue.add(new Integer(ConnectionHandler.QUIT)); |
147 |
} |
148 |
}); |
149 |
conientMenu.add(quit); |
150 |
bar.add(conientMenu); |
151 |
|
152 |
JMenu connectionMenu = new JMenu("Connection"); |
153 |
JMenuItem controlConnect = new JMenuItem("Connect", new ImageIcon("./uk/ac/ukc/iscream/conient/control16.gif")); |
154 |
controlConnect.addActionListener(new ActionListener() { |
155 |
public void actionPerformed(ActionEvent e) { |
156 |
_actionQueue.add(new Integer(ConnectionHandler.CONNECT)); |
157 |
} |
158 |
}); |
159 |
connectionMenu.add(controlConnect); |
160 |
JMenuItem controlDisconnect = new JMenuItem("Disconnect", new ImageIcon("./uk/ac/ukc/iscream/conient/stop16.gif")); |
161 |
controlDisconnect.addActionListener(new ActionListener() { |
162 |
public void actionPerformed(ActionEvent e) { |
163 |
_actionQueue.add(new Integer(ConnectionHandler.DISCONNECT)); |
164 |
} |
165 |
}); |
166 |
connectionMenu.add(controlDisconnect); |
167 |
connectionMenu.addSeparator(); |
168 |
JMenuItem dataConnect = new JMenuItem("Start Data", new ImageIcon("./uk/ac/ukc/iscream/conient/data16.gif")); |
169 |
dataConnect.addActionListener(new ActionListener() { |
170 |
public void actionPerformed(ActionEvent e) { |
171 |
_actionQueue.add(new Integer(ConnectionHandler.STARTDATA)); |
172 |
} |
173 |
}); |
174 |
connectionMenu.add(dataConnect); |
175 |
JMenuItem dataDisconnect = new JMenuItem("Stop Data", new ImageIcon("./uk/ac/ukc/iscream/conient/stop16.gif")); |
176 |
dataDisconnect.addActionListener(new ActionListener() { |
177 |
public void actionPerformed(ActionEvent e) { |
178 |
_actionQueue.add(new Integer(ConnectionHandler.STOPDATA)); |
179 |
} |
180 |
}); |
181 |
connectionMenu.add(dataDisconnect); |
182 |
bar.add(connectionMenu); |
183 |
|
184 |
JMenu helpMenu = new JMenu("Help"); |
185 |
JMenuItem help = new JMenuItem("Help"); |
186 |
helpMenu.add(help); |
187 |
JMenuItem about = new JMenuItem("About"); |
188 |
helpMenu.add(about); |
189 |
bar.add(helpMenu); |
190 |
|
191 |
return bar; |
192 |
} |
193 |
|
194 |
//---ACCESSOR/MUTATOR METHODS--- |
195 |
|
196 |
public JMenuBar getMenuBar() { |
197 |
return _menuBar; |
198 |
} |
199 |
|
200 |
//---ATTRIBUTES--- |
201 |
|
202 |
/** |
203 |
* The tool bar for the control panel |
204 |
*/ |
205 |
JToolBar _toolBar = setupToolBar(); |
206 |
|
207 |
/** |
208 |
* The menu bar for the Frame |
209 |
*/ |
210 |
JMenuBar _menuBar = setupMenuBar(); |
211 |
|
212 |
/** |
213 |
* The queue that we will add actions to. |
214 |
*/ |
215 |
Queue _actionQueue = new Queue(); |
216 |
|
217 |
/** |
218 |
* The connection handler in use by the system. |
219 |
*/ |
220 |
ConnectionHandler _handler; |
221 |
|
222 |
//---STATIC ATTRIBUTES--- |
223 |
|
224 |
} |