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