Skip to content

Commit 120d574

Browse files
committed
Fix the appearance of the tiles
1 parent 63013b4 commit 120d574

File tree

6 files changed

+30
-4520
lines changed

6 files changed

+30
-4520
lines changed

src/main/java/jcs/ui/layout/LayoutCanvas.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public enum Mode {
108108

109109
private RoutesDialog routesDialog;
110110

111+
private boolean showCenter;
112+
111113
public LayoutCanvas() {
112114
this(false);
113115
}
@@ -118,9 +120,11 @@ public LayoutCanvas(boolean readonly) {
118120
setOpaque(true);
119121
setDoubleBuffered(true);
120122

123+
showCenter = "true".equalsIgnoreCase(System.getProperty("tile.show.center", "false"));
124+
121125
this.readonly = readonly;
122126
drawGrid = !readonly;
123-
this.executor = Executors.newSingleThreadExecutor();
127+
this.executor = Executors.newCachedThreadPool();
124128

125129
this.mode = Mode.SELECT;
126130
this.orientation = Orientation.EAST;
@@ -151,7 +155,7 @@ public void paint(Graphics g) {
151155
paintDotGrid(g);
152156
//default -> no grid
153157
}
154-
}
158+
}
155159

156160
//long now = System.currentTimeMillis();
157161
//Logger.trace("Duration: " + (now - started) + " ms.");
@@ -232,23 +236,16 @@ void setDirection(Direction direction) {
232236
}
233237

234238
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);
248241

249-
private void loadTiles() {
250-
List<Tile> tiles = TileCache.loadTiles(readonly);
242+
java.awt.EventQueue.invokeLater(() -> {
243+
loadTiles(tiles);
244+
});
245+
});
246+
}
251247

248+
private void loadTiles(List<Tile> tiles) {
252249
removeAll();
253250
selectedTile = null;
254251

@@ -276,15 +273,14 @@ private void loadTiles() {
276273

277274
for (Tile tile : tiles) {
278275
add(tile);
279-
boolean showCenter = "true".equalsIgnoreCase(System.getProperty("tile.show.center", "false"));
280276
if (showCenter) {
281277
tile.setDrawCenterPoint(showCenter);
282278
}
283279
}
284280
}
285281

286282
private void mouseMoveAction(MouseEvent evt) {
287-
Point sp = LayoutUtil.snapToGrid(evt.getPoint());
283+
//Point sp = LayoutUtil.snapToGrid(evt.getPoint());
288284
if (selectedTile != null) {
289285
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
290286
} else {
@@ -343,10 +339,10 @@ private void mousePressedAction(MouseEvent evt) {
343339
}
344340
}
345341
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;
348345
removeTile(toBeDeleted);
349-
//selectedTiles.clear();
350346
repaint(toBeDeleted.getTileBounds());
351347
selectedTile = null;
352348
}
@@ -478,7 +474,7 @@ private void executeControlActionForTile(Tile tile, Point p) {
478474
bcd.setVisible(true);
479475

480476
Logger.trace("Block properties closed");
481-
this.repaint(block.getTileBounds());
477+
repaint(block.getTileBounds());
482478
}
483479
case SIGNAL -> {
484480
//this.executor.execute(() -> toggleSignal((Signal) tile));
@@ -547,6 +543,7 @@ private void editSelectedTileProperties() {
547543
default -> {
548544
}
549545
}
546+
//TODO: only repaint the edited tile?
550547
repaint();
551548
}
552549
}
@@ -996,8 +993,9 @@ private void resetDispatcherMIActionPerformed(ActionEvent evt) {//GEN-FIRST:even
996993
Block block = (Block) selectedTile;
997994
LocomotiveBean locomotive = block.getBlockBean().getLocomotive();
998995

999-
this.executor.execute(() -> {
996+
executor.execute(() -> {
1000997
AutoPilot.resetDispatcher(locomotive);
998+
1001999
repaint();
10021000
});
10031001
}

src/main/java/jcs/ui/settings/CommandStationPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
* @author frans
8888
*/
8989
public class CommandStationPanel extends JPanel implements TreeSelectionListener {
90+
91+
private static final long serialVersionUID = -6257688549267578845L;
9092

9193
private ComboBoxModel<CommandStationBean> commandStationCBM;
9294
private ComboBoxModel<CommandStationBean> feedbackCBM;
@@ -809,6 +811,7 @@ private void createNodes(DefaultMutableTreeNode root) {
809811

810812
}
811813

814+
//TODO
812815
public void valueChanged(TreeSelectionEvent e) {
813816
DefaultMutableTreeNode node = (DefaultMutableTreeNode) devicesTree.getLastSelectedPathComponent();
814817

0 commit comments

Comments
 (0)