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