root / trunk / code / projects / colonet / ColonetGUI / Colonet.java @ 136
History | View | Annotate | Download (31.7 KB)
1 |
//
|
---|---|
2 |
// Colonet.java
|
3 |
//
|
4 |
|
5 |
import javax.swing.*; |
6 |
import javax.swing.event.*; |
7 |
import java.awt.*; |
8 |
import java.awt.image.*; |
9 |
import java.awt.event.*; |
10 |
import java.net.*; |
11 |
import java.io.*; |
12 |
import java.util.Random; |
13 |
import java.applet.*; |
14 |
|
15 |
public class Colonet extends JApplet implements ActionListener, MouseInputListener, Runnable { |
16 |
|
17 |
final int CANVAS_SIZE = 500; //don't make this too large, or the applet will be slow. |
18 |
final int BUFFER = 50; |
19 |
final int RADIUS = 30; |
20 |
|
21 |
// Connection
|
22 |
JTextField txtHost;
|
23 |
JTextField txtPort;
|
24 |
JButton btnConnect;
|
25 |
JButton btnGraph;
|
26 |
JLabel lblConnectionStatus;
|
27 |
JTextArea txtMatrix;
|
28 |
JTextArea txtInfo;
|
29 |
JPanel panelConnect;
|
30 |
JPanel panelServerInterface;
|
31 |
|
32 |
// Stats
|
33 |
JLabel lblBattery;
|
34 |
JLabel lblTokenPasses;
|
35 |
JLabel lblHastToken;
|
36 |
JPanel panelStats;
|
37 |
|
38 |
// South
|
39 |
JPanel panelSouth;
|
40 |
JTextArea log;
|
41 |
JScrollPane spLog;
|
42 |
|
43 |
// Control
|
44 |
JPanel panelControl;
|
45 |
JTabbedPane tabPaneControl;
|
46 |
JPanel panelRobotControl;
|
47 |
JPanel panelRobotDirection;
|
48 |
JPanel panelRobotDirectionButtons;
|
49 |
JPanel panelRobotCommands;
|
50 |
JButton btnF, btnB, btnL, btnR, btnActivate;
|
51 |
JComboBox cmbRobotNum;
|
52 |
VectorController vectorController; |
53 |
BufferedImage imageVectorControl;
|
54 |
|
55 |
// Task Manager
|
56 |
JPanel panelTaskManager;
|
57 |
JScrollPane spTaskManager;
|
58 |
JPanel panelTaskManagerControls;
|
59 |
JPanel panelTaskManagerControlsPriority;
|
60 |
DefaultListModel taskListModel;
|
61 |
JList taskList;
|
62 |
JButton btnAddTask;
|
63 |
JButton btnRemoveTask;
|
64 |
JButton btnMoveTaskUp;
|
65 |
JButton btnMoveTaskDown;
|
66 |
JButton btnUpdateTasks;
|
67 |
TaskAddWindow taskAddWindow; |
68 |
|
69 |
// Graphics
|
70 |
ImagePanel panel; |
71 |
GraphicsConfiguration gc;
|
72 |
volatile BufferedImage image; |
73 |
volatile Graphics2D canvas; |
74 |
int cx, cy;
|
75 |
|
76 |
Socket socket;
|
77 |
OutputStreamWriter out;
|
78 |
DataUpdater dataUpdater; |
79 |
|
80 |
Font botFont;
|
81 |
Random random = new Random(); |
82 |
volatile int tokenLoc; //the token is currently here |
83 |
volatile int numBots; |
84 |
volatile int selectedBot; //the user has selected this bot |
85 |
volatile Rectangle[] botRect; //contains boundary shapes around bots for click detection |
86 |
volatile int[] xbeeID; |
87 |
|
88 |
Thread drawThread;
|
89 |
Simulator simulator; |
90 |
SelectionIndicator indicator; |
91 |
PacketMonitor packetMonitor; |
92 |
ColonetServerInterface csi; |
93 |
|
94 |
|
95 |
public void init () { |
96 |
// set the default look and feel - choose one
|
97 |
//String laf = UIManager.getSystemLookAndFeelClassName();
|
98 |
//String laf = UIManager.getCrossPlatformLookAndFeelClassName();
|
99 |
String laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; |
100 |
try {
|
101 |
UIManager.setLookAndFeel(laf);
|
102 |
} catch (UnsupportedLookAndFeelException exc) { |
103 |
System.err.println ("Warning: UnsupportedLookAndFeel: " + laf); |
104 |
} catch (Exception exc) { |
105 |
System.err.println ("Error loading " + laf + ": " + exc); |
106 |
} |
107 |
// We should invoke and wait to avoid browser display difficulties
|
108 |
Runnable r = new Runnable() { |
109 |
public void run() { |
110 |
createAndShowGUI(); |
111 |
} |
112 |
}; |
113 |
try {
|
114 |
SwingUtilities.invokeAndWait(r);
|
115 |
} catch (InterruptedException e) { |
116 |
//Not really sure why we would be in this situation
|
117 |
System.out.println(e);
|
118 |
} catch (java.lang.reflect.InvocationTargetException e) {
|
119 |
//This could happen for various reasons if there is a problem in createAndShowGUI
|
120 |
e.printStackTrace(); |
121 |
} |
122 |
} |
123 |
|
124 |
public void destroy () { |
125 |
try { drawThread.interrupt(); } catch (Exception e) { } |
126 |
try { indicator.interrupt(); } catch (Exception e) { } |
127 |
try { packetMonitor.interrupt(); } catch (Exception e) { } |
128 |
} |
129 |
|
130 |
private synchronized void createAndShowGUI () { |
131 |
// init graphical elements
|
132 |
// Get the graphics configuration of the screen to create a buffer
|
133 |
gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
134 |
.getDefaultScreenDevice().getDefaultConfiguration(); |
135 |
image = gc.createCompatibleImage(CANVAS_SIZE,CANVAS_SIZE); |
136 |
canvas = image.createGraphics(); |
137 |
canvas.setStroke(new BasicStroke(2)); //set pen width |
138 |
panel = new ImagePanel(false, image); //set automatic double-buffering to false. we are doing it manually. |
139 |
|
140 |
// Calculate center of canvas
|
141 |
cx = image.getWidth() / 2;
|
142 |
cy = image.getHeight() / 2;
|
143 |
|
144 |
botFont = new Font("Arial", Font.PLAIN, 14); |
145 |
tokenLoc = 0;
|
146 |
numBots = 0;
|
147 |
selectedBot = 0;
|
148 |
|
149 |
// Connection area
|
150 |
txtMatrix = new JTextArea(); |
151 |
txtMatrix.setBorder(BorderFactory.createTitledBorder("Input Matrix")); |
152 |
txtInfo = new JTextArea(); |
153 |
txtInfo.setBorder(BorderFactory.createTitledBorder("Info")); |
154 |
txtInfo.setEditable(false);
|
155 |
btnGraph = new JButton("Run"); |
156 |
txtHost = new JTextField("roboclub1.frc.ri.cmu.edu"); |
157 |
txtHost.setBorder(BorderFactory.createTitledBorder("Host")); |
158 |
txtPort = new JTextField("10123"); |
159 |
txtPort.setBorder(BorderFactory.createTitledBorder("Port")); |
160 |
btnConnect = new JButton("Connect"); |
161 |
lblConnectionStatus = new JLabel("Status: Offline"); |
162 |
panelConnect = new JPanel(); |
163 |
panelConnect.setLayout(new GridLayout(6,1)); |
164 |
panelConnect.add(lblConnectionStatus); |
165 |
panelConnect.add(txtHost); |
166 |
panelConnect.add(txtPort); |
167 |
panelConnect.add(btnConnect); |
168 |
panelConnect.add(txtInfo); |
169 |
panelConnect.add(btnGraph); |
170 |
panelServerInterface = new JPanel(); |
171 |
panelServerInterface.setLayout(new GridLayout(2,1)); |
172 |
panelServerInterface.add(panelConnect); |
173 |
panelServerInterface.add(txtMatrix); |
174 |
|
175 |
// Status Elements
|
176 |
lblTokenPasses = new JLabel(); |
177 |
lblBattery = new JLabel("???"); |
178 |
panelStats = new JPanel(); |
179 |
panelStats.setLayout(new GridLayout(4,2)); |
180 |
panelStats.add(new JLabel("Token Passes / sec ")); |
181 |
panelStats.add(lblTokenPasses); |
182 |
panelStats.add(new JLabel("Battery ")); |
183 |
panelStats.add(lblBattery); |
184 |
panelStats.add(new JLabel("Token Passes / sec ")); |
185 |
panelStats.add(lblTokenPasses); |
186 |
|
187 |
//TODO: add panelStats somewhere?
|
188 |
|
189 |
// Robot direction panel
|
190 |
panelRobotDirection = new JPanel(); |
191 |
panelRobotDirectionButtons = new JPanel(); |
192 |
btnF = new JButton("^"); |
193 |
btnB = new JButton("v"); |
194 |
btnL = new JButton("<"); |
195 |
btnR = new JButton(">"); |
196 |
btnActivate = new JButton("o"); |
197 |
panelRobotDirectionButtons.setLayout(new GridLayout(1,5)); |
198 |
panelRobotDirectionButtons.add(btnActivate); |
199 |
panelRobotDirectionButtons.add(btnF); |
200 |
panelRobotDirectionButtons.add(btnB); |
201 |
panelRobotDirectionButtons.add(btnL); |
202 |
panelRobotDirectionButtons.add(btnR); |
203 |
|
204 |
imageVectorControl = gc.createCompatibleImage(380, 210); |
205 |
vectorController = new VectorController(imageVectorControl);
|
206 |
panelRobotDirection.setLayout(new BorderLayout()); |
207 |
panelRobotDirection.add(vectorController, BorderLayout.CENTER);
|
208 |
panelRobotDirection.add(panelRobotDirectionButtons, BorderLayout.SOUTH);
|
209 |
|
210 |
// Robot Control and Commands
|
211 |
panelRobotCommands = new JPanel(); |
212 |
panelRobotCommands.setLayout(new FlowLayout()); |
213 |
cmbRobotNum = new JComboBox(); |
214 |
panelRobotCommands.add(cmbRobotNum); |
215 |
panelRobotCommands.add(new JLabel("Commands go here")); |
216 |
panelRobotControl = new JPanel(); |
217 |
panelRobotControl.setLayout(new GridLayout(2,1)); |
218 |
panelRobotControl.add(panelRobotDirection); |
219 |
panelRobotControl.add(panelRobotCommands); |
220 |
|
221 |
// Task Manager
|
222 |
panelTaskManager = new JPanel(); |
223 |
panelTaskManager.setLayout(new BorderLayout()); |
224 |
taskListModel = new DefaultListModel(); |
225 |
taskList = new JList(taskListModel); |
226 |
taskList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
227 |
taskList.setSelectedIndex(0);
|
228 |
spTaskManager = new JScrollPane(taskList); |
229 |
panelTaskManagerControls = new JPanel(); |
230 |
panelTaskManagerControls.setLayout(new GridLayout(1,4)); |
231 |
panelTaskManagerControlsPriority = new JPanel(); |
232 |
panelTaskManagerControlsPriority.setLayout(new GridLayout(1,2)); |
233 |
btnAddTask = new JButton("Add..."); |
234 |
btnRemoveTask = new JButton("Remove"); |
235 |
btnMoveTaskUp = new JButton("^"); |
236 |
btnMoveTaskDown = new JButton("v"); |
237 |
btnUpdateTasks = new JButton("Update"); |
238 |
panelTaskManagerControlsPriority.add(btnMoveTaskUp); |
239 |
panelTaskManagerControlsPriority.add(btnMoveTaskDown); |
240 |
panelTaskManagerControls.add(btnAddTask); |
241 |
panelTaskManagerControls.add(btnRemoveTask); |
242 |
panelTaskManagerControls.add(btnUpdateTasks); |
243 |
panelTaskManagerControls.add(panelTaskManagerControlsPriority); |
244 |
panelTaskManager.add(spTaskManager, BorderLayout.CENTER);
|
245 |
panelTaskManager.add(panelTaskManagerControls, BorderLayout.SOUTH);
|
246 |
panelTaskManager.add(new JLabel("Current Task Queue"), BorderLayout.NORTH); |
247 |
|
248 |
// Task Manager Add Window
|
249 |
taskAddWindow = new TaskAddWindow();
|
250 |
|
251 |
// Message log
|
252 |
log = new JTextArea(); |
253 |
spLog = new JScrollPane(log, |
254 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
255 |
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
256 |
spLog.setBorder(BorderFactory.createTitledBorder("Log")); |
257 |
spLog.setPreferredSize(new Dimension(0, 150)); |
258 |
log.setEditable(false);
|
259 |
|
260 |
// Main control mechanism
|
261 |
panelControl = new JPanel(); |
262 |
panelControl.setLayout(new GridLayout(1,1)); |
263 |
tabPaneControl = new JTabbedPane(JTabbedPane.TOP); |
264 |
tabPaneControl.setPreferredSize(new Dimension(400, 0)); |
265 |
tabPaneControl.addTab("Connection", panelServerInterface);
|
266 |
tabPaneControl.addTab("Robots", panelRobotControl);
|
267 |
tabPaneControl.addTab("Tasks", panelTaskManager);
|
268 |
panelControl.add(tabPaneControl); |
269 |
|
270 |
// Set up elements in the south
|
271 |
panelSouth = new JPanel(); |
272 |
panelSouth.setLayout(new GridLayout(1,2)); |
273 |
panelSouth.add(spLog); |
274 |
|
275 |
this.getContentPane().setLayout(new BorderLayout()); |
276 |
this.getContentPane().add(panel, BorderLayout.CENTER); |
277 |
this.getContentPane().add(panelSouth, BorderLayout.SOUTH); |
278 |
this.getContentPane().add(panelControl, BorderLayout.EAST); |
279 |
this.setVisible(true); |
280 |
|
281 |
/* Add all listeners here */
|
282 |
// Task Management
|
283 |
btnAddTask.addActionListener(this);
|
284 |
btnRemoveTask.addActionListener(this);
|
285 |
btnMoveTaskUp.addActionListener(this);
|
286 |
btnMoveTaskDown.addActionListener(this);
|
287 |
btnUpdateTasks.addActionListener(this);
|
288 |
// Robot Control
|
289 |
btnF.addActionListener(this);
|
290 |
btnB.addActionListener(this);
|
291 |
btnL.addActionListener(this);
|
292 |
btnR.addActionListener(this);
|
293 |
btnActivate.addActionListener(this);
|
294 |
vectorController.addMouseMotionListener(this);
|
295 |
vectorController.addMouseListener(this);
|
296 |
// Other
|
297 |
btnGraph.addActionListener(this);
|
298 |
btnConnect.addActionListener(this);
|
299 |
panel.addMouseListener(this);
|
300 |
this.addMouseMotionListener(this); |
301 |
|
302 |
|
303 |
// Set up dependent threads
|
304 |
indicator = new SelectionIndicator(canvas);
|
305 |
indicator.setRadius(RADIUS+3, 15); //a tad more than the bot radius |
306 |
packetMonitor = new PacketMonitor();
|
307 |
simulator = new Simulator();
|
308 |
|
309 |
csi = new ColonetServerInterface(this); |
310 |
|
311 |
} |
312 |
|
313 |
public synchronized void paint (Graphics g) { |
314 |
/* Redraw the graphical components in the applet.
|
315 |
This paint method overrides the built-in paint of the
|
316 |
JApplet, and we don't want to deal with redrawing the
|
317 |
components manually. Fuck that shit. */
|
318 |
step(); |
319 |
super.paint(g);
|
320 |
} |
321 |
|
322 |
public synchronized void update (Graphics g) { |
323 |
paint(g); |
324 |
} |
325 |
|
326 |
public void actionPerformed (ActionEvent e) { |
327 |
Object source = e.getSource();
|
328 |
if (source == btnGraph) {
|
329 |
btnGraph.setEnabled(false);
|
330 |
lblConnectionStatus.setText("Simulating");
|
331 |
//create sample matrix and xbee map
|
332 |
parseMatrix(ColonetServerInterface.RESPONSE_TO_CLIENT_REQUEST + " " +
|
333 |
ColonetServerInterface.REQUEST_BOM_MATRIX + |
334 |
" 5 -1 9 3 -1 1 -1 -1 -1 5 -1 4 -1 -1 -1 2 -1 -1 -1 -1 -1 1 -1 -1 3 -1");
|
335 |
parseXBeeIDs(ColonetServerInterface.RESPONSE_TO_CLIENT_REQUEST + " " +
|
336 |
ColonetServerInterface.REQUEST_XBEE_IDS + |
337 |
" 5 12345 76543 98786 87690 2");
|
338 |
//Start dependent threads
|
339 |
drawThread = new Thread(this, "drawThread"); |
340 |
drawThread.start(); |
341 |
indicator.start(); |
342 |
packetMonitor.start(); |
343 |
simulator.start(); |
344 |
} else if (source == btnConnect) { |
345 |
doSocket(); |
346 |
dataUpdater = new DataUpdater();
|
347 |
dataUpdater.start(); |
348 |
} |
349 |
|
350 |
// Robot Movement Controls
|
351 |
else if (source == btnF) { |
352 |
vectorController.setMaxForward(); |
353 |
vectorController.sendToServer(); |
354 |
} else if (source == btnB) { |
355 |
vectorController.setMaxReverse(); |
356 |
vectorController.sendToServer(); |
357 |
} else if (source == btnL) { |
358 |
vectorController.setMaxLeft(); |
359 |
vectorController.sendToServer(); |
360 |
} else if (source == btnR) { |
361 |
vectorController.setMaxRight(); |
362 |
vectorController.sendToServer(); |
363 |
} else if (source == btnActivate) { |
364 |
vectorController.setZero(); |
365 |
vectorController.sendToServer(); |
366 |
} |
367 |
|
368 |
// Queue Management
|
369 |
else if (source == btnAddTask) { |
370 |
taskAddWindow.prompt(); |
371 |
} else if (source == btnRemoveTask) { |
372 |
if (taskList.getSelectedIndex() >= 0); |
373 |
csi.sendQueueRemove(taskList.getSelectedIndex()); |
374 |
csi.sendQueueUpdate(); |
375 |
} else if (source == btnMoveTaskUp) { |
376 |
csi.sendQueueReorder(taskList.getSelectedIndex(), taskList.getSelectedIndex() - 1);
|
377 |
csi.sendQueueUpdate(); |
378 |
} else if (source == btnMoveTaskDown) { |
379 |
csi.sendQueueReorder(taskList.getSelectedIndex(), taskList.getSelectedIndex() + 1);
|
380 |
csi.sendQueueUpdate(); |
381 |
} else if (source == btnUpdateTasks) { |
382 |
csi.sendQueueUpdate(); |
383 |
} |
384 |
} |
385 |
|
386 |
private void randomize () { |
387 |
Random r = new Random(); |
388 |
StringBuilder s = new StringBuilder(); |
389 |
|
390 |
int count = r.nextInt(8) + 1; |
391 |
for (int i = 0; i < count; i++) { |
392 |
for (int j = 0; j < count; j++) { |
393 |
if (r.nextBoolean())
|
394 |
s.append("" + (r.nextInt(16) + 1)); |
395 |
else
|
396 |
s.append("-");
|
397 |
if (j != count-1) |
398 |
s.append(" ");
|
399 |
} |
400 |
if (i != count-1) s.append("\n"); |
401 |
} |
402 |
|
403 |
txtMatrix.setText(s.toString()); |
404 |
} |
405 |
|
406 |
private void doSocket () { |
407 |
csi.connect(txtHost.getText(), txtPort.getText()); |
408 |
} |
409 |
|
410 |
public void drawRobot (int id, int x, int y) { |
411 |
//save the bot in memory, so we can tell if we click on it later
|
412 |
botRect[id] = new Rectangle(x-RADIUS, y-RADIUS, 2*RADIUS, 2*RADIUS); |
413 |
|
414 |
//draw the bot on the canvas
|
415 |
canvas.setColor(Color.BLACK);
|
416 |
canvas.drawOval(x-RADIUS, y-RADIUS, RADIUS*2, RADIUS*2); |
417 |
|
418 |
//draw the label
|
419 |
canvas.setFont(botFont); |
420 |
try {
|
421 |
canvas.drawString("" + xbeeID[id], x-20, y+2); |
422 |
} catch (Exception e) { |
423 |
canvas.drawString("???", x-22, y+2); |
424 |
} |
425 |
} |
426 |
|
427 |
public void drawConnection (int start, int end, int radius, Color color) { |
428 |
final int ARROW_LENGTH = 18; |
429 |
|
430 |
double angle = 2.0 * Math.PI / numBots; |
431 |
int startx, starty, endx, endy;
|
432 |
startx = cx - (int)(radius * Math.cos(start * angle)); |
433 |
starty = cy - (int)(radius * Math.sin(start * angle)); |
434 |
endx = cx - (int)(radius * Math.cos(end * angle)); |
435 |
endy = cy - (int)(radius * Math.sin(end * angle)); |
436 |
canvas.setColor(color); |
437 |
canvas.drawLine(startx, starty, endx, endy); |
438 |
|
439 |
//create arrow
|
440 |
if (color.equals(Color.BLACK)) return; |
441 |
int big_dy = starty - endy;
|
442 |
int big_dx = endx - startx;
|
443 |
double theta = 0; |
444 |
if (big_dx == 0 && starty > endy) //pointing up |
445 |
theta = Math.PI/2; |
446 |
else if (big_dx == 0 && starty < endy) //pointing down |
447 |
theta = 3*Math.PI/2; |
448 |
else if (big_dy == 0 && startx > endx) //pointing left |
449 |
theta = Math.PI;
|
450 |
else if (big_dy == 0 && startx < endx) //pointing right |
451 |
theta = 0;
|
452 |
else
|
453 |
theta = Math.atan(1.0 * big_dy / big_dx); |
454 |
|
455 |
//create ploygon
|
456 |
Polygon poly = new Polygon(); |
457 |
int dx_arrow = Math.abs((int)(ARROW_LENGTH * Math.cos(theta))); |
458 |
int dy_arrow = Math.abs((int)(ARROW_LENGTH * Math.sin(theta))); |
459 |
int dy_half = (int)(ARROW_LENGTH/2 * Math.cos(theta)); |
460 |
int dx_half = (int)(ARROW_LENGTH/2 * Math.sin(theta)); |
461 |
int rx = (big_dx > 0) ? endx - dx_arrow : endx + dx_arrow; |
462 |
int ry = (big_dy > 0) ? endy + dy_arrow : endy - dy_arrow; |
463 |
poly.addPoint(endx, endy); |
464 |
poly.addPoint(rx - dx_half, ry - dy_half); |
465 |
poly.addPoint(rx + dx_half, ry + dy_half); |
466 |
canvas.fillPolygon(poly); |
467 |
} |
468 |
|
469 |
public void run () { |
470 |
while (true) { |
471 |
repaint(); |
472 |
try {
|
473 |
Thread.sleep(90); |
474 |
} catch (InterruptedException e) { |
475 |
return;
|
476 |
} |
477 |
} |
478 |
} |
479 |
|
480 |
public void step () { |
481 |
final int DIAMETER = image.getWidth() - 2*BUFFER; |
482 |
final int BIGRADIUS = DIAMETER / 2; |
483 |
final int TOKENRADIUS = 40; |
484 |
boolean valid;
|
485 |
|
486 |
// clear image
|
487 |
canvas.setColor(Color.WHITE);
|
488 |
canvas.fillRect(0, 0, image.getWidth(), image.getHeight()); |
489 |
|
490 |
// parse the matrix, to see what robots exist
|
491 |
String [] rows = txtMatrix.getText().split("\n"); |
492 |
numBots = rows.length; |
493 |
String [][] entries = new String[numBots][numBots]; |
494 |
valid = true;
|
495 |
for (int i = 0; i < numBots; i++) { |
496 |
entries[i] = rows[i].split(" ");
|
497 |
if (entries[i].length != rows.length) valid = false; |
498 |
} |
499 |
|
500 |
if (valid) {
|
501 |
this.showStatus("Running"); |
502 |
|
503 |
// draw robots and find which one is seleced
|
504 |
double angle = 2.0 * Math.PI / numBots; |
505 |
canvas.setColor(Color.BLACK);
|
506 |
botRect = new Rectangle[numBots]; |
507 |
int x, y;
|
508 |
if (selectedBot >= numBots) selectedBot = 0; |
509 |
for (int i = 0; i < numBots; i++) { |
510 |
x = cx - (int)(BIGRADIUS * Math.cos(i * angle)); |
511 |
y = cy - (int)(BIGRADIUS * Math.sin(i * angle)); |
512 |
drawRobot(i, x, y); |
513 |
if (i == selectedBot) indicator.setCenter(x, y);
|
514 |
} |
515 |
|
516 |
// draw token marker
|
517 |
int tokenx, tokeny;
|
518 |
int tokenNum = tokenLoc;
|
519 |
tokenx = cx - (int)(BIGRADIUS * Math.cos(tokenNum * angle)); |
520 |
tokeny = cy - (int)(BIGRADIUS * Math.sin(tokenNum * angle)); |
521 |
canvas.setColor(Color.RED);
|
522 |
canvas.drawOval(tokenx-TOKENRADIUS, tokeny-TOKENRADIUS, 2*TOKENRADIUS, 2*TOKENRADIUS); |
523 |
|
524 |
// create an inner circle along which the connections are made.
|
525 |
// let the diameter of this circle be 2*RADIUS less than the outerDiameter.
|
526 |
// see what connections exist
|
527 |
for (int row = 0; row < numBots; row++) { |
528 |
for(int col = 0; col < numBots; col++) { |
529 |
if (!entries[row][col].equals("-") && entries[col][row].equals("-") && row != col) { |
530 |
//TODO: Make a standard gray
|
531 |
drawConnection(row, col, BIGRADIUS-RADIUS, new Color(200,200,200)); |
532 |
} else if (!entries[row][col].equals("-") && ! entries[col][row].equals("-") && row != col) { |
533 |
drawConnection(row, col, BIGRADIUS-RADIUS, Color.BLACK);
|
534 |
} |
535 |
} |
536 |
} |
537 |
|
538 |
// draw the selection indicator
|
539 |
indicator.draw(); |
540 |
|
541 |
} else {// if matrix is not valid |
542 |
this.showStatus("Error: Invalid matrix"); |
543 |
} |
544 |
|
545 |
} |
546 |
|
547 |
/* At this point, moveToken is only called by the simulator.
|
548 |
* In the future, it can be rewritten to account for non-standard
|
549 |
* token passing or deleted if the information can be retrieved
|
550 |
* directly from the Colonet server instead.
|
551 |
*/
|
552 |
public void moveToken () { |
553 |
try {
|
554 |
tokenLoc = (tokenLoc+1)%numBots;
|
555 |
} catch (ArithmeticException e) { // in case numRobots is zero |
556 |
} |
557 |
|
558 |
packetMonitor.addTokenPass(); |
559 |
} |
560 |
|
561 |
public JTextArea getLog () { |
562 |
return log;
|
563 |
} |
564 |
|
565 |
public JTextArea getMatrixInput () { |
566 |
return txtMatrix;
|
567 |
} |
568 |
|
569 |
public void parseMatrix (String line) { |
570 |
txtMatrix.setText("");
|
571 |
String [] str = line.split(" "); |
572 |
int num = Integer.parseInt(str[2]); |
573 |
for (int i = 0; i < num; i++) { |
574 |
for (int j = 0; j < num; j++) { |
575 |
String next = str[3 + i*num + j]; |
576 |
if (next.equals("-1")) |
577 |
txtMatrix.append("-");
|
578 |
else
|
579 |
txtMatrix.append(next); |
580 |
if (j < num - 1) |
581 |
txtMatrix.append(" ");
|
582 |
} |
583 |
if (i < num - 1) |
584 |
txtMatrix.append("\n");
|
585 |
} |
586 |
|
587 |
} |
588 |
|
589 |
public void parseQueue (String line) { |
590 |
log.append("Got queue update\n");
|
591 |
|
592 |
} |
593 |
|
594 |
public void parseXBeeIDs (String line) { |
595 |
log.append("Got XBee ID map: " + line + "\n"); |
596 |
String [] str = line.split(" "); |
597 |
int num = Integer.parseInt(str[2]); |
598 |
xbeeID = new int[num]; |
599 |
for (int i = 0; i < num; i++) |
600 |
xbeeID[i] = Integer.parseInt(str[i+3]); |
601 |
|
602 |
//update the list of robots to control
|
603 |
cmbRobotNum.removeAllItems(); |
604 |
cmbRobotNum.addItem(new String(" All ")); |
605 |
for (int i = 0; i < num; i++) |
606 |
cmbRobotNum.addItem(new String("" + xbeeID[i])); |
607 |
} |
608 |
|
609 |
//
|
610 |
// MouseEvent methods
|
611 |
//
|
612 |
public void mouseExited(MouseEvent e) {} |
613 |
public void mouseEntered(MouseEvent e) {} |
614 |
public void mouseReleased(MouseEvent e) { |
615 |
vectorController.sendToServer(); |
616 |
} |
617 |
public void mouseClicked(MouseEvent e) { |
618 |
mouseDragged(e); |
619 |
} |
620 |
public void mousePressed(MouseEvent e) { |
621 |
try {
|
622 |
for (int i = 0; i < numBots; i++) { |
623 |
if (botRect[i].contains(e.getPoint()))
|
624 |
selectedBot = i; |
625 |
} |
626 |
} catch (Exception ex) { |
627 |
System.out.println(e);
|
628 |
} |
629 |
|
630 |
} |
631 |
public void mouseDragged(MouseEvent e) { |
632 |
vectorController.setPoint(e.getX(), e.getY()); |
633 |
vectorController.repaint(); |
634 |
} |
635 |
public void mouseMoved(MouseEvent e) {} |
636 |
|
637 |
|
638 |
/*
|
639 |
* SelectionIndicator thread.
|
640 |
* Graphical representation of the selection marker
|
641 |
*
|
642 |
* step() and draw() are synchronized methods. step() is private and
|
643 |
* used to update the position of the crosshairs. draw() is called
|
644 |
* externally and should only run if all calculations in step() have
|
645 |
* been completed.
|
646 |
*/
|
647 |
private class SelectionIndicator extends Thread { |
648 |
|
649 |
final int INDICATOR_DELAY = 100; |
650 |
final double DTHETA = 0.3; //larger values make the marker rotate faster |
651 |
Graphics2D g; //canvas to draw on |
652 |
boolean running;
|
653 |
|
654 |
int sx, sy; //center |
655 |
int r, dr; //radius and width of marker |
656 |
double theta; //current angle |
657 |
|
658 |
volatile Polygon poly1, poly2, poly3, poly4; |
659 |
|
660 |
int px1, py1;
|
661 |
int rx1, ry1;
|
662 |
int px2, py2;
|
663 |
int rx2, ry2;
|
664 |
int px3, py3;
|
665 |
int rx3, ry3;
|
666 |
int px4, py4;
|
667 |
int rx4, ry4;
|
668 |
|
669 |
int steps;
|
670 |
|
671 |
public SelectionIndicator (Graphics2D g) { |
672 |
super("SelectionIndicator"); |
673 |
this.g = g;
|
674 |
running = false;
|
675 |
steps = 0;
|
676 |
|
677 |
theta = 0;
|
678 |
rx1 = 0; ry1 = 0; |
679 |
px1 = 0; py1 = 0; |
680 |
rx2 = 0; ry2 = 0; |
681 |
px2 = 0; py2 = 0; |
682 |
rx3 = 0; ry3 = 0; |
683 |
px3 = 0; py3 = 0; |
684 |
rx4 = 0; ry4 = 0; |
685 |
px4 = 0; py4 = 0; |
686 |
} |
687 |
|
688 |
public synchronized void setCenter (int sx, int sy) { |
689 |
if (sx == this.sx && sy == this.sy) return; |
690 |
this.sx = sx;
|
691 |
this.sy = sy;
|
692 |
steps = 0;
|
693 |
} |
694 |
|
695 |
public synchronized void setRadius (int r, int dr) { |
696 |
this.r = r;
|
697 |
this.dr = dr;
|
698 |
steps = 0;
|
699 |
} |
700 |
|
701 |
public void run () { |
702 |
running = true;
|
703 |
while (running) {
|
704 |
step(); |
705 |
try {
|
706 |
Thread.sleep(INDICATOR_DELAY);
|
707 |
} catch (InterruptedException e) { |
708 |
running = false;
|
709 |
return;
|
710 |
} |
711 |
} |
712 |
} |
713 |
|
714 |
private synchronized void step () { |
715 |
Polygon poly1_new = new Polygon(); |
716 |
Polygon poly2_new = new Polygon(); |
717 |
Polygon poly3_new = new Polygon(); |
718 |
Polygon poly4_new = new Polygon(); |
719 |
|
720 |
//the step
|
721 |
theta = (theta + DTHETA/Math.PI) % (Math.PI); |
722 |
|
723 |
//the calculation
|
724 |
//let p be the point of the pointy thing toward the center
|
725 |
//let r be the point at the opposite side
|
726 |
|
727 |
//recalculate radius, if it will look cool, lolz
|
728 |
int newr = r;
|
729 |
if (steps < 100) |
730 |
newr = (int)( r + 200/(steps+1) ); |
731 |
|
732 |
//precompute values for dx and dy
|
733 |
int dx_inner = (int)(newr * Math.cos(theta)); |
734 |
int dy_inner = (int)(newr * Math.sin(theta)); |
735 |
int dx_outer = (int)((newr+dr) * Math.cos(theta)); |
736 |
int dy_outer = (int)((newr+dr) * Math.sin(theta)); |
737 |
|
738 |
//calculate polygon constants
|
739 |
int dy_poly = (int)(dr/2 * Math.cos(theta)); |
740 |
int dx_poly = (int)(dr/2 * Math.sin(theta)); |
741 |
|
742 |
//determine critical points
|
743 |
//kansas city shuffle!
|
744 |
px1 = sx + dx_inner; |
745 |
py1 = sy - dy_inner; |
746 |
rx1 = sx + dx_outer; |
747 |
ry1 = sy - dy_outer; |
748 |
px2 = sx - dx_inner; |
749 |
py2 = sy + dy_inner; |
750 |
rx2 = sx - dx_outer; |
751 |
ry2 = sy + dy_outer; |
752 |
px3 = sx - dy_inner; |
753 |
py3 = sy - dx_inner; |
754 |
rx3 = sx - dy_outer; |
755 |
ry3 = sy - dx_outer; |
756 |
px4 = sx + dy_inner; |
757 |
py4 = sy + dx_inner; |
758 |
rx4 = sx + dy_outer; |
759 |
ry4 = sy + dx_outer; |
760 |
|
761 |
//create polygons
|
762 |
poly1_new.addPoint(px1, py1); |
763 |
poly1_new.addPoint(rx1+dx_poly, ry1+dy_poly); |
764 |
poly1_new.addPoint(rx1-dx_poly, ry1-dy_poly); |
765 |
poly2_new.addPoint(px2, py2); |
766 |
poly2_new.addPoint(rx2+dx_poly, ry2+dy_poly); |
767 |
poly2_new.addPoint(rx2-dx_poly, ry2-dy_poly); |
768 |
poly3_new.addPoint(px3, py3); |
769 |
poly3_new.addPoint(rx3-dy_poly, ry3+dx_poly); |
770 |
poly3_new.addPoint(rx3+dy_poly, ry3-dx_poly); |
771 |
poly4_new.addPoint(px4, py4); |
772 |
poly4_new.addPoint(rx4-dy_poly, ry4+dx_poly); |
773 |
poly4_new.addPoint(rx4+dy_poly, ry4-dx_poly); |
774 |
|
775 |
//reassign updated polygons
|
776 |
poly1 = poly1_new; |
777 |
poly2 = poly2_new; |
778 |
poly3 = poly3_new; |
779 |
poly4 = poly4_new; |
780 |
|
781 |
if (steps < 300) steps++; |
782 |
} |
783 |
|
784 |
public synchronized void draw () { |
785 |
if (!running) return; |
786 |
g.setColor(Color.GRAY);
|
787 |
//draw polygons
|
788 |
g.fillPolygon(poly1); |
789 |
g.fillPolygon(poly2); |
790 |
g.fillPolygon(poly3); |
791 |
g.fillPolygon(poly4); |
792 |
} |
793 |
|
794 |
} |
795 |
|
796 |
/*
|
797 |
* Simulator thread.
|
798 |
*
|
799 |
*/
|
800 |
private class Simulator extends Thread { |
801 |
final int SIMULATOR_DELAY = 300; |
802 |
boolean running;
|
803 |
|
804 |
public Simulator () {
|
805 |
super("Simulator"); |
806 |
running = false;
|
807 |
} |
808 |
|
809 |
public void run () { |
810 |
running = true;
|
811 |
while (running) {
|
812 |
step(); |
813 |
try {
|
814 |
Thread.sleep(SIMULATOR_DELAY);
|
815 |
} catch (InterruptedException e) { |
816 |
running = false;
|
817 |
return;
|
818 |
} |
819 |
} |
820 |
} |
821 |
|
822 |
private void step () { |
823 |
// simulate passing the token
|
824 |
moveToken(); |
825 |
} |
826 |
|
827 |
} |
828 |
|
829 |
/*
|
830 |
* PacketMonitor thread.
|
831 |
*
|
832 |
* Currently, this counts the rate of token passes but will eventually
|
833 |
* be modified to keep more important statistics.
|
834 |
*/
|
835 |
private class PacketMonitor extends Thread { |
836 |
final int PACKETMONITOR_DELAY = 1000; |
837 |
|
838 |
boolean running;
|
839 |
int tokenPasses;
|
840 |
|
841 |
public PacketMonitor () {
|
842 |
super("PacketMonitor"); |
843 |
running = false;
|
844 |
tokenPasses = 0;
|
845 |
} |
846 |
|
847 |
public void run () { |
848 |
running = true;
|
849 |
while (running) {
|
850 |
displayTokenPasses(); |
851 |
try {
|
852 |
Thread.sleep(PACKETMONITOR_DELAY);
|
853 |
} catch (InterruptedException e) { |
854 |
running = false;
|
855 |
return;
|
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
public synchronized void addTokenPass () { |
861 |
tokenPasses++; |
862 |
} |
863 |
|
864 |
public synchronized void displayTokenPasses () { |
865 |
lblTokenPasses.setText("" + tokenPasses);
|
866 |
tokenPasses = 0;
|
867 |
} |
868 |
|
869 |
} |
870 |
|
871 |
/*
|
872 |
* DataUpdater thread.
|
873 |
* The purpose of this thread is to request data from the server at regular intervals.
|
874 |
*
|
875 |
*/
|
876 |
class DataUpdater extends Thread { |
877 |
final int DATAUPDATER_DELAY = 1100; |
878 |
|
879 |
public DataUpdater () {
|
880 |
super("Colonet DataUpdater"); |
881 |
} |
882 |
|
883 |
public void run () { |
884 |
String line;
|
885 |
while (true) { |
886 |
try {
|
887 |
//request more data
|
888 |
if (csi.isReady()) {
|
889 |
csi.sendSensorDataRequest(); |
890 |
csi.sendXBeeIDRequest(); |
891 |
} |
892 |
Thread.sleep(DATAUPDATER_DELAY);
|
893 |
} catch (InterruptedException e) { |
894 |
return;
|
895 |
} |
896 |
} |
897 |
} |
898 |
|
899 |
} |
900 |
|
901 |
/*
|
902 |
* ImagePanel class
|
903 |
* Enables more efficient image handling in a component-controlled environment
|
904 |
*/
|
905 |
class ImagePanel extends JPanel { |
906 |
protected Image img; |
907 |
|
908 |
public ImagePanel (Image img) { |
909 |
super();
|
910 |
this.img = img;
|
911 |
} |
912 |
|
913 |
public ImagePanel (boolean isDoubleBuffered, Image img) { |
914 |
super(isDoubleBuffered);
|
915 |
this.img = img;
|
916 |
} |
917 |
|
918 |
public void paint (Graphics g) { |
919 |
// Place the buffered image on the screen, inside the panel
|
920 |
g.drawImage(img, 0, 0, Color.WHITE, this); |
921 |
} |
922 |
|
923 |
} |
924 |
|
925 |
/*
|
926 |
* VectorController class
|
927 |
* Manages robot motion control graphically
|
928 |
*/
|
929 |
class VectorController extends ImagePanel { |
930 |
int x, y, cx, cy;
|
931 |
int width, height;
|
932 |
int side;
|
933 |
|
934 |
public VectorController (Image img) { |
935 |
super (img);
|
936 |
width = img.getWidth(null);
|
937 |
height = img.getHeight(null);
|
938 |
cx = img.getWidth(null)/2; |
939 |
cy = img.getHeight(null)/2; |
940 |
x = cx; |
941 |
y = cy; |
942 |
if (width < height)
|
943 |
side = width; |
944 |
else
|
945 |
side = height; |
946 |
} |
947 |
|
948 |
public void setPoint (int x, int y) { |
949 |
if (!isValidPoint(x, y))
|
950 |
return;
|
951 |
this.x = x;
|
952 |
this.y = y;
|
953 |
repaint(); |
954 |
} |
955 |
|
956 |
public boolean isValidPoint (int x, int y) { |
957 |
double xterm = Math.pow(1.0*(x - cx)/(side/2), 2); |
958 |
double yterm = Math.pow(1.0*(y - cy)/(side/2), 2); |
959 |
return (xterm + yterm <= 1); |
960 |
} |
961 |
|
962 |
public int getVelocity () { |
963 |
int dx = x - cx;
|
964 |
int dy = y - cy;
|
965 |
int v = (int) Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) ); |
966 |
return v;
|
967 |
} |
968 |
|
969 |
public double getAngle () { |
970 |
int dx = x - cx;
|
971 |
int dy = cy - y;
|
972 |
double theta = Math.atan2(Math.abs(dx), Math.abs(dy)); |
973 |
theta = (int) (1.0 * theta * 180 / Math.PI); //transform to degrees |
974 |
if (dy < 0) |
975 |
theta = 180 - theta;
|
976 |
theta *= Math.signum(dx);
|
977 |
return theta;
|
978 |
} |
979 |
|
980 |
public void paint (Graphics g) { |
981 |
g.setColor(Color.BLACK);
|
982 |
g.fillRect(0, 0, width, height); |
983 |
((Graphics2D)g).setStroke(new BasicStroke(1)); |
984 |
g.setColor(Color.RED);
|
985 |
g.drawOval(cx-side/2, cy-side/2, side, side); |
986 |
((Graphics2D)g).setStroke(new BasicStroke(2)); |
987 |
g.setColor(Color.GREEN);
|
988 |
g.drawLine(cx, cy, x, y); |
989 |
g.fillOval(x-3, y-3, 6, 6); |
990 |
} |
991 |
|
992 |
public void setMaxForward () { |
993 |
setPoint(cx, cy - (side/2) + 1); |
994 |
} |
995 |
|
996 |
public void setMaxReverse () { |
997 |
setPoint(cx, cy + (side/2) - 1); |
998 |
} |
999 |
|
1000 |
public void setMaxLeft () { |
1001 |
setPoint(cx - (side/2) + 1, cy); |
1002 |
} |
1003 |
|
1004 |
public void setMaxRight () { |
1005 |
setPoint(cx + (side/2) - 1, cy); |
1006 |
} |
1007 |
|
1008 |
public void setZero () { |
1009 |
setPoint(cx, cy); |
1010 |
} |
1011 |
|
1012 |
public void sendToServer () { |
1013 |
if (csi != null) |
1014 |
csi.sendData(ColonetServerInterface.MOVE + " " +
|
1015 |
vectorController.getAngle() + " " +
|
1016 |
vectorController.getVelocity(), ColonetServerInterface.GLOBAL_DEST); |
1017 |
} |
1018 |
|
1019 |
} |
1020 |
|
1021 |
/*
|
1022 |
* TaskAddWindow class
|
1023 |
* makes it easy to add tasks to the queue
|
1024 |
*/
|
1025 |
class TaskAddWindow extends JFrame implements ActionListener, ListSelectionListener { |
1026 |
JPanel panelButtons;
|
1027 |
JPanel panelParameters;
|
1028 |
JPanel panelSouth;
|
1029 |
JPanel panelSelection;
|
1030 |
JButton btnSubmit;
|
1031 |
JButton btnCancel;
|
1032 |
DefaultListModel availableListModel;
|
1033 |
JList availableList;
|
1034 |
JScrollPane spAvailableTasks;
|
1035 |
JTextArea txtDescription;
|
1036 |
JTextField txtParameters;
|
1037 |
MouseListener mouseListener;
|
1038 |
|
1039 |
public TaskAddWindow () {
|
1040 |
super("Add a Task ... if you dare!"); |
1041 |
super.setSize(500,500); |
1042 |
super.setLayout(new BorderLayout()); |
1043 |
|
1044 |
// set up buttons
|
1045 |
btnSubmit = new JButton("Submit"); |
1046 |
btnCancel = new JButton("Cancel"); |
1047 |
panelButtons = new JPanel(); |
1048 |
panelButtons.setLayout(new FlowLayout()); |
1049 |
panelButtons.add(btnSubmit); |
1050 |
panelButtons.add(btnCancel); |
1051 |
this.getRootPane().setDefaultButton(btnSubmit);
|
1052 |
|
1053 |
// set up task list
|
1054 |
availableListModel = new DefaultListModel(); |
1055 |
availableListModel.addElement("Map the Environment");
|
1056 |
availableListModel.addElement("Clean Up Chemical Spill");
|
1057 |
availableListModel.addElement("Grow Plants");
|
1058 |
availableListModel.addElement("Save the Cheerleader");
|
1059 |
availableListModel.addElement("Save the World");
|
1060 |
availableList = new JList(availableListModel); |
1061 |
availableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
1062 |
availableList.setSelectedIndex(-1);
|
1063 |
spAvailableTasks = new JScrollPane(availableList); |
1064 |
spAvailableTasks.setBorder(BorderFactory.createTitledBorder("Select A Task")); |
1065 |
txtDescription = new JTextArea(); |
1066 |
txtDescription.setEditable(false);
|
1067 |
txtDescription.setLineWrap(true);
|
1068 |
txtDescription.setWrapStyleWord(true);
|
1069 |
txtDescription.setBorder(BorderFactory.createTitledBorder("Description")); |
1070 |
|
1071 |
//set up parameter area
|
1072 |
panelParameters = new JPanel(); |
1073 |
panelParameters.setLayout(new BorderLayout()); |
1074 |
txtParameters = new JTextField(); |
1075 |
panelParameters.add(new JLabel("Optional parameters for this task: "), BorderLayout.WEST); |
1076 |
panelParameters.add(txtParameters); |
1077 |
|
1078 |
// assemble objects
|
1079 |
panelSelection = new JPanel(); |
1080 |
panelSelection.setLayout(new GridLayout(1,2)); |
1081 |
panelSelection.add(spAvailableTasks); |
1082 |
panelSelection.add(txtDescription); |
1083 |
|
1084 |
panelSouth = new JPanel(); |
1085 |
panelSouth.setLayout(new GridLayout(2,1)); |
1086 |
panelSouth.add(panelParameters); |
1087 |
panelSouth.add(panelButtons); |
1088 |
|
1089 |
this.getContentPane().add(panelSouth, BorderLayout.SOUTH); |
1090 |
this.getContentPane().add(panelSelection, BorderLayout.CENTER); |
1091 |
this.setLocationRelativeTo(null); |
1092 |
|
1093 |
// add listeners here
|
1094 |
availableList.addListSelectionListener(this);
|
1095 |
btnSubmit.addActionListener(this);
|
1096 |
btnCancel.addActionListener(this);
|
1097 |
} |
1098 |
|
1099 |
public void prompt () { |
1100 |
this.setVisible(true); |
1101 |
} |
1102 |
|
1103 |
private String getDescription (int index) { |
1104 |
if (index < 0) |
1105 |
return ""; |
1106 |
switch (index) {
|
1107 |
case 0: return "SLAM and junk"; |
1108 |
case 1: return "I'm not sure this works"; |
1109 |
case 2: return "Push them into the light"; |
1110 |
case 3: return "Watch out for clock repair guys"; |
1111 |
case 4: return "But make sure he's dead, geez, why would you let him get away? I mean come on, " |
1112 |
+"he's just lying there and everyone's too busy looking at people flying through the sky to "
|
1113 |
+"notice? Oh yeah, that's a good transition to a new season, let's make the audience think "
|
1114 |
+"he's dead and then pull a fast one on them, they'll never see that coming.";
|
1115 |
|
1116 |
default: return "Task not recognized"; |
1117 |
} |
1118 |
} |
1119 |
|
1120 |
public void actionPerformed (ActionEvent e) { |
1121 |
Object source = e.getSource();
|
1122 |
if (source == btnSubmit) {
|
1123 |
txtParameters.setText(txtParameters.getText().trim()); |
1124 |
|
1125 |
|
1126 |
this.setVisible(false); |
1127 |
} else if (source == btnCancel) { |
1128 |
this.setVisible(false); |
1129 |
} |
1130 |
} |
1131 |
|
1132 |
public void valueChanged (ListSelectionEvent e) { |
1133 |
int index = availableList.getSelectedIndex();
|
1134 |
if (index >= 0) |
1135 |
txtDescription.setText(getDescription(index)); |
1136 |
} |
1137 |
|
1138 |
} |
1139 |
|
1140 |
} |