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