@@ -108,6 +108,8 @@ public enum Mode {
108
108
109
109
private RoutesDialog routesDialog ;
110
110
111
+ private boolean showCenter ;
112
+
111
113
public LayoutCanvas () {
112
114
this (false );
113
115
}
@@ -118,9 +120,11 @@ public LayoutCanvas(boolean readonly) {
118
120
setOpaque (true );
119
121
setDoubleBuffered (true );
120
122
123
+ showCenter = "true" .equalsIgnoreCase (System .getProperty ("tile.show.center" , "false" ));
124
+
121
125
this .readonly = readonly ;
122
126
drawGrid = !readonly ;
123
- this .executor = Executors .newSingleThreadExecutor ();
127
+ this .executor = Executors .newCachedThreadPool ();
124
128
125
129
this .mode = Mode .SELECT ;
126
130
this .orientation = Orientation .EAST ;
@@ -151,7 +155,7 @@ public void paint(Graphics g) {
151
155
paintDotGrid (g );
152
156
//default -> no grid
153
157
}
154
- }
158
+ }
155
159
156
160
//long now = System.currentTimeMillis();
157
161
//Logger.trace("Duration: " + (now - started) + " ms.");
@@ -232,23 +236,16 @@ void setDirection(Direction direction) {
232
236
}
233
237
234
238
void loadLayoutInBackground () {
235
- this .executor .execute (() -> loadTiles ());
236
-
237
- // new Thread(new Runnable() {
238
- // public void run() {
239
- // final String text = readHugeFile();
240
- // SwingUtilities.invokeLater(new Runnable() {
241
- // public void run() {
242
- // canvas.setTiles();
243
- // }
244
- // });
245
- // }
246
- // }).start();
247
- }
239
+ executor .execute (() -> {
240
+ List <Tile > tiles = TileCache .loadTiles (readonly );
248
241
249
- private void loadTiles () {
250
- List <Tile > tiles = TileCache .loadTiles (readonly );
242
+ java .awt .EventQueue .invokeLater (() -> {
243
+ loadTiles (tiles );
244
+ });
245
+ });
246
+ }
251
247
248
+ private void loadTiles (List <Tile > tiles ) {
252
249
removeAll ();
253
250
selectedTile = null ;
254
251
@@ -276,15 +273,14 @@ private void loadTiles() {
276
273
277
274
for (Tile tile : tiles ) {
278
275
add (tile );
279
- boolean showCenter = "true" .equalsIgnoreCase (System .getProperty ("tile.show.center" , "false" ));
280
276
if (showCenter ) {
281
277
tile .setDrawCenterPoint (showCenter );
282
278
}
283
279
}
284
280
}
285
281
286
282
private void mouseMoveAction (MouseEvent evt ) {
287
- Point sp = LayoutUtil .snapToGrid (evt .getPoint ());
283
+ // Point sp = LayoutUtil.snapToGrid(evt.getPoint());
288
284
if (selectedTile != null ) {
289
285
setCursor (Cursor .getPredefinedCursor (Cursor .CROSSHAIR_CURSOR ));
290
286
} else {
@@ -343,10 +339,10 @@ private void mousePressedAction(MouseEvent evt) {
343
339
}
344
340
}
345
341
case DELETE -> {
346
- Tile toBeDeleted = (Tile ) getComponentAt (snapPoint );
347
- if (toBeDeleted != null ) {
342
+ Component c = getComponentAt (snapPoint );
343
+ if (c != null && c instanceof Tile ) {
344
+ Tile toBeDeleted = (Tile ) c ;
348
345
removeTile (toBeDeleted );
349
- //selectedTiles.clear();
350
346
repaint (toBeDeleted .getTileBounds ());
351
347
selectedTile = null ;
352
348
}
@@ -478,7 +474,7 @@ private void executeControlActionForTile(Tile tile, Point p) {
478
474
bcd .setVisible (true );
479
475
480
476
Logger .trace ("Block properties closed" );
481
- this . repaint (block .getTileBounds ());
477
+ repaint (block .getTileBounds ());
482
478
}
483
479
case SIGNAL -> {
484
480
//this.executor.execute(() -> toggleSignal((Signal) tile));
@@ -547,6 +543,7 @@ private void editSelectedTileProperties() {
547
543
default -> {
548
544
}
549
545
}
546
+ //TODO: only repaint the edited tile?
550
547
repaint ();
551
548
}
552
549
}
@@ -996,8 +993,9 @@ private void resetDispatcherMIActionPerformed(ActionEvent evt) {//GEN-FIRST:even
996
993
Block block = (Block ) selectedTile ;
997
994
LocomotiveBean locomotive = block .getBlockBean ().getLocomotive ();
998
995
999
- this . executor .execute (() -> {
996
+ executor .execute (() -> {
1000
997
AutoPilot .resetDispatcher (locomotive );
998
+
1001
999
repaint ();
1002
1000
});
1003
1001
}
0 commit comments