Revision 76
the gui can now request the sensor matrix from the server and parse the matrix.
Colonet.java | ||
---|---|---|
23 | 23 |
JButton btnConnect; |
24 | 24 |
JButton btnGraph; |
25 | 25 |
JLabel lblConnectionStatus; |
26 |
JTextArea txtInput;
|
|
26 |
JTextArea txtMatrix;
|
|
27 | 27 |
JTextArea txtInfo; |
28 | 28 |
JPanel panelConnect; |
29 | 29 |
JPanel panelServerInterface; |
... | ... | |
69 | 69 |
|
70 | 70 |
Socket socket; |
71 | 71 |
OutputStreamWriter out; //TODO: add a BufferedWriter |
72 |
DataUpdater dataupdater;
|
|
72 |
DataUpdater dataUpdater;
|
|
73 | 73 |
|
74 | 74 |
Font botFont; |
75 | 75 |
Random random = new Random(); |
... | ... | |
79 | 79 |
volatile Rectangle[] botRect; //contains boundary shapes around bots for click detection |
80 | 80 |
|
81 | 81 |
Thread drawThread; |
82 |
Simulator simulator; |
|
82 | 83 |
SelectionIndicator indicator; |
83 | 84 |
PacketMonitor packetMonitor; |
84 | 85 |
ColonetServerInterface csi; |
... | ... | |
122 | 123 |
panel = new JPanel(false); //set automatic double-buffering to false. we are doing it manually. |
123 | 124 |
|
124 | 125 |
// Connection area |
125 |
txtInput = new JTextArea("- 9 3 - 1\n- - - 5 -\n4 - - - 2\n- - - - -\n1 - - 3 -");
|
|
126 |
txtInput.setBorder(BorderFactory.createTitledBorder("Input Matrix"));
|
|
126 |
txtMatrix = new JTextArea("- 9 3 - 1\n- - - 5 -\n4 - - - 2\n- - - - -\n1 - - 3 -");
|
|
127 |
txtMatrix.setBorder(BorderFactory.createTitledBorder("Input Matrix"));
|
|
127 | 128 |
txtInfo = new JTextArea(); |
128 | 129 |
txtInfo.setBorder(BorderFactory.createTitledBorder("Info")); |
129 | 130 |
txtInfo.setEditable(false); |
... | ... | |
145 | 146 |
panelServerInterface = new JPanel(); |
146 | 147 |
panelServerInterface.setLayout(new GridLayout(2,1)); |
147 | 148 |
panelServerInterface.add(panelConnect); |
148 |
panelServerInterface.add(txtInput);
|
|
149 |
panelServerInterface.add(txtMatrix);
|
|
149 | 150 |
|
150 | 151 |
// Status Elements |
151 | 152 |
lblTokenPasses = new JLabel(); |
... | ... | |
289 | 290 |
indicator = new SelectionIndicator(canvas); |
290 | 291 |
indicator.setRadius(RADIUS+3, 15); //a tad more than the bot radius |
291 | 292 |
packetMonitor = new PacketMonitor(); |
292 |
dataupdater = new DataUpdater();
|
|
293 |
simulator = new Simulator();
|
|
293 | 294 |
|
294 |
csi = new ColonetServerInterface(log); |
|
295 |
csi = new ColonetServerInterface(log, txtMatrix);
|
|
295 | 296 |
|
296 | 297 |
} |
297 | 298 |
|
... | ... | |
322 | 323 |
drawThread.start(); |
323 | 324 |
indicator.start(); |
324 | 325 |
packetMonitor.start(); |
326 |
simulator.start(); |
|
325 | 327 |
} else if (source == btnConnect) { |
326 | 328 |
doSocket(); |
329 |
dataUpdater = new DataUpdater(); |
|
330 |
dataUpdater.start(); |
|
327 | 331 |
} else if (source == btnRemoveTask) { |
328 | 332 |
try { |
329 | 333 |
taskListModel.remove(taskList.getSelectedIndex()); |
... | ... | |
366 | 370 |
if (i != count-1) s.append("\n"); |
367 | 371 |
} |
368 | 372 |
|
369 |
txtInput.setText(s.toString());
|
|
373 |
txtMatrix.setText(s.toString());
|
|
370 | 374 |
} |
371 | 375 |
|
372 | 376 |
private void doSocket () { |
... | ... | |
451 | 455 |
canvas.fillRect(0, 0, image.getWidth(), image.getHeight()); |
452 | 456 |
|
453 | 457 |
// parse the matrix, to see what robots exist |
454 |
String [] rows = txtInput.getText().split("\n");
|
|
458 |
String [] rows = txtMatrix.getText().split("\n");
|
|
455 | 459 |
numBots = rows.length; |
456 | 460 |
String [][] entries = new String[numBots][numBots]; |
457 | 461 |
valid = true; |
... | ... | |
775 | 779 |
|
776 | 780 |
/* |
777 | 781 |
* DataUpdater thread. |
782 |
* The purpose of this thread is to request data from the server at regular intervals. |
|
778 | 783 |
* |
779 | 784 |
*/ |
780 | 785 |
class DataUpdater extends Thread { |
781 |
final int DATAUPDATER_DELAY = 666;
|
|
786 |
final int DATAUPDATER_DELAY = 1100;
|
|
782 | 787 |
|
783 | 788 |
public DataUpdater () { |
784 | 789 |
super("Colonet DataUpdater"); |
... | ... | |
788 | 793 |
String line; |
789 | 794 |
while (true) { |
790 | 795 |
try { |
791 |
if (csi == null) return; |
|
792 |
line = csi.getLine(); |
|
793 |
if (line != null) { |
|
794 |
log.append("Incoming data: [" + line + "]"); |
|
795 |
//TODO: parse incoming data here |
|
796 |
|
|
797 |
//request more data |
|
798 |
//csi.sendRequest("Get all data", "server"); |
|
799 |
|
|
800 |
// update robot list |
|
801 |
int numRobots = 5; |
|
802 |
String [] robotList = new String[numRobots+1]; |
|
803 |
robotList[0] = "All"; |
|
804 |
for (int i = 1; i <= numRobots; i++) |
|
805 |
robotList[i] = "Robot " + i; |
|
806 |
cmbRobotNum = new JComboBox(robotList); |
|
807 |
} |
|
796 |
//request more data |
|
797 |
if (csi.isReady()) |
|
798 |
csi.sendRequest(ColonetServerInterface.REQUEST_BOM_MATRIX, ""); |
|
808 | 799 |
Thread.sleep(DATAUPDATER_DELAY); |
809 | 800 |
} catch (InterruptedException e) { |
810 | 801 |
return; |
Also available in: Unified diff