ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/ControlPanel.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/ControlPanel.java (file contents):
Revision 1.2 by ajm, Mon Jan 22 03:03:39 2001 UTC vs.
Revision 1.9 by ajm, Tue Feb 27 03:09:59 2001 UTC

# Line 1 | Line 1
1 < import javax.swing.*;
2 < import javax.swing.border.*;
3 < import java.awt.Color;
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 < import java.awt.*;
12 < import java.awt.event.*;
13 < import java.net.*;
14 < import java.io.*;
15 < import java.util.Date;
16 < import java.text.DateFormat;
17 < import java.util.Locale;
18 < import java.util.HashMap;
19 < import javax.swing.border.*;
20 <
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$
19 > * @version $Id$
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$";
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 <        _data = data;
21 <        _handler = new ConnectionHandler(_data, _actionQueue);
42 >        _handler = new ConnectionHandler(data, _actionQueue);
43          add(_toolBar, "North");
44          _handler.start();
45      }
46 <    
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");
57 <        connectButton.addActionListener(new ActionListener() {
56 >        JButton connectButton = new JButton("Connect", new ImageIcon("./uk/ac/ukc/iscream/conient/control16.gif"));
57 >        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              public void actionPerformed(ActionEvent e) {
86 <                _actionQueue.add(new Integer(ConnectionHandler.CONNECT));
86 >                Configuration.getInstance().GUIReconfiguration();
87              }
88          });
89 +        conientMenu.add(modifiyConfig);
90 +        conientMenu.addSeparator();
91 +        JMenuItem saveConfig = new JMenuItem("Save Configuration");
92 +        saveConfig.addActionListener(new ActionListener() {
93 +            public void actionPerformed(ActionEvent e) {
94 +                if (Configuration.getInstance().getUsingSpecificConfig()) {
95 +                    Configuration.getInstance().saveConfiguration();
96 +                } else {
97 +                    Configuration.getInstance().saveNewConfiguration();
98 +                }
99 +            }
100 +        });
101 +        conientMenu.add(saveConfig);
102          
103 <        JButton startDataButton = new JButton("Start Data");
104 <        startDataButton.addActionListener(new ActionListener() {
103 >        JMenuItem saveAsConfig = new JMenuItem("Save Configuration As...");
104 >        saveAsConfig.addActionListener(new ActionListener() {
105              public void actionPerformed(ActionEvent e) {
106 <                _actionQueue.add(new Integer(ConnectionHandler.STARTDATA));
106 >                Configuration.getInstance().saveNewConfiguration();
107              }
108          });
109 +        conientMenu.add(saveAsConfig);
110          
111 <        JButton stopDataButton = new JButton("Stop Data");
112 <        stopDataButton.addActionListener(new ActionListener() {
111 >        JMenuItem saveDefaultConfig = new JMenuItem("Save Configuration As Default");
112 >        saveDefaultConfig.addActionListener(new ActionListener() {
113              public void actionPerformed(ActionEvent e) {
114 <                _actionQueue.add(new Integer(ConnectionHandler.STOPDATA));
114 >                Configuration.getInstance().saveDefaultConfiguration();
115              }
116          });
117 +        conientMenu.add(saveDefaultConfig);
118          
119 <        JButton disconnectButton = new JButton("Disconnect");
120 <        disconnectButton.addActionListener(new ActionListener() {
119 >        JMenuItem loadConfig = new JMenuItem("Load Configuration...");
120 >        loadConfig.addActionListener(new ActionListener() {
121              public void actionPerformed(ActionEvent e) {
122 <                _actionQueue.add(new Integer(ConnectionHandler.DISCONNECT));
122 >                Configuration.getInstance().loadConfiguration();
123              }
124          });
125 +        conientMenu.add(loadConfig);
126 +        conientMenu.addSeparator();
127 +        JMenuItem quit = new JMenuItem("Quit");
128 +        quit.addActionListener(new ActionListener() {
129 +            public void actionPerformed(ActionEvent e) {
130 +                _actionQueue.add(new Integer(ConnectionHandler.QUIT));
131 +            }
132 +        });
133 +        conientMenu.add(quit);
134 +        bar.add(conientMenu);
135          
136 <        JToolBar bar = new JToolBar(JToolBar.HORIZONTAL);
137 <        bar.add(connectButton);
138 <        bar.add(startDataButton);
139 <        bar.add(stopDataButton);
140 <        bar.add(disconnectButton);
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 >        
159          return bar;
160 <    }
160 >    }
161  
162 <    DataPanel _data;
162 > //---ACCESSOR/MUTATOR METHODS---
163 >
164 >    public JMenuBar getMenuBar() {
165 >        return _menuBar;
166 >    }
167 >
168 > //---ATTRIBUTES---
169 >
170 >    /**
171 >     * The tool bar for the control panel
172 >     */    
173      JToolBar _toolBar = setupToolBar();
174      
175 +    JMenuBar _menuBar = setupMenuBar();
176 +    
177 +    /**
178 +     * The queue that we will add actions to.
179 +     */
180      Queue _actionQueue = new Queue();
181 +    
182 +    /**
183 +     * The connection handler in use by the system.
184 +     */
185      ConnectionHandler _handler;
186 < }
186 >    
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 >
215 > //---STATIC ATTRIBUTES---
216 >
217 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines