-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlDeskView.java
201 lines (160 loc) · 5.01 KB
/
ControlDeskView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* ControlDeskView.java
*
* Version:
* $Id$
*
* Revisions:
* $Log$
*
*/
/**
* Class for representation of the control desk
*
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
public class ControlDeskView implements ControlDeskObserver {
private JButton addParty, finished, assign;
private JFrame win;
private JList<String> partyList;
/** The maximum number of members in a party */
private int maxMembers;
private ControlDesk controlDesk;
private ButtonCommand command;
/**
* Displays a GUI representation of the ControlDesk
*
*/
public ControlDeskView(ControlDesk controlDesk, int maxMembers) {
this.controlDesk = controlDesk;
this.maxMembers = maxMembers;
int numLanes = controlDesk.getNumLanes();
ControlDeskClickEvent listener = new ControlDeskClickEvent();
win = new JFrame("Control Desk");
win.getContentPane().setLayout(new BorderLayout());
((JPanel) win.getContentPane()).setOpaque(false);
JPanel colPanel = new JPanel();
colPanel.setLayout(new BorderLayout());
// Controls Panel
JPanel controlsPanel = createPanel("Controls", new GridLayout(3, 1));
JPanel addPartyPanel = new JPanel();
addParty = createButton("Add Party", addPartyPanel, listener);
controlsPanel.add(addPartyPanel);
JPanel assignPanel = new JPanel();
assign = createButton("Assign Lanes", assignPanel, listener);
assignPanel.add(assign);
// controlsPanel.add(assignPanel);
JPanel finishedPanel = new JPanel();
finished = createButton("Finished", finishedPanel, listener);
controlsPanel.add(finishedPanel);
// Lane Status Panel
JPanel laneStatusPanel = createPanel("Lane Status", new GridLayout(numLanes, 1));
HashSet<Lane> lanes=controlDesk.getLanes();
Iterator<Lane> it = lanes.iterator();
int laneCount=0;
while (it.hasNext()) {
Lane curLane = it.next();
LaneStatusView laneStat = new LaneStatusView(curLane,(laneCount+1));
curLane.subscribe(laneStat);
(curLane.getPinsetter()).subscribe(laneStat);
JPanel lanePanel = laneStat.showLane();
lanePanel.setBorder(new TitledBorder("Lane" + ++laneCount ));
laneStatusPanel.add(lanePanel);
}
// Party Queue Panel
JPanel partyPanel = createPanel("Party Queue", new FlowLayout());
Vector<String> empty = new Vector<>();
empty.add("(Empty)");
partyList = new JList<>(empty);
partyList.setFixedCellWidth(120);
partyList.setVisibleRowCount(10);
JScrollPane partyPane = new JScrollPane(partyList);
partyPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
partyPanel.add(partyPane);
// partyPanel.add(partyList);
// Clean up main panel
colPanel.add(controlsPanel, "East");
colPanel.add(laneStatusPanel, "Center");
colPanel.add(partyPanel, "West");
win.getContentPane().add("Center", colPanel);
win.pack();
/* Close program when this window closes */
win.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// Center Window on Screen
Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize();
win.setLocation(
((screenSize.width) / 2) - ((win.getSize().width) / 2),
((screenSize.height) / 2) - ((win.getSize().height) / 2));
win.setVisible(true);
}
private JButton createButton(String text, JPanel panel, ActionListener listener) {
JButton button = new JButton(text);
button.addActionListener(listener);
panel.setLayout(new FlowLayout());
panel.add(button);
return button;
}
private JPanel createPanel(String title, LayoutManager mgr){
JPanel panel = new JPanel();
panel.setLayout(mgr);
panel.setBorder(new TitledBorder(title));
return panel;
}
// The Invoker holds a command and can use it to call a method
public void setCommand(ButtonCommand command) {
this.command = command;
}
// Call the execute() method of the command
public void buttonPressed() {
command.execute();
}
/**
* Receive a new party from andPartyView.
*
* @param addPartyView the AddPartyView that is providing a new party
*
*/
public void updateAddParty(AddPartyView addPartyView) {
controlDesk.addPartyQueue(addPartyView.getParty());
}
/**
* Receive a broadcast from a ControlDesk
*
* @param pe the ControlDeskEvent that triggered the handler
*
*/
public void receiveControlDeskEvent(PartyQueueEvent pe) {
partyList.setListData(pe.getPartyQueue());
}
public int getMaxMembers() {
return maxMembers;
}
public JFrame getWin() {
return win;
}
public ControlDesk getControlDesk() {
return controlDesk;
}
public class ControlDeskClickEvent implements ActionListener{
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(addParty)) {
setCommand(new ControlDeskViewAddPartyCommand(ControlDeskView.this));
}
else if (e.getSource().equals(assign)) {
setCommand(new ControlDeskViewAssignCommand(ControlDeskView.this));
}
else if (e.getSource().equals(finished)) {
setCommand(new ExitProgramCommand(ControlDeskView.this));
}
buttonPressed();
}
}
}