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