From 89b6bc58197abd51cb9cc85f9e846cd4d730dbc8 Mon Sep 17 00:00:00 2001 From: Holt59 Date: Sat, 3 Mar 2018 18:21:16 +0100 Subject: [PATCH] Fix issue with observers. --- src/main/org/insa/graphics/MainWindow.java | 6 +++++- src/main/org/insa/graphics/ShortestPathPanel.java | 2 +- .../org/insa/graphics/drawing/components/BasicDrawing.java | 4 ++-- .../insa/graphics/drawing/components/MapZoomControls.java | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/org/insa/graphics/MainWindow.java b/src/main/org/insa/graphics/MainWindow.java index 3892970..e345c45 100644 --- a/src/main/org/insa/graphics/MainWindow.java +++ b/src/main/org/insa/graphics/MainWindow.java @@ -169,7 +169,6 @@ public class MainWindow extends JFrame { } spPanel.setEnabled(false); - launchShortestPathThread(spAlgorithm); if (evt.isGraphicVisualizationEnabled()) { spAlgorithm.addObserver(new ShortestPathGraphicObserver(drawing)); @@ -177,6 +176,8 @@ public class MainWindow extends JFrame { if (evt.isTextualVisualizationEnabled()) { spAlgorithm.addObserver(new ShortestPathTextObserver(printStream)); } + + launchShortestPathThread(spAlgorithm); } }); spPanel.setVisible(false); @@ -285,6 +286,9 @@ public class MainWindow extends JFrame { threadTimer.stop(); threadPanel.setVisible(false); currentThread.setThread(null); + if (spPanel.isVisible()) { + spPanel.setEnabled(true); + } } private void displayShortestPathSolution(ShortestPathSolution solution) { diff --git a/src/main/org/insa/graphics/ShortestPathPanel.java b/src/main/org/insa/graphics/ShortestPathPanel.java index 7b195a6..7d34846 100644 --- a/src/main/org/insa/graphics/ShortestPathPanel.java +++ b/src/main/org/insa/graphics/ShortestPathPanel.java @@ -194,7 +194,7 @@ public class ShortestPathPanel extends JPanel { @Override public String toString() { - return "Non-private roads allowed for motorcars"; + return "Only non-private roads allowed for motorcars"; } } }); arcFilterSelect.setBackground(Color.WHITE); diff --git a/src/main/org/insa/graphics/drawing/components/BasicDrawing.java b/src/main/org/insa/graphics/drawing/components/BasicDrawing.java index d1ace53..9ceb0ac 100644 --- a/src/main/org/insa/graphics/drawing/components/BasicDrawing.java +++ b/src/main/org/insa/graphics/drawing/components/BasicDrawing.java @@ -154,6 +154,7 @@ public class BasicDrawing extends JPanel implements Drawing { this.points = points; this.origin = origin; this.destination = destination; + this.color = color; } @Override @@ -217,7 +218,7 @@ public class BasicDrawing extends JPanel implements Drawing { @Override public void setWidth(int width) { - this.width = width; + this.width = Math.max(2, width); } @Override @@ -228,7 +229,6 @@ public class BasicDrawing extends JPanel implements Drawing { @Override public void addPoint(Point point) { - this.width = 5; int x = BasicDrawing.this.projx(point.getLongitude()) - this.width / 2; int y = BasicDrawing.this.projy(point.getLatitude()) - this.width / 2; this.graphics.fillOval(x, y, this.width, this.width); diff --git a/src/main/org/insa/graphics/drawing/components/MapZoomControls.java b/src/main/org/insa/graphics/drawing/components/MapZoomControls.java index d6fd2a8..5fa4201 100644 --- a/src/main/org/insa/graphics/drawing/components/MapZoomControls.java +++ b/src/main/org/insa/graphics/drawing/components/MapZoomControls.java @@ -1,5 +1,6 @@ package org.insa.graphics.drawing.components; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Cursor; @@ -173,6 +174,8 @@ public class MapZoomControls { g.drawImage(zoomOut, xoffset, yoffset, observer); zoomOutRect.setBounds(xoffset, yoffset, DEFAULT_HEIGHT, DEFAULT_HEIGHT); + g.setStroke(new BasicStroke(1)); + // Draw ticks xoffset += DEFAULT_HEIGHT + 2; g.setColor(ZOOM_TICK_COLOR);