Skip to content

Commit 1124330

Browse files
authored
Merge pull request #116 from fransjacobs/77-block-description-is-removed-when-the-layout-is-re-routed
Fix issue 77 block properties removed when rerouting
2 parents 64dee36 + 5b4c1a2 commit 1124330

File tree

7 files changed

+24
-95
lines changed

7 files changed

+24
-95
lines changed

src/main/java/jcs/persistence/H2PersistenceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public synchronized void remove(RouteBean route) {
864864
database.sql("delete from route_elements where route_id =?", route.getId()).execute();
865865
}
866866

867-
int rows = this.database.delete(route).getRowsAffected();
867+
int rows = database.delete(route).getRowsAffected();
868868
Logger.trace(rows + " rows deleted");
869869
changeSupport.firePropertyChange("data.route.deleted", route, null);
870870
}

src/main/java/jcs/ui/JCSFrame.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ private void showLocomotives() {
220220
locomotiveDialog.setLocationRelativeTo(null);
221221
}
222222
locomotiveDialog.setVisible(true);
223-
224-
//Should add a listener here?
225223
}
226224

227225
private void showAccessories() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,8 @@ private void mousePressedAction(MouseEvent evt) {
321321
if (MouseEvent.BUTTON1 == evt.getButton() && selectedTile == null) {
322322
//Only add a new tile when there is no tile on the selected snapPoint
323323
Logger.trace("Adding a new tile: " + tileType + " @ (" + snapPoint.x + ", " + snapPoint.y + ")");
324-
selectedTile = addTile(snapPoint, tileType, orientation, direction, true, !readonly);
324+
selectedTile = addTile(snapPoint, tileType, orientation, direction, true, showCenter);
325325
if (selectedTile != null) {
326-
//selectedTiles.addAll(selectedTile.getAllPoints());
327326
selectedTile.setSelected(true);
328327
repaint(selectedTile.getTileBounds());
329328
}

src/main/java/jcs/ui/layout/LayoutPanel.form

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
<Properties>
1313
<Property name="text" type="java.lang.String" value="Vertical"/>
1414
</Properties>
15-
<Events>
16-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="verticalMIActionPerformed"/>
17-
</Events>
1815
</MenuItem>
1916
<MenuItem class="javax.swing.JMenuItem" name="horizontalMI">
2017
<Properties>
2118
<Property name="text" type="java.lang.String" value="Horizontal"/>
2219
</Properties>
23-
<Events>
24-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="horizontalMIActionPerformed"/>
25-
</Events>
2620
</MenuItem>
2721
</SubComponents>
2822
</Container>
@@ -36,17 +30,11 @@
3630
<Properties>
3731
<Property name="text" type="java.lang.String" value="Right"/>
3832
</Properties>
39-
<Events>
40-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rightMIActionPerformed"/>
41-
</Events>
4233
</MenuItem>
4334
<MenuItem class="javax.swing.JMenuItem" name="leftMI">
4435
<Properties>
4536
<Property name="text" type="java.lang.String" value="Left"/>
4637
</Properties>
47-
<Events>
48-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="leftMIActionPerformed"/>
49-
</Events>
5038
</MenuItem>
5139
</SubComponents>
5240
</Container>

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -240,35 +240,15 @@ private void initComponents() {
240240
canvas = new LayoutCanvas(this.readonly);
241241

242242
verticalMI.setText("Vertical");
243-
verticalMI.addActionListener(new ActionListener() {
244-
public void actionPerformed(ActionEvent evt) {
245-
verticalMIActionPerformed(evt);
246-
}
247-
});
248243
straightPopupMenu.add(verticalMI);
249244

250245
horizontalMI.setText("Horizontal");
251-
horizontalMI.addActionListener(new ActionListener() {
252-
public void actionPerformed(ActionEvent evt) {
253-
horizontalMIActionPerformed(evt);
254-
}
255-
});
256246
straightPopupMenu.add(horizontalMI);
257247

258248
rightMI.setText("Right");
259-
rightMI.addActionListener(new ActionListener() {
260-
public void actionPerformed(ActionEvent evt) {
261-
rightMIActionPerformed(evt);
262-
}
263-
});
264249
curvedPopupMenu.add(rightMI);
265250

266251
leftMI.setText("Left");
267-
leftMI.addActionListener(new ActionListener() {
268-
public void actionPerformed(ActionEvent evt) {
269-
leftMIActionPerformed(evt);
270-
}
271-
});
272252
curvedPopupMenu.add(leftMI);
273253

274254
xyMI.setText("x: y:");
@@ -741,44 +721,6 @@ public void actionPerformed(ActionEvent evt) {
741721
canvasScrollPane.getAccessibleContext().setAccessibleDescription("");
742722
}// </editor-fold>//GEN-END:initComponents
743723

744-
private void horizontalMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_horizontalMIActionPerformed
745-
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
746-
//
747-
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
748-
// addTile(this.mouseLocation);
749-
// this.mouseLocation = null;
750-
// }
751-
}//GEN-LAST:event_horizontalMIActionPerformed
752-
753-
private void verticalMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_verticalMIActionPerformed
754-
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
755-
//
756-
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
757-
// addTile(this.mouseLocation);
758-
// this.mouseLocation = null;
759-
// }
760-
}//GEN-LAST:event_verticalMIActionPerformed
761-
762-
private void rightMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rightMIActionPerformed
763-
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
764-
//
765-
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
766-
// addTile(this.mouseLocation);
767-
// this.mouseLocation = null;
768-
// }
769-
}//GEN-LAST:event_rightMIActionPerformed
770-
771-
private void leftMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_leftMIActionPerformed
772-
// Logger.trace(this.orientation + ", " + evt.getModifiers() + ", " + evt.paramString());
773-
//
774-
// if (this.mouseLocation != null && evt.getModifiers() == ActionEvent.MOUSE_EVENT_MASK) {
775-
// addTile(this.mouseLocation);
776-
//
777-
// //do someting with the rotation/direction...
778-
// this.mouseLocation = null;
779-
// }
780-
}//GEN-LAST:event_leftMIActionPerformed
781-
782724
private void rotateMIActionPerformed(ActionEvent evt) {//GEN-FIRST:event_rotateMIActionPerformed
783725
// rotateSelectedTile();
784726
}//GEN-LAST:event_rotateMIActionPerformed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
*/
4343
public class RoutesDialog extends javax.swing.JDialog {
4444

45+
private static final long serialVersionUID = -7597770366968399204L;
46+
4547
private final boolean readonly;
4648
private final List<RouteBean> routes;
4749
private RouteBean selectedRoute;
@@ -247,7 +249,8 @@ private void routeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//
247249

248250
private void routeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_routeBtnActionPerformed
249251
if (layoutCanvas != null) {
250-
this.executor.execute(() -> routeLayout());
252+
//executor.execute(() -> routeLayout());
253+
routeLayout();
251254
} else {
252255
Logger.warn("Can not perform routing as the LayoutPanel is null " + evt.paramString());
253256
}

src/main/java/jcs/ui/layout/pathfinding/astar/AStar.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
*/
4040
public class AStar {
4141

42-
//private final TileCache tileCache;
43-
4442
private final Graph graph;
4543
private final Map<String, RouteBean> routes;
4644

@@ -150,19 +148,24 @@ private RouteBean createRouteBeanFromNodePath(List<Node> path) {
150148
}
151149

152150
public void persistRoutes() {
153-
for (RouteBean route : this.routes.values()) {
151+
for (RouteBean route : routes.values()) {
154152
PersistenceFactory.getService().persist(route);
155153
}
156154

157-
//Now also create the blocks
158-
List<Node> blockNodes = this.graph.getBlockNodes();
155+
List<Node> blockNodes = graph.getBlockNodes();
159156

160157
for (Node block : blockNodes) {
161-
BlockBean bb = new BlockBean(block.getTile().getTileBean());
162-
//Use a default
163-
bb.setMinWaitTime(10);
164-
bb.setAlwaysStop(true);
165-
158+
BlockBean bb = block.getTile().getBlockBean();
159+
if (bb == null) {
160+
bb = new BlockBean(block.getTile().getTileBean());
161+
bb.setAlwaysStop(true);
162+
bb.setMinWaitTime(10);
163+
} else {
164+
Logger.trace("Using existing BlockBean: " + bb);
165+
if (bb.getMinWaitTime() == null) {
166+
bb.setMinWaitTime(10);
167+
}
168+
}
166169
PersistenceFactory.getService().persist(bb);
167170
}
168171
}
@@ -176,8 +179,8 @@ public Map<String, RouteBean> getRoutes() {
176179
}
177180

178181
public List<Node> findPath(String fromNodeId, String fromSuffix, String toNodeId, String toSuffix) {
179-
Node from = this.graph.getNode(fromNodeId);
180-
Node to = this.graph.getNode(toNodeId);
182+
Node from = graph.getNode(fromNodeId);
183+
Node to = graph.getNode(toNodeId);
181184
return findPath(from, fromSuffix, to, toSuffix);
182185
}
183186

@@ -231,26 +234,22 @@ public List<RouteBean> routeAll() {
231234
}
232235

233236
public void buildGraph(List<Tile> tiles) {
234-
//this.tileCache.reload(tiles);
235-
this.graph.clear();
236-
237+
graph.clear();
237238
//Every Tile becomes a node
238239
for (Tile tile : tiles) {
239240
Node n = new Node(tile);
240-
this.graph.addNode(n);
241+
graph.addNode(n);
241242
}
242243

243-
Logger.trace("Graph has " + this.graph.size() + " nodes...");
244+
Logger.trace("Graph has " + graph.size() + " nodes...");
244245

245246
//Create the links or connection between the Nodes
246247
for (Node node : graph.getNodes()) {
247248
Collection<Point> neighborPoints = node.getTile().getNeighborPoints().values();
248249
Logger.trace("Node: " + node.getId() + " has " + neighborPoints.size() + " neighbors " + (node.isBlock() ? "[Block]" : "") + (node.isJunction() ? "[Junction]" : ""));
249250

250251
for (Point p : neighborPoints) {
251-
//if (tileCache.contains(p)) {
252252
if (TileCache.contains(p)) {
253-
//Node neighbor = graph.getNode(tileCache.getTileId(p));
254253
Node neighbor = graph.getNode(TileCache.findTile(p).getId());
255254

256255
if (node.getTile().isAdjacent(neighbor.getTile())) {

0 commit comments

Comments
 (0)