1 |
//---PACKAGE DECLARATION--- |
2 |
|
3 |
//---IMPORTS--- |
4 |
import uk.ac.ukc.iscream.util.*; |
5 |
import javax.swing.*; |
6 |
import java.awt.*; |
7 |
import java.awt.event.*; |
8 |
|
9 |
/** |
10 |
* This panel holds the toolbar at the top. |
11 |
* The tool bar dispatches events to the ConnectionHandler. |
12 |
* |
13 |
* @author $Author: ajm4 $ |
14 |
* @version $Id: HostDisplayPanel.java,v 1.4 2001/01/22 03:03:39 ajm4 Exp $ |
15 |
*/ |
16 |
public class ControlPanel extends JPanel { |
17 |
|
18 |
//---FINAL ATTRIBUTES--- |
19 |
|
20 |
/** |
21 |
* The current CVS revision of this class |
22 |
*/ |
23 |
public final String REVISION = "$Revision: 1.4 $"; |
24 |
|
25 |
//---STATIC METHODS--- |
26 |
|
27 |
//---CONSTRUCTORS--- |
28 |
|
29 |
public ControlPanel(DataPanel data) { |
30 |
super(); |
31 |
setLayout(new BorderLayout()); |
32 |
_data = data; |
33 |
_handler = new ConnectionHandler(_data, _actionQueue); |
34 |
add(_toolBar, "North"); |
35 |
_handler.start(); |
36 |
} |
37 |
|
38 |
//---PUBLIC METHODS--- |
39 |
|
40 |
//---PRIVATE METHODS--- |
41 |
|
42 |
private JToolBar setupToolBar() { |
43 |
JButton connectButton = new JButton("Connect"); |
44 |
connectButton.addActionListener(new ActionListener() { |
45 |
public void actionPerformed(ActionEvent e) { |
46 |
_actionQueue.add(new Integer(ConnectionHandler.CONNECT)); |
47 |
} |
48 |
}); |
49 |
|
50 |
JButton startDataButton = new JButton("Start Data"); |
51 |
startDataButton.addActionListener(new ActionListener() { |
52 |
public void actionPerformed(ActionEvent e) { |
53 |
_actionQueue.add(new Integer(ConnectionHandler.STARTDATA)); |
54 |
} |
55 |
}); |
56 |
|
57 |
JButton stopDataButton = new JButton("Stop Data"); |
58 |
stopDataButton.addActionListener(new ActionListener() { |
59 |
public void actionPerformed(ActionEvent e) { |
60 |
_actionQueue.add(new Integer(ConnectionHandler.STOPDATA)); |
61 |
} |
62 |
}); |
63 |
|
64 |
JButton disconnectButton = new JButton("Disconnect"); |
65 |
disconnectButton.addActionListener(new ActionListener() { |
66 |
public void actionPerformed(ActionEvent e) { |
67 |
_actionQueue.add(new Integer(ConnectionHandler.DISCONNECT)); |
68 |
} |
69 |
}); |
70 |
|
71 |
JButton quitButton = new JButton("Quit"); |
72 |
quitButton.addActionListener(new ActionListener() { |
73 |
public void actionPerformed(ActionEvent e) { |
74 |
_actionQueue.add(new Integer(ConnectionHandler.QUIT)); |
75 |
} |
76 |
}); |
77 |
|
78 |
JToolBar bar = new JToolBar(JToolBar.HORIZONTAL); |
79 |
bar.add(connectButton); |
80 |
bar.add(startDataButton); |
81 |
bar.add(stopDataButton); |
82 |
bar.add(disconnectButton); |
83 |
bar.add(quitButton); |
84 |
return bar; |
85 |
} |
86 |
|
87 |
//---ACCESSOR/MUTATOR METHODS--- |
88 |
|
89 |
//---ATTRIBUTES--- |
90 |
|
91 |
DataPanel _data; |
92 |
JToolBar _toolBar = setupToolBar(); |
93 |
|
94 |
Queue _actionQueue = new Queue(); |
95 |
ConnectionHandler _handler; |
96 |
|
97 |
//---STATIC ATTRIBUTES--- |
98 |
|
99 |
} |