|
@@ -11,10 +11,12 @@ import java.io.File;
|
11
|
11
|
import java.io.IOException;
|
12
|
12
|
import java.io.OutputStream;
|
13
|
13
|
import java.io.PrintStream;
|
|
14
|
+import java.lang.reflect.Constructor;
|
14
|
15
|
import java.util.ArrayList;
|
15
|
16
|
|
16
|
17
|
import javax.swing.BorderFactory;
|
17
|
18
|
import javax.swing.BoxLayout;
|
|
19
|
+import javax.swing.JButton;
|
18
|
20
|
import javax.swing.JFileChooser;
|
19
|
21
|
import javax.swing.JFrame;
|
20
|
22
|
import javax.swing.JLabel;
|
|
@@ -28,13 +30,21 @@ import javax.swing.JSplitPane;
|
28
|
30
|
import javax.swing.JTextArea;
|
29
|
31
|
import javax.swing.KeyStroke;
|
30
|
32
|
import javax.swing.SwingConstants;
|
|
33
|
+import javax.swing.UIManager;
|
31
|
34
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
32
|
35
|
|
|
36
|
+import org.insa.algo.AbstractSolution;
|
|
37
|
+import org.insa.algo.shortestpath.BellmanFordAlgorithm;
|
|
38
|
+import org.insa.algo.shortestpath.ShortestPathAlgorithm;
|
|
39
|
+import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
|
|
40
|
+import org.insa.algo.shortestpath.ShortestPathInstance;
|
|
41
|
+import org.insa.algo.shortestpath.ShortestPathInstance.Mode;
|
|
42
|
+import org.insa.algo.shortestpath.ShortestPathSolution;
|
33
|
43
|
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentGraphicObserver;
|
34
|
44
|
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentTextObserver;
|
35
|
45
|
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
|
36
|
46
|
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsInstance;
|
37
|
|
-import org.insa.drawing.DrawingVisible;
|
|
47
|
+import org.insa.drawing.Drawing;
|
38
|
48
|
import org.insa.drawing.graph.BlackAndWhiteGraphPalette;
|
39
|
49
|
import org.insa.drawing.graph.GraphDrawing;
|
40
|
50
|
import org.insa.drawing.graph.PathDrawing;
|
|
@@ -48,71 +58,76 @@ import org.insa.graph.io.Openfile;
|
48
|
58
|
import com.sun.glass.events.KeyEvent;
|
49
|
59
|
|
50
|
60
|
public class MainWindow extends JFrame {
|
51
|
|
-
|
|
61
|
+
|
52
|
62
|
public class JOutputStream extends OutputStream {
|
53
|
|
- private JTextArea textArea;
|
54
|
|
-
|
55
|
|
- public JOutputStream(JTextArea textArea) {
|
56
|
|
- this.textArea = textArea;
|
57
|
|
- }
|
58
|
|
-
|
59
|
|
- @Override
|
60
|
|
- public void write(int b) throws IOException {
|
61
|
|
- // redirects data to the text area
|
62
|
|
- textArea.setText(textArea.getText() + String.valueOf((char)b));
|
63
|
|
- // scrolls the text area to the end of data
|
64
|
|
- textArea.setCaretPosition(textArea.getDocument().getLength());
|
65
|
|
- // keeps the textArea up to date
|
66
|
|
- textArea.update(textArea.getGraphics());
|
67
|
|
- }
|
|
63
|
+ private JTextArea textArea;
|
|
64
|
+
|
|
65
|
+ public JOutputStream(JTextArea textArea) {
|
|
66
|
+ this.textArea = textArea;
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ @Override
|
|
70
|
+ public void write(int b) throws IOException {
|
|
71
|
+ // redirects data to the text area
|
|
72
|
+ textArea.setText(textArea.getText() + String.valueOf((char)b));
|
|
73
|
+ // scrolls the text area to the end of data
|
|
74
|
+ textArea.setCaretPosition(textArea.getDocument().getLength());
|
|
75
|
+ // keeps the textArea up to date
|
|
76
|
+ textArea.update(textArea.getGraphics());
|
|
77
|
+ }
|
68
|
78
|
}
|
69
|
79
|
|
70
|
80
|
/**
|
71
|
81
|
*
|
72
|
82
|
*/
|
73
|
83
|
private static final long serialVersionUID = -527660583705140687L;
|
74
|
|
-
|
|
84
|
+
|
75
|
85
|
/**
|
76
|
86
|
*
|
77
|
87
|
*/
|
78
|
88
|
private static final String WINDOW_TITLE = "BE Graphes INSA";
|
79
|
|
-
|
|
89
|
+
|
80
|
90
|
/**
|
81
|
91
|
*
|
82
|
92
|
*/
|
83
|
93
|
private static final Dimension DEFAULT_DIMENSION = new Dimension(800, 600);
|
84
|
|
-
|
|
94
|
+
|
85
|
95
|
// Current graph.
|
86
|
96
|
private Graph graph;
|
87
|
|
-
|
|
97
|
+
|
88
|
98
|
// Current loaded path.
|
89
|
99
|
private Path currentPath;
|
90
|
|
-
|
|
100
|
+
|
91
|
101
|
// List of item for the top menus.
|
92
|
102
|
private JMenuItem openMapItem;
|
93
|
|
-
|
|
103
|
+
|
94
|
104
|
// List of items that cannot be used without a graph
|
95
|
105
|
private ArrayList<JMenuItem> graphItems = new ArrayList<JMenuItem>();
|
96
|
|
-
|
|
106
|
+
|
97
|
107
|
// Label containing the map ID of the current graph.
|
98
|
108
|
private JLabel mapIdPanel;
|
99
|
109
|
|
|
110
|
+ private JPanel threadPanel;
|
|
111
|
+
|
100
|
112
|
// Log stream and print stream
|
101
|
113
|
private JOutputStream logStream;
|
102
|
114
|
private PrintStream printStream;
|
103
|
115
|
|
|
116
|
+ // Current running thread
|
|
117
|
+ private Thread currentThread;
|
|
118
|
+
|
104
|
119
|
/**
|
105
|
120
|
*
|
106
|
121
|
*/
|
107
|
|
- private DrawingVisible drawing;
|
108
|
|
-
|
|
122
|
+ private Drawing drawing;
|
|
123
|
+
|
109
|
124
|
public MainWindow() {
|
110
|
125
|
super(WINDOW_TITLE);
|
111
|
126
|
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
112
|
127
|
setLayout(new BorderLayout());
|
113
|
128
|
setSize(DEFAULT_DIMENSION);
|
114
|
129
|
setJMenuBar(createMenuBar());
|
115
|
|
-
|
|
130
|
+
|
116
|
131
|
addWindowListener(new WindowAdapter() {
|
117
|
132
|
public void windowClosing(WindowEvent e) {
|
118
|
133
|
int confirmed = JOptionPane.showConfirmDialog(null,
|
|
@@ -125,13 +140,13 @@ public class MainWindow extends JFrame {
|
125
|
140
|
}
|
126
|
141
|
}
|
127
|
142
|
});
|
128
|
|
-
|
|
143
|
+
|
129
|
144
|
// Create graph area
|
130
|
145
|
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
131
|
|
-
|
132
|
|
- drawing = new DrawingVisible();
|
|
146
|
+
|
|
147
|
+ drawing = new Drawing();
|
133
|
148
|
drawing.setBackground(Color.WHITE);
|
134
|
|
-
|
|
149
|
+
|
135
|
150
|
JTextArea infoPanel = new JTextArea();
|
136
|
151
|
infoPanel.setMinimumSize(new Dimension(200, 50));
|
137
|
152
|
// infoPanel.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.GRAY));
|
|
@@ -140,36 +155,70 @@ public class MainWindow extends JFrame {
|
140
|
155
|
infoPanel.setEditable(false);
|
141
|
156
|
this.logStream = new JOutputStream(infoPanel);
|
142
|
157
|
this.printStream = new PrintStream(this.logStream);
|
143
|
|
-
|
144
|
|
- sp.setResizeWeight(0.8);
|
145
|
|
- // sp.setEnabled(false);
|
146
|
|
- sp.setDividerSize(5);
|
147
|
|
-
|
148
|
|
- sp.setBackground(Color.WHITE);
|
|
158
|
+
|
|
159
|
+ sp.setResizeWeight(0.8);
|
|
160
|
+ // sp.setEnabled(false);
|
|
161
|
+ sp.setDividerSize(5);
|
|
162
|
+
|
|
163
|
+ sp.setBackground(Color.WHITE);
|
149
|
164
|
sp.add(drawing);
|
150
|
165
|
sp.add(new JScrollPane(infoPanel));
|
151
|
166
|
this.add(sp, BorderLayout.CENTER);
|
152
|
|
-
|
|
167
|
+
|
153
|
168
|
this.add(createStatusBar(), BorderLayout.SOUTH);
|
154
|
169
|
}
|
155
|
170
|
|
|
171
|
+ private void launchThread(Runnable runnable) {
|
|
172
|
+ currentThread = new Thread(new Runnable() {
|
|
173
|
+ @Override
|
|
174
|
+ public void run() {
|
|
175
|
+ threadPanel.setVisible(true);
|
|
176
|
+ runnable.run();
|
|
177
|
+ threadPanel.setVisible(false);
|
|
178
|
+ }
|
|
179
|
+ });
|
|
180
|
+ currentThread.start();
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ private ShortestPathInstance getShortestPathParameters() {
|
|
184
|
+ // TODO: Select origin / end nodes.
|
|
185
|
+ return new ShortestPathInstance(
|
|
186
|
+ graph, graph.getNodes().get(2), graph.getNodes().get(139), Mode.TIME);
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ private void launchShortestPathThread(ShortestPathAlgorithm spAlgorithm) {
|
|
190
|
+ spAlgorithm.addObserver(new ShortestPathGraphicObserver(drawing));
|
|
191
|
+ // algo.addObserver(new ShortestPathTextObserver(printStream));
|
|
192
|
+ launchThread(new Runnable() {
|
|
193
|
+ @Override
|
|
194
|
+ public void run() {
|
|
195
|
+ spAlgorithm.run();
|
|
196
|
+ AbstractSolution solution = spAlgorithm.getLastSolution();
|
|
197
|
+ if (solution != null && solution.isFeasible()) {
|
|
198
|
+ new PathDrawing(drawing).drawPath(((ShortestPathSolution)solution).getPath());
|
|
199
|
+ }
|
|
200
|
+ }
|
|
201
|
+ });
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ @SuppressWarnings("restriction")
|
156
|
205
|
private JMenuBar createMenuBar() {
|
157
|
206
|
|
158
|
207
|
// Open Map item...
|
159
|
208
|
openMapItem = new JMenuItem("Open Map... ",
|
160
|
|
- KeyEvent.VK_O);
|
|
209
|
+ KeyEvent.VK_O);
|
161
|
210
|
openMapItem.setAccelerator(KeyStroke.getKeyStroke(
|
162
|
|
- KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
|
211
|
+ KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
163
|
212
|
openMapItem.addActionListener(new ActionListener() {
|
164
|
213
|
@Override
|
165
|
214
|
public void actionPerformed(ActionEvent e) {
|
166
|
215
|
JFileChooser chooser = new JFileChooser();
|
167
|
|
- FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
168
|
|
- "Map & compressed map files", "map", "map.gz");
|
169
|
|
- chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
170
|
|
- chooser.setFileFilter(filter);
|
171
|
|
- if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
172
|
|
- BinaryGraphReader reader;
|
|
216
|
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
|
217
|
+ "Map & compressed map files", "map", "map.gz");
|
|
218
|
+ chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
|
219
|
+ chooser.setFileFilter(filter);
|
|
220
|
+ if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
|
221
|
+ BinaryGraphReader reader;
|
173
|
222
|
try {
|
174
|
223
|
reader = new BinaryGraphReader(
|
175
|
224
|
Openfile.open(chooser.getSelectedFile().getAbsolutePath()));
|
|
@@ -177,38 +226,38 @@ public class MainWindow extends JFrame {
|
177
|
226
|
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
178
|
227
|
return ;
|
179
|
228
|
}
|
180
|
|
- try {
|
181
|
|
- graph = reader.read();
|
182
|
|
- }
|
183
|
|
- catch (Exception exception) {
|
|
229
|
+ try {
|
|
230
|
+ graph = reader.read();
|
|
231
|
+ }
|
|
232
|
+ catch (Exception exception) {
|
184
|
233
|
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read graph from the selected file.");
|
185
|
234
|
return ;
|
186
|
|
- }
|
187
|
|
- drawing.clear();
|
188
|
|
- new GraphDrawing(drawing).drawGraph(graph);
|
189
|
|
-
|
190
|
|
- for (JMenuItem item: graphItems) {
|
191
|
|
- item.setEnabled(true);
|
192
|
|
- }
|
193
|
|
- mapIdPanel.setText("Map ID: 0x" + Integer.toHexString(graph.getMapId()));
|
194
|
|
- }
|
|
235
|
+ }
|
|
236
|
+ drawing.clear();
|
|
237
|
+ new GraphDrawing(drawing).drawGraph(graph);
|
|
238
|
+
|
|
239
|
+ for (JMenuItem item: graphItems) {
|
|
240
|
+ item.setEnabled(true);
|
|
241
|
+ }
|
|
242
|
+ mapIdPanel.setText("Map ID: 0x" + Integer.toHexString(graph.getMapId()));
|
|
243
|
+ }
|
195
|
244
|
}
|
196
|
245
|
});
|
197
|
|
-
|
|
246
|
+
|
198
|
247
|
// Open Path item...
|
199
|
248
|
JMenuItem openPathItem = new JMenuItem("Open Path... ", KeyEvent.VK_P);
|
200
|
249
|
openPathItem.setAccelerator(KeyStroke.getKeyStroke(
|
201
|
|
- KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
|
250
|
+ KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
202
|
251
|
openPathItem.addActionListener(new ActionListener() {
|
203
|
252
|
@Override
|
204
|
253
|
public void actionPerformed(ActionEvent e) {
|
205
|
254
|
JFileChooser chooser = new JFileChooser();
|
206
|
|
- FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
207
|
|
- "Path & compressed path files", "path", "path.gz");
|
208
|
|
- chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
209
|
|
- chooser.setFileFilter(filter);
|
210
|
|
- if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
211
|
|
- BinaryPathReader reader;
|
|
255
|
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
|
256
|
+ "Path & compressed path files", "path", "path.gz");
|
|
257
|
+ chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
|
258
|
+ chooser.setFileFilter(filter);
|
|
259
|
+ if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
|
260
|
+ BinaryPathReader reader;
|
212
|
261
|
try {
|
213
|
262
|
reader = new BinaryPathReader(
|
214
|
263
|
Openfile.open(chooser.getSelectedFile().getAbsolutePath()));
|
|
@@ -216,23 +265,23 @@ public class MainWindow extends JFrame {
|
216
|
265
|
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
217
|
266
|
return ;
|
218
|
267
|
}
|
219
|
|
- try {
|
220
|
|
- currentPath = reader.readPath(graph);
|
221
|
|
- }
|
222
|
|
- catch (MapMismatchException exception) {
|
223
|
|
- JOptionPane.showMessageDialog(MainWindow.this, "The selected file does not contain a path for the current graph.");
|
224
|
|
- return;
|
225
|
|
- }
|
226
|
|
- catch (Exception exception) {
|
|
268
|
+ try {
|
|
269
|
+ currentPath = reader.readPath(graph);
|
|
270
|
+ }
|
|
271
|
+ catch (MapMismatchException exception) {
|
|
272
|
+ JOptionPane.showMessageDialog(MainWindow.this, "The selected file does not contain a path for the current graph.");
|
|
273
|
+ return;
|
|
274
|
+ }
|
|
275
|
+ catch (Exception exception) {
|
227
|
276
|
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read path from the selected file.");
|
228
|
277
|
return ;
|
229
|
|
- }
|
230
|
|
- new PathDrawing(drawing).drawPath(currentPath);
|
231
|
|
- }
|
|
278
|
+ }
|
|
279
|
+ new PathDrawing(drawing).drawPath(currentPath);
|
|
280
|
+ }
|
232
|
281
|
}
|
233
|
282
|
});
|
234
|
283
|
graphItems.add(openPathItem);
|
235
|
|
-
|
|
284
|
+
|
236
|
285
|
// Close item
|
237
|
286
|
JMenuItem closeItem = new JMenuItem("Quit", KeyEvent.VK_Q);
|
238
|
287
|
closeItem.setAccelerator(KeyStroke.getKeyStroke(
|
|
@@ -250,7 +299,7 @@ public class MainWindow extends JFrame {
|
250
|
299
|
fileMenu.add(openPathItem);
|
251
|
300
|
fileMenu.addSeparator();
|
252
|
301
|
fileMenu.add(closeItem);
|
253
|
|
-
|
|
302
|
+
|
254
|
303
|
// Second menu
|
255
|
304
|
JMenuItem drawGraphItem = new JMenuItem("Redraw", KeyEvent.VK_R);
|
256
|
305
|
drawGraphItem.setAccelerator(KeyStroke.getKeyStroke(
|
|
@@ -258,10 +307,14 @@ public class MainWindow extends JFrame {
|
258
|
307
|
drawGraphItem.addActionListener(new ActionListener() {
|
259
|
308
|
@Override
|
260
|
309
|
public void actionPerformed(ActionEvent e) {
|
261
|
|
- drawing.clear();
|
262
|
|
- drawing.setAutoRepaint(true);
|
263
|
|
- new GraphDrawing(drawing).drawGraph(graph);
|
264
|
|
- drawing.setAutoRepaint(false);
|
|
310
|
+ launchThread(new Runnable() {
|
|
311
|
+ @Override
|
|
312
|
+ public void run() {
|
|
313
|
+ drawing.clear();
|
|
314
|
+ drawing.setAutoRepaint(true);
|
|
315
|
+ new GraphDrawing(drawing).drawGraph(graph);
|
|
316
|
+ }
|
|
317
|
+ });
|
265
|
318
|
}
|
266
|
319
|
});
|
267
|
320
|
graphItems.add(drawGraphItem);
|
|
@@ -271,40 +324,58 @@ public class MainWindow extends JFrame {
|
271
|
324
|
drawGraphBWItem.addActionListener(new ActionListener() {
|
272
|
325
|
@Override
|
273
|
326
|
public void actionPerformed(ActionEvent e) {
|
274
|
|
- drawing.clear();
|
275
|
|
- drawing.setAutoRepaint(true);
|
276
|
|
- new GraphDrawing(drawing, new BlackAndWhiteGraphPalette()).drawGraph(graph);
|
277
|
|
- drawing.setAutoRepaint(false);
|
|
327
|
+ launchThread(new Runnable() {
|
|
328
|
+ @Override
|
|
329
|
+ public void run() {
|
|
330
|
+ drawing.clear();
|
|
331
|
+ drawing.setAutoRepaint(true);
|
|
332
|
+ new GraphDrawing(drawing, new BlackAndWhiteGraphPalette()).drawGraph(graph);
|
|
333
|
+ }
|
|
334
|
+ });
|
278
|
335
|
}
|
279
|
336
|
});
|
280
|
337
|
graphItems.add(drawGraphBWItem);
|
281
|
|
-
|
|
338
|
+
|
282
|
339
|
JMenu graphMenu = new JMenu("Graph");
|
283
|
340
|
graphMenu.add(drawGraphItem);
|
284
|
341
|
graphMenu.add(drawGraphBWItem);
|
285
|
|
-
|
|
342
|
+
|
286
|
343
|
// Algo menu
|
287
|
344
|
JMenu algoMenu = new JMenu("Algorithms");
|
288
|
|
-
|
|
345
|
+
|
|
346
|
+ // Weakly connected components
|
289
|
347
|
JMenuItem wccItem = new JMenuItem("Weakly Connected Components");
|
290
|
348
|
wccItem.addActionListener(new ActionListener() {
|
291
|
349
|
@Override
|
292
|
350
|
public void actionPerformed(ActionEvent e) {
|
293
|
|
-
|
294
|
351
|
WeaklyConnectedComponentsInstance instance = new WeaklyConnectedComponentsInstance(graph);
|
295
|
352
|
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(instance);
|
296
|
353
|
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
297
|
|
-
|
298
|
|
- (new Thread(algo)).start();
|
|
354
|
+ // algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
|
355
|
+ launchThread(algo);
|
|
356
|
+ }
|
|
357
|
+ });
|
|
358
|
+
|
|
359
|
+ // Shortest path
|
|
360
|
+ JMenuItem bellmanItem = new JMenuItem("Shortest Path (Bellman-Ford)");
|
|
361
|
+ bellmanItem.addActionListener(new ActionListener() {
|
|
362
|
+ @Override
|
|
363
|
+ public void actionPerformed(ActionEvent e) {
|
|
364
|
+ launchShortestPathThread(new BellmanFordAlgorithm(getShortestPathParameters()));
|
299
|
365
|
}
|
300
|
366
|
});
|
301
|
367
|
graphItems.add(wccItem);
|
302
|
|
-
|
|
368
|
+ graphItems.add(bellmanItem);
|
|
369
|
+
|
303
|
370
|
algoMenu.add(wccItem);
|
304
|
|
-
|
|
371
|
+ algoMenu.addSeparator();
|
|
372
|
+ algoMenu.add(bellmanItem);
|
|
373
|
+ // algoMenu.add(djikstraItem);
|
|
374
|
+ // algoMenu.add(aStarItem);
|
|
375
|
+
|
305
|
376
|
// Create the menu bar.
|
306
|
377
|
JMenuBar menuBar = new JMenuBar();
|
307
|
|
-
|
|
378
|
+
|
308
|
379
|
menuBar.add(fileMenu);
|
309
|
380
|
menuBar.add(graphMenu);
|
310
|
381
|
menuBar.add(algoMenu);
|
|
@@ -312,29 +383,60 @@ public class MainWindow extends JFrame {
|
312
|
383
|
for (JMenuItem item: graphItems) {
|
313
|
384
|
item.setEnabled(false);
|
314
|
385
|
}
|
315
|
|
-
|
|
386
|
+
|
316
|
387
|
return menuBar;
|
317
|
388
|
}
|
318
|
|
-
|
|
389
|
+
|
319
|
390
|
private JPanel createStatusBar() {
|
320
|
391
|
// create the status bar panel and shove it down the bottom of the frame
|
321
|
392
|
JPanel statusPanel = new JPanel();
|
322
|
393
|
statusPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY));
|
323
|
|
- statusPanel.setPreferredSize(new Dimension(getWidth(), 20));
|
324
|
|
- statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
|
325
|
|
-
|
|
394
|
+ statusPanel.setPreferredSize(new Dimension(getWidth(), 34));
|
|
395
|
+ statusPanel.setLayout(new BorderLayout());
|
|
396
|
+
|
326
|
397
|
mapIdPanel = new JLabel();
|
327
|
398
|
mapIdPanel.setHorizontalAlignment(SwingConstants.LEFT);
|
328
|
|
- statusPanel.add(mapIdPanel);
|
|
399
|
+ statusPanel.add(mapIdPanel, BorderLayout.WEST);
|
|
400
|
+
|
|
401
|
+ JLabel threadInfo = new JLabel("Thread running... ");
|
|
402
|
+ JButton threadButton = new JButton("Stop");
|
|
403
|
+ threadButton.addActionListener(new ActionListener() {
|
|
404
|
+ @SuppressWarnings("deprecation")
|
|
405
|
+ @Override
|
|
406
|
+ public void actionPerformed(ActionEvent e) {
|
|
407
|
+ if (currentThread != null && currentThread.isAlive()) {
|
|
408
|
+ int confirmed = JOptionPane.showConfirmDialog(null,
|
|
409
|
+ "Are you sure you want to kill the running thread?", "Kill Confirmation",
|
|
410
|
+ JOptionPane.YES_NO_OPTION);
|
|
411
|
+ if (confirmed == JOptionPane.YES_OPTION) {
|
|
412
|
+ currentThread.stop();
|
|
413
|
+ currentThread = null;
|
|
414
|
+ threadPanel.setVisible(false);
|
|
415
|
+ }
|
|
416
|
+ }
|
|
417
|
+ }
|
|
418
|
+ });
|
|
419
|
+ threadPanel = new JPanel();
|
|
420
|
+ threadPanel.add(threadInfo);
|
|
421
|
+ threadPanel.add(threadButton);
|
|
422
|
+ // threadPanel.setVisible(false);
|
|
423
|
+ statusPanel.add(threadPanel, BorderLayout.EAST);
|
329
|
424
|
|
330
|
425
|
return statusPanel;
|
331
|
426
|
}
|
332
|
|
-
|
|
427
|
+
|
333
|
428
|
public static void main(final String[] args) {
|
|
429
|
+
|
|
430
|
+ // Try to set system look and feel.
|
|
431
|
+ try {
|
|
432
|
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) ;
|
|
433
|
+ }
|
|
434
|
+ catch (Exception e) { }
|
|
435
|
+
|
334
|
436
|
MainWindow w = new MainWindow();
|
335
|
437
|
w.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
336
|
438
|
w.setVisible(true);
|
337
|
439
|
}
|
338
|
|
-
|
|
440
|
+
|
339
|
441
|
|
340
|
442
|
}
|