Browse Source

Switch to Maven project.

Mikaël Capelle 1 year ago
parent
commit
5bb454a3b2
100 changed files with 2298 additions and 1771 deletions
  1. 0
    69
      .classpath
  2. 3
    1
      .gitignore
  3. 0
    5
      .settings/org.eclipse.jdt.core.prefs
  4. 0
    4
      .settings/org.eclipse.m2e.core.prefs
  5. 25
    0
      be-graphes-algos/pom.xml
  6. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java
  7. 4
    4
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java
  8. 6
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java
  9. 16
    16
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java
  10. 4
    4
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java
  11. 6
    6
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java
  12. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java
  13. 13
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingData.java
  14. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingGraphicObserver.java
  15. 5
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingObserver.java
  16. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingSolution.java
  17. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingTextObserver.java
  18. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java
  19. 13
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchData.java
  20. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchGraphicObserver.java
  21. 5
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchObserver.java
  22. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchSolution.java
  23. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchTextObserver.java
  24. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java
  25. 6
    6
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java
  26. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java
  27. 3
    3
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java
  28. 5
    5
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathData.java
  29. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathObserver.java
  30. 7
    13
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathSolution.java
  31. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTextObserver.java
  32. 205
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java
  33. 198
    0
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java
  34. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java
  35. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java
  36. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java
  37. 1
    1
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java
  38. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java
  39. 2
    2
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java
  40. 6
    6
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java
  41. 3
    3
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsData.java
  42. 3
    3
      be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java
  43. 1
    1
      be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java
  44. 1
    1
      be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java
  45. 1
    1
      be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java
  46. 84
    0
      be-graphes-gui/pom.xml
  47. 10
    23
      be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java
  48. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/BlockingActionFactory.java
  49. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java
  50. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java
  51. 5
    5
      be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java
  52. 862
    865
      be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java
  53. 8
    8
      be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java
  54. 11
    12
      be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java
  55. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/RunningAction.java
  56. 8
    7
      be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java
  57. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java
  58. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/ThreadWrapper.java
  59. 3
    3
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java
  60. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java
  61. 7
    7
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java
  62. 14
    14
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java
  63. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java
  64. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java
  65. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java
  66. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java
  67. 19
    19
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java
  68. 521
    465
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java
  69. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapZoomControls.java
  70. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/ZoomAndPanListener.java
  71. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerAutoScaling.java
  72. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerOverlay.java
  73. 97
    97
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/MarkerUtils.java
  74. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/Overlay.java
  75. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PaintUtils.java
  76. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PathOverlay.java
  77. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PointSetOverlay.java
  78. 2
    2
      be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/overlays/PolylineAutoScaling.java
  79. 5
    4
      be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/ShortestPathGraphicObserver.java
  80. 7
    5
      be-graphes-gui/src/main/java/org/insa/graphs/gui/observers/WeaklyConnectedComponentGraphicObserver.java
  81. 15
    16
      be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java
  82. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/ColorUtils.java
  83. 1
    1
      be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java
  84. 0
    0
      be-graphes-gui/src/main/resources/delete-icon.png
  85. 0
    0
      be-graphes-gui/src/main/resources/marker_mask.bin
  86. 0
    0
      be-graphes-gui/src/main/resources/save-icon.png
  87. 0
    0
      be-graphes-gui/src/main/resources/zoomIn.png
  88. 0
    0
      be-graphes-gui/src/main/resources/zoomOut.png
  89. 14
    0
      be-graphes-model/pom.xml
  90. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/AccessRestrictions.java
  91. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/Arc.java
  92. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/ArcBackward.java
  93. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/ArcForward.java
  94. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/Graph.java
  95. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/GraphStatistics.java
  96. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/Node.java
  97. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/Path.java
  98. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/Point.java
  99. 1
    1
      be-graphes-model/src/main/java/org/insa/graphs/model/RoadInformation.java
  100. 0
    0
      be-graphes-model/src/main/java/org/insa/graphs/model/io/BadFormatException.java

+ 0
- 69
.classpath View File

@@ -1,69 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<classpath>
3
-	<classpathentry kind="src" output="target/classes" path="src/main">
4
-		<attributes>
5
-			<attribute name="optional" value="true"/>
6
-			<attribute name="maven.pomderived" value="true"/>
7
-		</attributes>
8
-	</classpathentry>
9
-	<classpathentry kind="src" output="target/test-classes" path="src/test">
10
-		<attributes>
11
-			<attribute name="optional" value="true"/>
12
-			<attribute name="maven.pomderived" value="true"/>
13
-		</attributes>
14
-	</classpathentry>
15
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
16
-		<attributes>
17
-			<attribute name="maven.pomderived" value="true"/>
18
-		</attributes>
19
-	</classpathentry>
20
-	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
21
-		<attributes>
22
-			<attribute name="maven.pomderived" value="true"/>
23
-		</attributes>
24
-	</classpathentry>
25
-	<classpathentry kind="lib" path="libs/kxml2-2.3.0.jar"/>
26
-	<classpathentry kind="lib" path="libs/mapsforge-core-0.9.1.jar">
27
-		<attributes>
28
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-core-0.9.1-javadoc.jar!/"/>
29
-		</attributes>
30
-	</classpathentry>
31
-	<classpathentry kind="lib" path="libs/mapsforge-map-0.9.1.jar">
32
-		<attributes>
33
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-0.9.1-javadoc.jar!/"/>
34
-		</attributes>
35
-	</classpathentry>
36
-	<classpathentry kind="lib" path="libs/mapsforge-map-awt-0.9.1.jar">
37
-		<attributes>
38
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-awt-0.9.1-javadoc.jar!/"/>
39
-		</attributes>
40
-	</classpathentry>
41
-	<classpathentry kind="lib" path="libs/mapsforge-map-reader-0.9.1.jar">
42
-		<attributes>
43
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-reader-0.9.1-javadoc.jar!/"/>
44
-		</attributes>
45
-	</classpathentry>
46
-	<classpathentry kind="lib" path="libs/mapsforge-poi-0.9.1.jar">
47
-		<attributes>
48
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-poi-0.9.1-javadoc.jar!/"/>
49
-		</attributes>
50
-	</classpathentry>
51
-	<classpathentry kind="lib" path="libs/mapsforge-poi-awt-0.9.1.jar">
52
-		<attributes>
53
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-poi-awt-0.9.1-javadoc.jar!/"/>
54
-		</attributes>
55
-	</classpathentry>
56
-	<classpathentry kind="lib" path="libs/mapsforge-themes-0.9.1.jar">
57
-		<attributes>
58
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-themes-0.9.1-javadoc.jar!/"/>
59
-		</attributes>
60
-	</classpathentry>
61
-	<classpathentry kind="lib" path="libs/svg-salamander-1.0.jar">
62
-		<attributes>
63
-			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/svg-salamander-1.0-javadoc.jar!/"/>
64
-		</attributes>
65
-	</classpathentry>
66
-	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
67
-	<classpathentry kind="lib" path="res"/>
68
-	<classpathentry kind="output" path="target/classes"/>
69
-</classpath>

+ 3
- 1
.gitignore View File

@@ -6,12 +6,14 @@ bin
6 6
 target
7 7
 doc
8 8
 *.jar
9
+.settings
10
+.classpath
9 11
 
10 12
 # Editor specific files and folders
11 13
 *~
12 14
 .project
13 15
 
14
-# Project speicific files and folders
16
+# Project specific files and folders
15 17
 *.mapfg
16 18
 *.mapgr
17 19
 *.path

+ 0
- 5
.settings/org.eclipse.jdt.core.prefs View File

@@ -1,5 +0,0 @@
1
-eclipse.preferences.version=1
2
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3
-org.eclipse.jdt.core.compiler.compliance=1.8
4
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5
-org.eclipse.jdt.core.compiler.source=1.8

+ 0
- 4
.settings/org.eclipse.m2e.core.prefs View File

@@ -1,4 +0,0 @@
1
-activeProfiles=
2
-eclipse.preferences.version=1
3
-resolveWorkspaceProjects=true
4
-version=1

+ 25
- 0
be-graphes-algos/pom.xml View File

@@ -0,0 +1,25 @@
1
+<?xml version="1.0"?>
2
+<project
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4
+	xmlns="http://maven.apache.org/POM/4.0.0"
5
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6
+	<modelVersion>4.0.0</modelVersion>
7
+	<parent>
8
+		<groupId>org.insa.graphs</groupId>
9
+		<artifactId>be-graphes-all</artifactId>
10
+		<version>0.0.1-SNAPSHOT</version>
11
+	</parent>
12
+	<artifactId>be-graphes-algos</artifactId>
13
+	<name>be-graphes-algos</name>
14
+	<url>http://maven.apache.org</url>
15
+	<properties>
16
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17
+	</properties>
18
+	<dependencies>
19
+		<dependency>
20
+			<groupId>org.insa.graphs</groupId>
21
+			<artifactId>be-graphes-model</artifactId>
22
+			<version>${project.version}</version>
23
+		</dependency>
24
+	</dependencies>
25
+</project>

src/main/org/insa/algo/AbstractAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractAlgorithm.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3 3
 import java.time.Duration;
4 4
 import java.time.Instant;

src/main/org/insa/algo/AbstractInputData.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3
-import org.insa.graph.Arc;
4
-import org.insa.graph.Graph;
5
-import org.insa.graph.GraphStatistics;
3
+import org.insa.graphs.model.Arc;
4
+import org.insa.graphs.model.Graph;
5
+import org.insa.graphs.model.GraphStatistics;
6 6
 
7 7
 /**
8 8
  * Base class for algorithm input data classes. This class contains the basic

src/main/org/insa/algo/AbstractSolution.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractSolution.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3 3
 import java.time.Duration;
4 4
 
@@ -38,6 +38,11 @@ public abstract class AbstractSolution {
38 38
         this.status = Status.UNKNOWN;
39 39
     }
40 40
 
41
+    /**
42
+     * 
43
+     * @param data
44
+     * @param status
45
+     */
41 46
     protected AbstractSolution(AbstractInputData data, Status status) {
42 47
         this.data = data;
43 48
         this.status = status;

src/main/org/insa/algo/AlgorithmFactory.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3 3
 import java.lang.reflect.Constructor;
4 4
 import java.util.IdentityHashMap;
@@ -7,11 +7,11 @@ import java.util.Map;
7 7
 import java.util.Set;
8 8
 import java.util.TreeSet;
9 9
 
10
-import org.insa.algo.shortestpath.AStarAlgorithm;
11
-import org.insa.algo.shortestpath.BellmanFordAlgorithm;
12
-import org.insa.algo.shortestpath.DijkstraAlgorithm;
13
-import org.insa.algo.shortestpath.ShortestPathAlgorithm;
14
-import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
10
+import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
11
+import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
12
+import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
13
+import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
14
+import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
15 15
 
16 16
 /**
17 17
  * Factory class used to register and retrieve algorithms based on their common
@@ -43,10 +43,10 @@ public class AlgorithmFactory {
43 43
      * the given base algorithm.
44 44
      * 
45 45
      * @param baseAlgorithm Base algorithm class that corresponds to the newly
46
-     *        registered algorithm class (e.g., generic algorithm class for the
47
-     *        problem).
48
-     * @param name Name for the registered algorithm class.
49
-     * @param algoClass Algorithm class to register.
46
+     *                      registered algorithm class (e.g., generic algorithm
47
+     *                      class for the problem).
48
+     * @param name          Name for the registered algorithm class.
49
+     * @param algoClass     Algorithm class to register.
50 50
      */
51 51
     public static void registerAlgorithm(Class<? extends AbstractAlgorithm<?>> baseAlgorithm,
52 52
             String name, Class<? extends AbstractAlgorithm<?>> algoClass) {
@@ -62,14 +62,14 @@ public class AlgorithmFactory {
62 62
      * an object equivalent to `new Algorithm(data)`.
63 63
      * 
64 64
      * @param algorithm Class of the algorithm to create.
65
-     * @param data Input data for the algorithm.
65
+     * @param data      Input data for the algorithm.
66 66
      * 
67 67
      * @return A new instance of the given algorithm class using the given data.
68 68
      * 
69 69
      * @throws Exception if something wrong happens when constructing the object,
70
-     *         i.e. the given input data does not correspond to the given algorithm
71
-     *         and/or no constructor that takes a single parameter of type
72
-     *         (data.getClass()) exists.
70
+     *                   i.e. the given input data does not correspond to the given
71
+     *                   algorithm and/or no constructor that takes a single
72
+     *                   parameter of type (data.getClass()) exists.
73 73
      */
74 74
     public static AbstractAlgorithm<?> createAlgorithm(
75 75
             Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data)
@@ -96,7 +96,7 @@ public class AlgorithmFactory {
96 96
      * registerAlgorithm.
97 97
      * 
98 98
      * @param baseAlgorithm Base algorithm class for the algorithm to retrieve.
99
-     * @param name Name of the algorithm to retrieve.
99
+     * @param name          Name of the algorithm to retrieve.
100 100
      * 
101 101
      * @return Class corresponding to the given name.
102 102
      * 
@@ -112,7 +112,7 @@ public class AlgorithmFactory {
112 112
      * for the given base algorithm class.
113 113
      * 
114 114
      * @param baseAlgorithm Base algorithm class for the algorithm class names to
115
-     *        retrieve.
115
+     *                      retrieve.
116 116
      * 
117 117
      * @return Names of the currently registered algorithms.
118 118
      * 

src/main/org/insa/algo/ArcInspector.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3
-import org.insa.algo.AbstractInputData.Mode;
4
-import org.insa.graph.Arc;
5
-import org.insa.graph.GraphStatistics;
3
+import org.insa.graphs.algorithm.AbstractInputData.Mode;
4
+import org.insa.graphs.model.Arc;
5
+import org.insa.graphs.model.GraphStatistics;
6 6
 
7 7
 /**
8 8
  * This class can be used to indicate to an algorithm which arcs can be used and

src/main/org/insa/algo/ArcInspectorFactory.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java View File

@@ -1,14 +1,14 @@
1
-package org.insa.algo;
1
+package org.insa.graphs.algorithm;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.EnumSet;
5 5
 import java.util.List;
6 6
 
7
-import org.insa.algo.AbstractInputData.Mode;
8
-import org.insa.graph.AccessRestrictions.AccessMode;
9
-import org.insa.graph.AccessRestrictions.AccessRestriction;
10
-import org.insa.graph.Arc;
11
-import org.insa.graph.GraphStatistics;
7
+import org.insa.graphs.algorithm.AbstractInputData.Mode;
8
+import org.insa.graphs.model.Arc;
9
+import org.insa.graphs.model.GraphStatistics;
10
+import org.insa.graphs.model.AccessRestrictions.AccessMode;
11
+import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
12 12
 
13 13
 public class ArcInspectorFactory {
14 14
 

src/main/org/insa/algo/carpooling/CarPoolingAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingAlgorithm.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.algo.carpooling;
1
+package org.insa.graphs.algorithm.carpooling;
2 2
 
3
-import org.insa.algo.AbstractAlgorithm;
3
+import org.insa.graphs.algorithm.AbstractAlgorithm;
4 4
 
5 5
 public abstract class CarPoolingAlgorithm extends AbstractAlgorithm<CarPoolingObserver> {
6 6
 

+ 13
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingData.java View File

@@ -0,0 +1,13 @@
1
+package org.insa.graphs.algorithm.carpooling;
2
+
3
+import org.insa.graphs.algorithm.AbstractInputData;
4
+import org.insa.graphs.algorithm.ArcInspector;
5
+import org.insa.graphs.model.Graph;
6
+
7
+public class CarPoolingData extends AbstractInputData {
8
+
9
+    protected CarPoolingData(Graph graph, ArcInspector arcFilter) {
10
+        super(graph, arcFilter);
11
+    }
12
+
13
+}

src/main/org/insa/algo/carpooling/CarPoolingGraphicObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingGraphicObserver.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.carpooling;
1
+package org.insa.graphs.algorithm.carpooling;
2 2
 
3 3
 public class CarPoolingGraphicObserver implements CarPoolingObserver {
4 4
 

+ 5
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.graphs.algorithm.carpooling;
2
+
3
+public interface CarPoolingObserver {
4
+
5
+}

src/main/org/insa/algo/carpooling/CarPoolingSolution.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingSolution.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.algo.carpooling;
1
+package org.insa.graphs.algorithm.carpooling;
2 2
 
3
-import org.insa.algo.AbstractSolution;
3
+import org.insa.graphs.algorithm.AbstractSolution;
4 4
 
5 5
 public class CarPoolingSolution extends AbstractSolution {
6 6
 

src/main/org/insa/algo/carpooling/CarPoolingTextObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/carpooling/CarPoolingTextObserver.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.carpooling;
1
+package org.insa.graphs.algorithm.carpooling;
2 2
 
3 3
 public class CarPoolingTextObserver implements CarPoolingObserver {
4 4
 

src/main/org/insa/algo/packageswitch/PackageSwitchAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchAlgorithm.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.algo.packageswitch;
1
+package org.insa.graphs.algorithm.packageswitch;
2 2
 
3
-import org.insa.algo.AbstractAlgorithm;
3
+import org.insa.graphs.algorithm.AbstractAlgorithm;
4 4
 
5 5
 public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm<PackageSwitchObserver> {
6 6
 

+ 13
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchData.java View File

@@ -0,0 +1,13 @@
1
+package org.insa.graphs.algorithm.packageswitch;
2
+
3
+import org.insa.graphs.algorithm.AbstractInputData;
4
+import org.insa.graphs.algorithm.ArcInspector;
5
+import org.insa.graphs.model.Graph;
6
+
7
+public class PackageSwitchData extends AbstractInputData {
8
+
9
+    protected PackageSwitchData(Graph graph, ArcInspector arcFilter) {
10
+        super(graph, arcFilter);
11
+    }
12
+
13
+}

src/main/org/insa/algo/packageswitch/PackageSwitchGraphicObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchGraphicObserver.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.packageswitch;
1
+package org.insa.graphs.algorithm.packageswitch;
2 2
 
3 3
 public class PackageSwitchGraphicObserver implements PackageSwitchObserver {
4 4
 

+ 5
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.graphs.algorithm.packageswitch;
2
+
3
+public interface PackageSwitchObserver {
4
+
5
+}

src/main/org/insa/algo/packageswitch/PackageSwitchSolution.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchSolution.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.algo.packageswitch;
1
+package org.insa.graphs.algorithm.packageswitch;
2 2
 
3
-import org.insa.algo.AbstractSolution;
3
+import org.insa.graphs.algorithm.AbstractSolution;
4 4
 
5 5
 public class PackageSwitchSolution extends AbstractSolution {
6 6
 

src/main/org/insa/algo/packageswitch/PackageSwitchTextObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/packageswitch/PackageSwitchTextObserver.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.packageswitch;
1
+package org.insa.graphs.algorithm.packageswitch;
2 2
 
3 3
 public class PackageSwitchTextObserver implements PackageSwitchObserver {
4 4
 

src/main/org/insa/algo/shortestpath/AStarAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3 3
 public class AStarAlgorithm extends DijkstraAlgorithm {
4 4
 

src/main/org/insa/algo/shortestpath/BellmanFordAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/BellmanFordAlgorithm.java View File

@@ -1,14 +1,14 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.Arrays;
5 5
 import java.util.Collections;
6 6
 
7
-import org.insa.algo.AbstractSolution.Status;
8
-import org.insa.graph.Arc;
9
-import org.insa.graph.Graph;
10
-import org.insa.graph.Node;
11
-import org.insa.graph.Path;
7
+import org.insa.graphs.algorithm.AbstractSolution.Status;
8
+import org.insa.graphs.model.Arc;
9
+import org.insa.graphs.model.Graph;
10
+import org.insa.graphs.model.Node;
11
+import org.insa.graphs.model.Path;
12 12
 
13 13
 public class BellmanFordAlgorithm extends ShortestPathAlgorithm {
14 14
 

src/main/org/insa/algo/shortestpath/DijkstraAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3 3
 public class DijkstraAlgorithm extends ShortestPathAlgorithm {
4 4
 
@@ -8,7 +8,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
8 8
 
9 9
     @Override
10 10
     protected ShortestPathSolution doRun() {
11
-        ShortestPathData data = getInputData();
11
+        final ShortestPathData data = getInputData();
12 12
         ShortestPathSolution solution = null;
13 13
         // TODO:
14 14
         return solution;

src/main/org/insa/algo/shortestpath/ShortestPathAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathAlgorithm.java View File

@@ -1,7 +1,7 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
-import org.insa.algo.AbstractAlgorithm;
4
-import org.insa.graph.Node;
3
+import org.insa.graphs.algorithm.AbstractAlgorithm;
4
+import org.insa.graphs.model.Node;
5 5
 
6 6
 public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
7 7
 

src/main/org/insa/algo/shortestpath/ShortestPathData.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathData.java View File

@@ -1,9 +1,9 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
-import org.insa.algo.AbstractInputData;
4
-import org.insa.algo.ArcInspector;
5
-import org.insa.graph.Graph;
6
-import org.insa.graph.Node;
3
+import org.insa.graphs.algorithm.AbstractInputData;
4
+import org.insa.graphs.algorithm.ArcInspector;
5
+import org.insa.graphs.model.Graph;
6
+import org.insa.graphs.model.Node;
7 7
 
8 8
 public class ShortestPathData extends AbstractInputData {
9 9
 

src/main/org/insa/algo/shortestpath/ShortestPathObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathObserver.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
-import org.insa.graph.Node;
3
+import org.insa.graphs.model.Node;
4 4
 
5 5
 public interface ShortestPathObserver {
6 6
 	

src/main/org/insa/algo/shortestpath/ShortestPathSolution.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathSolution.java View File

@@ -1,21 +1,14 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
-import org.insa.algo.AbstractInputData.Mode;
4
-import org.insa.algo.AbstractSolution;
5
-import org.insa.graph.Arc;
6
-import org.insa.graph.Path;
3
+import org.insa.graphs.algorithm.AbstractInputData.Mode;
4
+import org.insa.graphs.model.Arc;
5
+import org.insa.graphs.model.Path;
6
+import org.insa.graphs.algorithm.AbstractSolution;
7 7
 
8 8
 public class ShortestPathSolution extends AbstractSolution {
9 9
 
10 10
     // Optimal solution.
11
-    private Path path;
12
-
13
-    /**
14
-     * {@inheritDoc}
15
-     */
16
-    public ShortestPathSolution(ShortestPathData data) {
17
-        super(data);
18
-    }
11
+    private final Path path;
19 12
 
20 13
     /**
21 14
      * Create a new infeasible shortest-path solution for the given input and
@@ -26,6 +19,7 @@ public class ShortestPathSolution extends AbstractSolution {
26 19
      */
27 20
     public ShortestPathSolution(ShortestPathData data, Status status) {
28 21
         super(data, status);
22
+        this.path = null;
29 23
     }
30 24
 
31 25
     /**

src/main/org/insa/algo/shortestpath/ShortestPathTextObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTextObserver.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.algo.shortestpath;
1
+package org.insa.graphs.algorithm.shortestpath;
2 2
 
3 3
 import java.io.PrintStream;
4 4
 
5
-import org.insa.graph.Node;
5
+import org.insa.graphs.model.Node;
6 6
 
7 7
 public class ShortestPathTextObserver implements ShortestPathObserver {
8 8
 

+ 205
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java View File

@@ -0,0 +1,205 @@
1
+package org.insa.graphs.algorithm.utils;
2
+
3
+import java.util.ArrayList;
4
+
5
+/**
6
+ * Implements a binary heap containing elements of type E.
7
+ *
8
+ * Note that all comparisons are based on the compareTo method, hence E must
9
+ * implement Comparable
10
+ * 
11
+ * @author Mark Allen Weiss
12
+ * @author DLB
13
+ */
14
+public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
15
+
16
+    // Number of elements in heap.
17
+    private int currentSize;
18
+
19
+    // The heap array.
20
+    protected final ArrayList<E> array;
21
+
22
+    /**
23
+     * Construct a new empty binary heap.
24
+     */
25
+    public BinaryHeap() {
26
+        this.currentSize = 0;
27
+        this.array = new ArrayList<E>();
28
+    }
29
+
30
+    /**
31
+     * Construct a copy of the given heap.
32
+     * 
33
+     * @param heap Binary heap to copy.
34
+     */
35
+    public BinaryHeap(BinaryHeap<E> heap) {
36
+        this.currentSize = heap.currentSize;
37
+        this.array = new ArrayList<E>(heap.array);
38
+    }
39
+
40
+    /**
41
+     * Set an element at the given index.
42
+     * 
43
+     * @param index Index at which the element should be set.
44
+     * @param value Element to set.
45
+     */
46
+    private void arraySet(int index, E value) {
47
+        if (index == this.array.size()) {
48
+            this.array.add(value);
49
+        }
50
+        else {
51
+            this.array.set(index, value);
52
+        }
53
+    }
54
+
55
+    /**
56
+     * @return Index of the parent of the given index.
57
+     */
58
+    protected int indexParent(int index) {
59
+        return (index - 1) / 2;
60
+    }
61
+
62
+    /**
63
+     * @return Index of the left child of the given index.
64
+     */
65
+    protected int indexLeft(int index) {
66
+        return index * 2 + 1;
67
+    }
68
+
69
+    /**
70
+     * Internal method to percolate up in the heap.
71
+     * 
72
+     * @param index Index at which the percolate begins.
73
+     */
74
+    private void percolateUp(int index) {
75
+        E x = this.array.get(index);
76
+
77
+        for (; index > 0
78
+                && x.compareTo(this.array.get(indexParent(index))) < 0; index = indexParent(
79
+                        index)) {
80
+            E moving_val = this.array.get(indexParent(index));
81
+            this.arraySet(index, moving_val);
82
+        }
83
+
84
+        this.arraySet(index, x);
85
+    }
86
+
87
+    /**
88
+     * Internal method to percolate down in the heap.
89
+     * 
90
+     * @param index Index at which the percolate begins.
91
+     */
92
+    private void percolateDown(int index) {
93
+        int ileft = indexLeft(index);
94
+        int iright = ileft + 1;
95
+
96
+        if (ileft < this.currentSize) {
97
+            E current = this.array.get(index);
98
+            E left = this.array.get(ileft);
99
+            boolean hasRight = iright < this.currentSize;
100
+            E right = (hasRight) ? this.array.get(iright) : null;
101
+
102
+            if (!hasRight || left.compareTo(right) < 0) {
103
+                // Left is smaller
104
+                if (left.compareTo(current) < 0) {
105
+                    this.arraySet(index, left);
106
+                    this.arraySet(ileft, current);
107
+                    this.percolateDown(ileft);
108
+                }
109
+            }
110
+            else {
111
+                // Right is smaller
112
+                if (right.compareTo(current) < 0) {
113
+                    this.arraySet(index, right);
114
+                    this.arraySet(iright, current);
115
+                    this.percolateDown(iright);
116
+                }
117
+            }
118
+        }
119
+    }
120
+
121
+    @Override
122
+    public boolean isEmpty() {
123
+        return this.currentSize == 0;
124
+    }
125
+
126
+    @Override
127
+    public int size() {
128
+        return this.currentSize;
129
+    }
130
+
131
+    @Override
132
+    public void insert(E x) {
133
+        int index = this.currentSize++;
134
+        this.arraySet(index, x);
135
+        this.percolateUp(index);
136
+    }
137
+
138
+    @Override
139
+    public void remove(E x) throws ElementNotFoundException {
140
+        // TODO:
141
+    }
142
+
143
+    @Override
144
+    public E findMin() throws EmptyPriorityQueueException {
145
+        if (isEmpty())
146
+            throw new EmptyPriorityQueueException();
147
+        return this.array.get(0);
148
+    }
149
+
150
+    @Override
151
+    public E deleteMin() throws EmptyPriorityQueueException {
152
+        E minItem = findMin();
153
+        E lastItem = this.array.get(--this.currentSize);
154
+        this.arraySet(0, lastItem);
155
+        this.percolateDown(0);
156
+        return minItem;
157
+    }
158
+
159
+    /**
160
+     * Creates a multi-lines string representing a sorted view of this binary heap.
161
+     * 
162
+     * @return a string containing a sorted view this binary heap.
163
+     */
164
+    public String toStringSorted() {
165
+        return BinaryHeapFormatter.toStringSorted(this, -1);
166
+    }
167
+
168
+    /**
169
+     * Creates a multi-lines string representing a sorted view of this binary heap.
170
+     * 
171
+     * @param maxElement Maximum number of elements to display. or {@code -1} to
172
+     *                   display all the elements.
173
+     * 
174
+     * @return a string containing a sorted view this binary heap.
175
+     */
176
+    public String toStringSorted(int maxElement) {
177
+        return BinaryHeapFormatter.toStringSorted(this, maxElement);
178
+    }
179
+
180
+    /**
181
+     * Creates a multi-lines string representing a tree view of this binary heap.
182
+     * 
183
+     * @return a string containing a tree view of this binary heap.
184
+     */
185
+    public String toStringTree() {
186
+        return BinaryHeapFormatter.toStringTree(this, Integer.MAX_VALUE);
187
+    }
188
+
189
+    /**
190
+     * Creates a multi-lines string representing a tree view of this binary heap.
191
+     * 
192
+     * @param maxDepth Maximum depth of the tree to display.
193
+     * 
194
+     * @return a string containing a tree view of this binary heap.
195
+     */
196
+    public String toStringTree(int maxDepth) {
197
+        return BinaryHeapFormatter.toStringTree(this, maxDepth);
198
+    }
199
+
200
+    @Override
201
+    public String toString() {
202
+        return BinaryHeapFormatter.toStringTree(this, 8);
203
+    }
204
+
205
+}

+ 198
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java View File

@@ -0,0 +1,198 @@
1
+package org.insa.graphs.algorithm.utils;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class BinaryHeapFormatter {
6
+
7
+    /**
8
+     * This class is used by {@link #toStringTree}, and simply contains three string
9
+     * accumulating. This is an immutable class.
10
+     *
11
+     */
12
+    private static class Context {
13
+
14
+        // Output text:
15
+        public final String acu;
16
+
17
+        // Margin to get back exactly under the current position:
18
+        public final String margin;
19
+
20
+        // Last margin used for the last child of a node. The markers are different:
21
+        public final String lastmargin;
22
+
23
+        /**
24
+         * Creaet a new {@code Context}.
25
+         * 
26
+         * @param acu        The accumulated string.
27
+         * @param margin     The current margin.
28
+         * @param lastMargin The last margin used.
29
+         */
30
+        public Context(String acu, String margin, String lastMargin) {
31
+            this.acu = acu;
32
+            this.margin = margin;
33
+            this.lastmargin = lastMargin;
34
+        }
35
+
36
+        /**
37
+         * Creates a new context by appending newlines to this context.
38
+         * 
39
+         * @param n Number of newlines to append.
40
+         * 
41
+         * @return a new context with {@code n} newlines appended.
42
+         */
43
+        public Context appendNewlines(int n) {
44
+            if (n <= 0) {
45
+                return this;
46
+            }
47
+            else {
48
+                return (new Context(this.acu + "\n" + this.margin, this.margin, this.lastmargin)
49
+                        .appendNewlines(n - 1));
50
+            }
51
+        }
52
+
53
+        /**
54
+         * Creates a new context by appending the given string to this context.
55
+         * 
56
+         * @param count Number of spaces to add to the margin, or {@code null} to use
57
+         *              the length of the string.
58
+         * @param text  String to append.
59
+         * 
60
+         * @return a new context with {@code text} appended.
61
+         */
62
+        public Context appendText(Integer count, String text) {
63
+            int cnt = (count == null) ? text.length() : count;
64
+            final String spaces = new String(new char[cnt]).replace('\0', ' ');
65
+            return new Context(this.acu + text, this.margin + spaces, this.lastmargin + spaces);
66
+        }
67
+
68
+        /**
69
+         * Creates a new context by appending a branch to this context.
70
+         * 
71
+         * @param n     Number of spaces to add to the margin, or {@code null} to use
72
+         *              the length of the string.
73
+         * @param label Name of the branch.
74
+         * 
75
+         * @return a new context with the branch appended.
76
+         */
77
+        public Context appendBranch(Integer count, String label) {
78
+            final Context ctxt = this.appendText(count, label);
79
+
80
+            if (count == null) {
81
+                return new Context(ctxt.acu + "_", ctxt.margin + "|", ctxt.margin + " ");
82
+            }
83
+            else {
84
+                return new Context(ctxt.acu, ctxt.margin + "|", ctxt.margin + " ")
85
+                        .appendNewlines(1);
86
+
87
+            }
88
+        }
89
+    }
90
+
91
+    /*
92
+     * Input : ready to write the current node at the current context position.
93
+     * Output : the last character of acu is the last character of the current node.
94
+     */
95
+    protected static <E extends Comparable<E>> Context toStringLoop(BinaryHeap<E> heap,
96
+            Context ctxt, int node, int max_depth) {
97
+
98
+        if (max_depth < 0) {
99
+            return ctxt.appendText(null, "...");
100
+        }
101
+        else {
102
+            E nodeval = heap.array.get(node);
103
+            String nodevals = nodeval.toString();
104
+
105
+            ArrayList<Integer> childs = new ArrayList<Integer>();
106
+            // Add childs
107
+            int index_left = heap.indexLeft(node);
108
+            int index_right = index_left + 1;
109
+
110
+            if (index_left < heap.size()) {
111
+                childs.add(index_left);
112
+            }
113
+            if (index_right < heap.size()) {
114
+                childs.add(index_right);
115
+            }
116
+
117
+            Context ctxt2 = childs.isEmpty() ? ctxt.appendText(null, nodevals)
118
+                    : ctxt.appendBranch(1, nodevals);
119
+
120
+            for (int ch = 0; ch < childs.size(); ch++) {
121
+                boolean is_last = (ch == childs.size() - 1);
122
+                int child = childs.get(ch);
123
+
124
+                if (is_last) {
125
+                    Context ctxt3 = new Context(ctxt2.acu, ctxt2.lastmargin, ctxt2.lastmargin);
126
+                    ctxt2 = new Context(toStringLoop(heap, ctxt3.appendText(null, "___"), child,
127
+                            max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin);
128
+                }
129
+                else {
130
+                    ctxt2 = new Context(toStringLoop(heap, ctxt2.appendText(null, "___"), child,
131
+                            max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin).appendNewlines(2);
132
+                }
133
+            }
134
+
135
+            return ctxt2;
136
+        }
137
+    }
138
+
139
+    /**
140
+     * Creates a multi-lines string representing a tree view of the given binary
141
+     * heap.
142
+     * 
143
+     * @param heap     The binary heap to display.
144
+     * @param maxDepth Maximum depth of the tree to display.
145
+     * 
146
+     * @return a string containing a tree view of the given binary heap.
147
+     */
148
+    public static <E extends Comparable<E>> String toStringTree(BinaryHeap<E> heap, int maxDepth) {
149
+        final Context init_context = new Context("   ", "   ", "   ");
150
+        final Context result = toStringLoop(heap, init_context, 0, maxDepth);
151
+        return result.acu;
152
+    }
153
+
154
+    /**
155
+     * Creates a multi-lines string representing a sorted view of the given binary
156
+     * heap.
157
+     * 
158
+     * @param heap       The binary heap to display.
159
+     * @param maxElement Maximum number of elements to display. or {@code -1} to
160
+     *                   display all the elements.
161
+     * 
162
+     * @return a string containing a sorted view the given binary heap.
163
+     */
164
+    public static <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap,
165
+            int max_elements) {
166
+        String result = "";
167
+        final BinaryHeap<E> copy = new BinaryHeap<E>(heap);
168
+
169
+        final String truncate;
170
+        if (max_elements < 0 || max_elements >= heap.size()) {
171
+            truncate = "";
172
+        }
173
+        else {
174
+            truncate = ", only " + max_elements + " elements are shown";
175
+        }
176
+
177
+        result += "========  Sorted HEAP  (size = " + heap.size() + truncate + ")  ========\n\n";
178
+
179
+        while (!copy.isEmpty() && max_elements-- != 0) {
180
+            result += copy.deleteMin() + "\n";
181
+        }
182
+
183
+        result += "\n--------  End of heap  --------";
184
+
185
+        return result;
186
+    }
187
+
188
+    public static void main(String[] args) {
189
+        final BinaryHeap<Integer> heap = new BinaryHeap<Integer>();
190
+
191
+        for (int i = 0; i < 12; i++) {
192
+            heap.insert(i);
193
+        }
194
+
195
+        System.out.println(heap.toStringSorted(-1));
196
+        System.out.println(heap.toStringTree(6));
197
+    }
198
+}

src/main/org/insa/algo/utils/BinarySearchTree.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinarySearchTree.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 import java.util.SortedSet;
4 4
 import java.util.TreeSet;

src/main/org/insa/algo/utils/ElementNotFoundException.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/ElementNotFoundException.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 public class ElementNotFoundException extends RuntimeException {
4 4
 

src/main/org/insa/algo/utils/EmptyPriorityQueueException.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/EmptyPriorityQueueException.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 public class EmptyPriorityQueueException extends RuntimeException {
4 4
 

src/main/org/insa/algo/utils/PriorityQueue.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/PriorityQueue.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 /**
4 4
  * Interface representing a basic priority queue.

src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentObserver.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.algo.weakconnectivity;
1
+package org.insa.graphs.algorithm.weakconnectivity;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 
5
-import org.insa.graph.Node;
5
+import org.insa.graphs.model.Node;
6 6
 
7 7
 public interface WeaklyConnectedComponentObserver {
8 8
 

src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentTextObserver.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentTextObserver.java View File

@@ -1,9 +1,9 @@
1
-package org.insa.algo.weakconnectivity;
1
+package org.insa.graphs.algorithm.weakconnectivity;
2 2
 
3 3
 import java.io.PrintStream;
4 4
 import java.util.ArrayList;
5 5
 
6
-import org.insa.graph.Node;
6
+import org.insa.graphs.model.Node;
7 7
 
8 8
 public class WeaklyConnectedComponentTextObserver implements WeaklyConnectedComponentObserver {
9 9
 	

src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsAlgorithm.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.weakconnectivity;
1
+package org.insa.graphs.algorithm.weakconnectivity;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.Arrays;
@@ -6,11 +6,11 @@ import java.util.HashSet;
6 6
 import java.util.LinkedList;
7 7
 import java.util.Queue;
8 8
 
9
-import org.insa.algo.AbstractAlgorithm;
10
-import org.insa.algo.AbstractSolution.Status;
11
-import org.insa.graph.Arc;
12
-import org.insa.graph.Graph;
13
-import org.insa.graph.Node;
9
+import org.insa.graphs.algorithm.AbstractAlgorithm;
10
+import org.insa.graphs.algorithm.AbstractSolution.Status;
11
+import org.insa.graphs.model.Arc;
12
+import org.insa.graphs.model.Graph;
13
+import org.insa.graphs.model.Node;
14 14
 
15 15
 public class WeaklyConnectedComponentsAlgorithm
16 16
         extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {

src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsData.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsData.java View File

@@ -1,7 +1,7 @@
1
-package org.insa.algo.weakconnectivity;
1
+package org.insa.graphs.algorithm.weakconnectivity;
2 2
 
3
-import org.insa.algo.AbstractInputData;
4
-import org.insa.graph.Graph;
3
+import org.insa.graphs.algorithm.AbstractInputData;
4
+import org.insa.graphs.model.Graph;
5 5
 
6 6
 public class WeaklyConnectedComponentsData extends AbstractInputData {
7 7
 

src/main/org/insa/algo/weakconnectivity/WeaklyConnectedComponentsSolution.java → be-graphes-algos/src/main/java/org/insa/graphs/algorithm/weakconnectivity/WeaklyConnectedComponentsSolution.java View File

@@ -1,9 +1,9 @@
1
-package org.insa.algo.weakconnectivity;
1
+package org.insa.graphs.algorithm.weakconnectivity;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 
5
-import org.insa.algo.AbstractSolution;
6
-import org.insa.graph.Node;
5
+import org.insa.graphs.algorithm.AbstractSolution;
6
+import org.insa.graphs.model.Node;
7 7
 
8 8
 public class WeaklyConnectedComponentsSolution extends AbstractSolution {
9 9
 

src/test/org/insa/algo/utils/BinaryHeapTest.java → be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinaryHeapTest.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 public class BinaryHeapTest extends PriorityQueueTest {
4 4
 

src/test/org/insa/algo/utils/BinarySearchTreeTest.java → be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/BinarySearchTreeTest.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 public class BinarySearchTreeTest extends PriorityQueueTest {
4 4
 

src/test/org/insa/algo/utils/PriorityQueueTest.java → be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/PriorityQueueTest.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.algo.utils;
1
+package org.insa.graphs.algorithm.utils;
2 2
 
3 3
 import static org.junit.Assert.assertEquals;
4 4
 import static org.junit.Assert.assertTrue;

+ 84
- 0
be-graphes-gui/pom.xml View File

@@ -0,0 +1,84 @@
1
+<?xml version="1.0"?>
2
+<project
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4
+	xmlns="http://maven.apache.org/POM/4.0.0"
5
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6
+	<modelVersion>4.0.0</modelVersion>
7
+	<parent>
8
+		<groupId>org.insa.graphs</groupId>
9
+		<artifactId>be-graphes-all</artifactId>
10
+		<version>0.0.1-SNAPSHOT</version>
11
+	</parent>
12
+	
13
+	<properties>
14
+	   <mapsforge.version>0.13.0</mapsforge.version>
15
+	</properties>
16
+	
17
+	<artifactId>be-graphes-gui</artifactId>
18
+	<name>be-graphes-gui</name>
19
+	
20
+	<repositories>
21
+        <repository>
22
+            <id>jitpack.io</id>
23
+            <url>https://jitpack.io</url>
24
+        </repository>
25
+    </repositories>
26
+
27
+	<dependencies>
28
+		<dependency>
29
+			<groupId>org.insa.graphs</groupId>
30
+			<artifactId>be-graphes-model</artifactId>
31
+			<version>${project.version}</version>
32
+		</dependency>
33
+		<dependency>
34
+			<groupId>org.insa.graphs</groupId>
35
+			<artifactId>be-graphes-algos</artifactId>
36
+			<version>${project.version}</version>
37
+		</dependency>
38
+
39
+		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-core -->
40
+		<dependency>
41
+			<groupId>net.sf.kxml</groupId>
42
+			<artifactId>kxml2</artifactId>
43
+			<version>2.3.0</version>
44
+		</dependency>
45
+
46
+        <!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
47
+        <dependency>
48
+            <groupId>org.mapsforge</groupId>
49
+            <artifactId>mapsforge-themes</artifactId>
50
+            <version>${mapsforge.version}</version>
51
+        </dependency>
52
+
53
+		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map -->
54
+		<dependency>
55
+			<groupId>org.mapsforge</groupId>
56
+			<artifactId>mapsforge-map</artifactId>
57
+            <version>${mapsforge.version}</version>
58
+		</dependency>
59
+
60
+		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-awt -->
61
+		<dependency>
62
+			<groupId>org.mapsforge</groupId>
63
+			<artifactId>mapsforge-map-awt</artifactId>
64
+            <version>${mapsforge.version}</version>
65
+		</dependency>
66
+
67
+        <!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
68
+        <dependency>
69
+            <groupId>org.mapsforge</groupId>
70
+            <artifactId>mapsforge-themes</artifactId>
71
+            <version>${mapsforge.version}</version>
72
+        </dependency>
73
+
74
+		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
75
+		<dependency>
76
+			<groupId>org.mapsforge</groupId>
77
+			<artifactId>mapsforge-map-reader</artifactId>
78
+            <version>${mapsforge.version}</version>
79
+		</dependency>
80
+
81
+	</dependencies>
82
+
83
+
84
+</project>

src/main/org/insa/graphics/AlgorithmPanel.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/AlgorithmPanel.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Color;
4 4
 import java.awt.Component;
@@ -22,15 +22,14 @@ import javax.swing.JLabel;
22 22
 import javax.swing.JPanel;
23 23
 import javax.swing.border.EmptyBorder;
24 24
 
25
-import org.insa.algo.AbstractAlgorithm;
26
-import org.insa.algo.AlgorithmFactory;
27
-import org.insa.algo.ArcInspector;
28
-import org.insa.algo.ArcInspectorFactory;
29
-import org.insa.graph.Node;
30
-import org.insa.graphics.NodesInputPanel.InputChangedEvent;
31
-import org.insa.graphics.drawing.Drawing;
32
-import org.insa.graphics.drawing.components.MapViewDrawing;
33
-import org.insa.graphics.utils.ColorUtils;
25
+import org.insa.graphs.algorithm.AbstractAlgorithm;
26
+import org.insa.graphs.algorithm.AlgorithmFactory;
27
+import org.insa.graphs.algorithm.ArcInspector;
28
+import org.insa.graphs.algorithm.ArcInspectorFactory;
29
+import org.insa.graphs.gui.NodesInputPanel.InputChangedEvent;
30
+import org.insa.graphs.gui.drawing.Drawing;
31
+import org.insa.graphs.gui.utils.ColorUtils;
32
+import org.insa.graphs.model.Node;
34 33
 
35 34
 public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
36 35
 
@@ -118,9 +117,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
118 117
     // Graphic / Text checkbox observer
119 118
     private final JCheckBox graphicObserverCheckbox, textualObserverCheckbox;
120 119
 
121
-    // Drawing
122
-    private Drawing drawing = null;
123
-
124 120
     private JButton startAlgoButton;
125 121
 
126 122
     // Start listeners
@@ -360,7 +356,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
360 356
         for (JComponent component: components) {
361 357
             component.setEnabled(enabled);
362 358
         }
363
-        graphicObserverCheckbox.setEnabled(enabled && !(drawing instanceof MapViewDrawing));
359
+        graphicObserverCheckbox.setEnabled(enabled);
364 360
         enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs());
365 361
         startAlgoButton.setEnabled(enabled);
366 362
     }
@@ -376,15 +372,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
376 372
 
377 373
     @Override
378 374
     public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
379
-        if (newDrawing instanceof MapViewDrawing) {
380
-            graphicObserverCheckbox.setSelected(false);
381
-            graphicObserverCheckbox.setEnabled(false);
382
-        }
383
-        else {
384
-            graphicObserverCheckbox.setSelected(true);
385
-            graphicObserverCheckbox.setEnabled(true);
386
-        }
387
-        this.drawing = newDrawing;
388 375
     }
389 376
 
390 377
     @Override

src/main/org/insa/graphics/BlockingActionFactory.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/BlockingActionFactory.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Component;
4 4
 import java.awt.event.ActionEvent;

src/main/org/insa/graphics/DrawingChangeListener.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/DrawingChangeListener.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3
-import org.insa.graphics.drawing.Drawing;
3
+import org.insa.graphs.gui.drawing.Drawing;
4 4
 
5 5
 public interface DrawingChangeListener {
6 6
 

src/main/org/insa/graphics/GraphChangeListener.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphChangeListener.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3
-import org.insa.graph.Graph;
3
+import org.insa.graphs.model.Graph;
4 4
 
5 5
 public interface GraphChangeListener {
6 6
 

src/main/org/insa/graphics/GraphReaderProgressBar.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/GraphReaderProgressBar.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Component;
4 4
 
@@ -11,10 +11,10 @@ import javax.swing.JPanel;
11 11
 import javax.swing.JProgressBar;
12 12
 import javax.swing.border.EmptyBorder;
13 13
 
14
-import org.insa.graph.Arc;
15
-import org.insa.graph.Node;
16
-import org.insa.graph.RoadInformation;
17
-import org.insa.graph.io.GraphReaderObserver;
14
+import org.insa.graphs.model.Arc;
15
+import org.insa.graphs.model.Node;
16
+import org.insa.graphs.model.RoadInformation;
17
+import org.insa.graphs.model.io.GraphReaderObserver;
18 18
 
19 19
 /**
20 20
  * One-time use GraphReaderObserver that display progress in three different

be-graphes-gui/src/main/java/org/insa/graphs/gui/MainWindow.java
File diff suppressed because it is too large
View File


src/main/org/insa/graphics/NodesInputPanel.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/NodesInputPanel.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Color;
4 4
 import java.awt.Font;
@@ -21,13 +21,13 @@ import javax.swing.JTextField;
21 21
 import javax.swing.event.DocumentEvent;
22 22
 import javax.swing.event.DocumentListener;
23 23
 
24
-import org.insa.graph.Graph;
25
-import org.insa.graph.Node;
26
-import org.insa.graph.Point;
27
-import org.insa.graphics.drawing.Drawing;
28
-import org.insa.graphics.drawing.Drawing.AlphaMode;
29
-import org.insa.graphics.drawing.DrawingClickListener;
30
-import org.insa.graphics.drawing.overlays.MarkerOverlay;
24
+import org.insa.graphs.gui.drawing.Drawing;
25
+import org.insa.graphs.gui.drawing.Drawing.AlphaMode;
26
+import org.insa.graphs.gui.drawing.DrawingClickListener;
27
+import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
28
+import org.insa.graphs.model.Graph;
29
+import org.insa.graphs.model.Node;
30
+import org.insa.graphs.model.Point;
31 31
 
32 32
 public class NodesInputPanel extends JPanel
33 33
         implements DrawingClickListener, DrawingChangeListener, GraphChangeListener {

src/main/org/insa/graphics/PathsPanel.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/PathsPanel.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Color;
4 4
 import java.awt.Component;
@@ -32,14 +32,14 @@ import javax.swing.border.EmptyBorder;
32 32
 import javax.swing.event.ChangeEvent;
33 33
 import javax.swing.event.ChangeListener;
34 34
 
35
-import org.insa.graph.Graph;
36
-import org.insa.graph.Path;
37
-import org.insa.graph.io.BinaryPathWriter;
38
-import org.insa.graphics.drawing.Drawing;
39
-import org.insa.graphics.drawing.overlays.PathOverlay;
40
-import org.insa.graphics.utils.ColorUtils;
41
-import org.insa.graphics.utils.FileUtils;
42
-import org.insa.graphics.utils.FileUtils.FolderType;
35
+import org.insa.graphs.gui.drawing.Drawing;
36
+import org.insa.graphs.gui.drawing.overlays.PathOverlay;
37
+import org.insa.graphs.gui.utils.ColorUtils;
38
+import org.insa.graphs.gui.utils.FileUtils;
39
+import org.insa.graphs.gui.utils.FileUtils.FolderType;
40
+import org.insa.graphs.model.Graph;
41
+import org.insa.graphs.model.Path;
42
+import org.insa.graphs.model.io.BinaryPathWriter;
43 43
 
44 44
 public class PathsPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
45 45
 
@@ -232,9 +232,8 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
232 232
                     if (chooser
233 233
                             .showSaveDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
234 234
                         File file = chooser.getSelectedFile();
235
-                        try {
236
-                            BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
237
-                                    new BufferedOutputStream(new FileOutputStream(file))));
235
+                        try (BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
236
+                                    new BufferedOutputStream(new FileOutputStream(file))))) {
238 237
                             writer.writePath(path);
239 238
                         }
240 239
                         catch (IOException e1) {

src/main/org/insa/graphics/RunningAction.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/RunningAction.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.time.Duration;
4 4
 import java.time.Instant;

src/main/org/insa/graphics/SolutionPanel.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/SolutionPanel.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.awt.Color;
4 4
 import java.awt.Component;
@@ -19,12 +19,12 @@ import javax.swing.JPanel;
19 19
 import javax.swing.border.CompoundBorder;
20 20
 import javax.swing.border.EmptyBorder;
21 21
 
22
-import org.insa.algo.AbstractInputData;
23
-import org.insa.algo.AbstractSolution;
24
-import org.insa.graph.Graph;
25
-import org.insa.graph.Path;
26
-import org.insa.graphics.drawing.Drawing;
27
-import org.insa.graphics.drawing.overlays.PathOverlay;
22
+import org.insa.graphs.algorithm.AbstractInputData;
23
+import org.insa.graphs.algorithm.AbstractSolution;
24
+import org.insa.graphs.gui.drawing.Drawing;
25
+import org.insa.graphs.gui.drawing.overlays.PathOverlay;
26
+import org.insa.graphs.model.Graph;
27
+import org.insa.graphs.model.Path;
28 28
 
29 29
 public class SolutionPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
30 30
 
@@ -122,6 +122,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
122 122
 
123 123
         /*
124 124
          * (non-Javadoc)
125
+         * 
125 126
          * @see java.lang.Object#toString()
126 127
          */
127 128
         public String toString() {

src/main/org/insa/graphics/StreamCapturer.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/StreamCapturer.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.io.IOException;
4 4
 import java.io.OutputStream;

src/main/org/insa/graphics/ThreadWrapper.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/ThreadWrapper.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics;
1
+package org.insa.graphs.gui;
2 2
 
3 3
 import java.time.Duration;
4 4
 import java.time.Instant;

src/main/org/insa/graphics/drawing/BasicGraphPalette.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BasicGraphPalette.java View File

@@ -1,9 +1,9 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 import java.awt.Color;
4 4
 
5
-import org.insa.graph.Arc;
6
-import org.insa.graph.RoadInformation.RoadType;
5
+import org.insa.graphs.model.Arc;
6
+import org.insa.graphs.model.RoadInformation.RoadType;
7 7
 
8 8
 public class BasicGraphPalette implements GraphPalette {
9 9
 

src/main/org/insa/graphics/drawing/BlackAndWhiteGraphPalette.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/BlackAndWhiteGraphPalette.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 import java.awt.Color;
4 4
 
5
-import org.insa.graph.Arc;
5
+import org.insa.graphs.model.Arc;
6 6
 
7 7
 public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
8 8
 

src/main/org/insa/graphics/drawing/Drawing.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Drawing.java View File

@@ -1,13 +1,13 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 import java.awt.Color;
4 4
 
5
-import org.insa.graph.Graph;
6
-import org.insa.graph.Path;
7
-import org.insa.graph.Point;
8
-import org.insa.graphics.drawing.overlays.MarkerOverlay;
9
-import org.insa.graphics.drawing.overlays.PathOverlay;
10
-import org.insa.graphics.drawing.overlays.PointSetOverlay;
5
+import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
6
+import org.insa.graphs.gui.drawing.overlays.PathOverlay;
7
+import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
8
+import org.insa.graphs.model.Graph;
9
+import org.insa.graphs.model.Path;
10
+import org.insa.graphs.model.Point;
11 11
 
12 12
 public interface Drawing {
13 13
 

src/main/org/insa/graphics/drawing/DrawingClickListener.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/DrawingClickListener.java View File

@@ -1,14 +1,14 @@
1
-package org.insa.graphics.drawing;
2
-
3
-import org.insa.graph.Point;
4
-
5
-public interface DrawingClickListener {
6
-
7
-    /**
8
-     * Event triggered when a click is made on the map.
9
-     * 
10
-     * @param point Position (on the map) of the mouse click.
11
-     */
12
-    public void mouseClicked(Point point);
13
-
14
-}
1
+package org.insa.graphs.gui.drawing;
2
+
3
+import org.insa.graphs.model.Point;
4
+
5
+public interface DrawingClickListener {
6
+
7
+    /**
8
+     * Event triggered when a click is made on the map.
9
+     * 
10
+     * @param point Position (on the map) of the mouse click.
11
+     */
12
+    public void mouseClicked(Point point);
13
+
14
+}

src/main/org/insa/graphics/drawing/GraphPalette.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/GraphPalette.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 import java.awt.Color;
4 4
 
5
-import org.insa.graph.Arc;
5
+import org.insa.graphs.model.Arc;
6 6
 
7 7
 public interface GraphPalette {
8 8
 

src/main/org/insa/graphics/drawing/MercatorProjection.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/MercatorProjection.java View File

@@ -1,8 +1,8 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 import java.awt.Dimension;
4 4
 
5
-import org.insa.graph.GraphStatistics.BoundingBox;
5
+import org.insa.graphs.model.GraphStatistics.BoundingBox;
6 6
 
7 7
 public class MercatorProjection implements Projection {
8 8
 

src/main/org/insa/graphics/drawing/PlateCarreProjection.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/PlateCarreProjection.java View File

@@ -1,6 +1,6 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3
-import org.insa.graph.GraphStatistics.BoundingBox;
3
+import org.insa.graphs.model.GraphStatistics.BoundingBox;
4 4
 
5 5
 public class PlateCarreProjection implements Projection {
6 6
 

src/main/org/insa/graphics/drawing/Projection.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/Projection.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics.drawing;
1
+package org.insa.graphs.gui.drawing;
2 2
 
3 3
 public interface Projection {
4 4
 

src/main/org/insa/graphics/drawing/components/BasicDrawing.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java View File

@@ -1,4 +1,4 @@
1
-package org.insa.graphics.drawing.components;
1
+package org.insa.graphs.gui.drawing.components;
2 2
 
3 3
 import java.awt.BasicStroke;
4 4
 import java.awt.Color;
@@ -20,24 +20,24 @@ import java.util.List;
20 20
 
21 21
 import javax.swing.JPanel;
22 22
 
23
-import org.insa.graph.Arc;
24
-import org.insa.graph.Graph;
25
-import org.insa.graph.GraphStatistics.BoundingBox;
26
-import org.insa.graph.Node;
27
-import org.insa.graph.Path;
28
-import org.insa.graph.Point;
29
-import org.insa.graphics.drawing.BasicGraphPalette;
30
-import org.insa.graphics.drawing.Drawing;
31
-import org.insa.graphics.drawing.DrawingClickListener;
32
-import org.insa.graphics.drawing.GraphPalette;
33
-import org.insa.graphics.drawing.MercatorProjection;
34
-import org.insa.graphics.drawing.PlateCarreProjection;
35
-import org.insa.graphics.drawing.Projection;
36
-import org.insa.graphics.drawing.overlays.MarkerOverlay;
37
-import org.insa.graphics.drawing.overlays.MarkerUtils;
38
-import org.insa.graphics.drawing.overlays.Overlay;
39
-import org.insa.graphics.drawing.overlays.PathOverlay;
40
-import org.insa.graphics.drawing.overlays.PointSetOverlay;
23
+import org.insa.graphs.gui.drawing.BasicGraphPalette;
24
+import org.insa.graphs.gui.drawing.Drawing;
25
+import org.insa.graphs.gui.drawing.DrawingClickListener;
26
+import org.insa.graphs.gui.drawing.GraphPalette;
27
+import org.insa.graphs.gui.drawing.MercatorProjection;
28
+import org.insa.graphs.gui.drawing.PlateCarreProjection;
29
+import org.insa.graphs.gui.drawing.Projection;
30
+import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
31
+import org.insa.graphs.gui.drawing.overlays.MarkerUtils;
32
+import org.insa.graphs.gui.drawing.overlays.Overlay;
33
+import org.insa.graphs.gui.drawing.overlays.PathOverlay;
34
+import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
35
+import org.insa.graphs.model.Arc;
36
+import org.insa.graphs.model.Graph;
37
+import org.insa.graphs.model.Node;
38
+import org.insa.graphs.model.Path;
39
+import org.insa.graphs.model.Point;
40
+import org.insa.graphs.model.GraphStatistics.BoundingBox;
41 41
 
42 42
 /**
43 43
  *

src/main/org/insa/graphics/drawing/components/MapViewDrawing.java → be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/MapViewDrawing.java View File

@@ -1,465 +1,521 @@
1
-package org.insa.graphics.drawing.components;
2
-
3
-import java.awt.Color;
4
-import java.awt.Graphics;
5
-import java.awt.Graphics2D;
6
-import java.awt.Image;
7
-import java.awt.event.ActionEvent;
8
-import java.awt.event.ActionListener;
9
-import java.io.File;
10
-import java.io.IOException;
11
-import java.util.ArrayList;
12
-import java.util.UUID;
13
-
14
-import org.insa.graph.Arc;
15
-import org.insa.graph.Graph;
16
-import org.insa.graph.Path;
17
-import org.insa.graph.Point;
18
-import org.insa.graphics.drawing.Drawing;
19
-import org.insa.graphics.drawing.DrawingClickListener;
20
-import org.insa.graphics.drawing.GraphPalette;
21
-import org.insa.graphics.drawing.overlays.MarkerAutoScaling;
22
-import org.insa.graphics.drawing.overlays.MarkerOverlay;
23
-import org.insa.graphics.drawing.overlays.MarkerUtils;
24
-import org.insa.graphics.drawing.overlays.Overlay;
25
-import org.insa.graphics.drawing.overlays.PathOverlay;
26
-import org.insa.graphics.drawing.overlays.PointSetOverlay;
27
-import org.insa.graphics.drawing.overlays.PolylineAutoScaling;
28
-import org.mapsforge.core.graphics.GraphicFactory;
29
-import org.mapsforge.core.model.BoundingBox;
30
-import org.mapsforge.core.model.LatLong;
31
-import org.mapsforge.core.model.MapPosition;
32
-import org.mapsforge.core.util.LatLongUtils;
33
-import org.mapsforge.core.util.Parameters;
34
-import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
35
-import org.mapsforge.map.awt.util.AwtUtil;
36
-import org.mapsforge.map.awt.view.MapView;
37
-import org.mapsforge.map.datastore.MapDataStore;
38
-import org.mapsforge.map.layer.Layer;
39
-import org.mapsforge.map.layer.Layers;
40
-import org.mapsforge.map.layer.cache.TileCache;
41
-import org.mapsforge.map.layer.hills.HillsRenderConfig;
42
-import org.mapsforge.map.layer.overlay.Marker;
43
-import org.mapsforge.map.layer.renderer.TileRendererLayer;
44
-import org.mapsforge.map.model.DisplayModel;
45
-import org.mapsforge.map.model.MapViewPosition;
46
-import org.mapsforge.map.model.Model;
47
-import org.mapsforge.map.reader.MapFile;
48
-import org.mapsforge.map.rendertheme.InternalRenderTheme;
49
-
50
-/**
51
- *
52
- */
53
-public class MapViewDrawing extends MapView implements Drawing {
54
-
55
-    /**
56
-     * 
57
-     */
58
-    private static final long serialVersionUID = 8606967833704938092L;
59
-
60
-    /**
61
-     * Base Overlay for MapViewDrawing overlays.
62
-     *
63
-     */
64
-    private abstract class MapViewOverlay implements Overlay {
65
-
66
-        // Marker associated.
67
-        protected Layer[] layers;
68
-
69
-        // Current color
70
-        protected Color color;
71
-
72
-        public MapViewOverlay(Layer[] layers, Color color) {
73
-            this.layers = layers;
74
-            for (Layer layer: this.layers) {
75
-                MapViewDrawing.this.getLayerManager().getLayers().add(layer);
76
-            }
77
-            this.color = color;
78
-        }
79
-
80
-        @Override
81
-        public void setColor(Color color) {
82
-            this.color = color;
83
-        }
84
-
85
-        @Override
86
-        public Color getColor() {
87
-            return this.color;
88
-        }
89
-
90
-        @Override
91
-        public void setVisible(boolean visible) {
92
-            for (Layer layer: layers) {
93
-                layer.setVisible(visible);
94
-            }
95
-        }
96
-
97
-        @Override
98
-        public boolean isVisible() {
99
-            if (this.layers.length == 0) {
100
-                return true;
101
-            }
102
-            return this.layers[0].isVisible();
103
-        }
104
-
105
-        @Override
106
-        public void delete() {
107
-            Layers mlayers = MapViewDrawing.this.getLayerManager().getLayers();
108
-            for (Layer layer: layers) {
109
-                mlayers.remove(layer);
110
-            }
111
-        }
112
-
113
-        @Override
114
-        public void redraw() {
115
-            MapViewDrawing.this.getLayerManager().redrawLayers();
116
-        }
117
-    };
118
-
119
-    /**
120
-     * MarkerOverlay for MapViewDrawing.
121
-     *
122
-     */
123
-    private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
124
-
125
-        private final AlphaMode alphaMode;
126
-        private Color innerColor;
127
-
128
-        public MapViewMarkerOverlay(Marker marker, Color outer, Color innerColor,
129
-                AlphaMode alphaMode) {
130
-            super(new Layer[] { marker }, outer);
131
-            this.innerColor = innerColor;
132
-            this.alphaMode = alphaMode;
133
-        }
134
-
135
-        @Override
136
-        public Point getPoint() {
137
-            Marker marker = (Marker) super.layers[0];
138
-            return new Point((float) marker.getLatLong().getLongitude(),
139
-                    (float) marker.getLatLong().getLatitude());
140
-        }
141
-
142
-        @Override
143
-        public void setColor(Color outer) {
144
-            this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
145
-            super.setColor(color);
146
-            MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
147
-            marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
148
-        }
149
-
150
-        @Override
151
-        public void moveTo(Point point) {
152
-            MarkerAutoScaling marker = (MarkerAutoScaling) this.layers[0];
153
-            this.delete();
154
-            marker = new MarkerAutoScaling(convertPoint(point), marker.getImage());
155
-            this.layers[0] = marker;
156
-            MapViewDrawing.this.getLayerManager().getLayers().add(marker);
157
-        }
158
-
159
-    };
160
-
161
-    /**
162
-     * PathOverlay for MapViewDrawing.
163
-     *
164
-     */
165
-    private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay {
166
-
167
-        public MapViewPathOverlay(PolylineAutoScaling path, MarkerAutoScaling origin,
168
-                MarkerAutoScaling destination) {
169
-            super(new Layer[] { path, origin, destination }, path.getColor());
170
-        }
171
-
172
-        public MapViewPathOverlay(PolylineAutoScaling path) {
173
-            super(new Layer[] { path }, path.getColor());
174
-        }
175
-
176
-        @Override
177
-        public void setColor(Color color) {
178
-            super.setColor(color);
179
-            ((PolylineAutoScaling) this.layers[0]).setColor(color);
180
-            ((MarkerAutoScaling) this.layers[1])
181
-                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
182
-            ((MarkerAutoScaling) this.layers[2])
183
-                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
184
-        }
185
-
186
-    }
187
-
188
-    /**
189
-     * PointSetOverlay for MapViewDrawing - Not currently implemented.
190
-     *
191
-     */
192
-    private class MapViewPointSetOverlay extends MapViewOverlay implements PointSetOverlay {
193
-
194
-        public MapViewPointSetOverlay() {
195
-            super(new Layer[0], Color.BLACK);
196
-        }
197
-
198
-        @Override
199
-        public void setWidth(int width) {
200
-        }
201
-
202
-        @Override
203
-        public void setWidthAndColor(int width, Color color) {
204
-            setWidth(width);
205
-            setColor(color);
206
-        }
207
-
208
-        @Override
209
-        public void addPoint(Point point) {
210
-        }
211
-
212
-        @Override
213
-        public void addPoint(Point point, int width) {
214
-            setWidth(width);
215
-            addPoint(point);
216
-        }
217
-
218
-        @Override
219
-        public void addPoint(Point point, Color color) {
220
-            setColor(color);
221
-            addPoint(point);
222
-        }
223
-
224
-        @Override
225
-        public void addPoint(Point point, int width, Color color) {
226
-            setWidth(width);
227
-            setColor(color);
228
-            addPoint(point);
229
-        }
230
-
231
-    };
232
-
233
-    // Default path color.
234
-    public static final Color DEFAULT_PATH_COLOR = new Color(66, 134, 244);
235
-
236
-    // Graphic factory.
237
-    private static final GraphicFactory GRAPHIC_FACTORY = AwtGraphicFactory.INSTANCE;
238
-
239
-    // Default tile size.
240
-    private static final int DEFAULT_TILE_SIZE = 512;
241
-
242
-    // List of listeners.
243
-    private ArrayList<DrawingClickListener> drawingClickListeners = new ArrayList<>();
244
-
245
-    // Tile size
246
-    private int tileSize;
247
-
248
-    // Zoom controls
249
-    private MapZoomControls zoomControls;
250
-
251
-    public MapViewDrawing() {
252
-        super();
253
-        Parameters.NUMBER_OF_THREADS = 2;
254
-        Parameters.SQUARE_FRAME_BUFFER = false;
255
-
256
-        getMapScaleBar().setVisible(true);
257
-        DisplayModel model = getModel().displayModel;
258
-        this.tileSize = DEFAULT_TILE_SIZE;
259
-        model.setFixedTileSize(this.tileSize);
260
-
261
-        this.setZoomLevelMin((byte) 0);
262
-        this.setZoomLevelMax((byte) 20);
263
-
264
-        // Try...
265
-        try {
266
-            this.zoomControls = new MapZoomControls(this, 0, 0, 20);
267
-            this.zoomControls.addZoomInListener(new ActionListener() {
268
-                @Override
269
-                public void actionPerformed(ActionEvent e) {
270
-                    getModel().mapViewPosition.zoomIn();
271
-                }
272
-            });
273
-            this.zoomControls.addZoomOutListener(new ActionListener() {
274
-                @Override
275
-                public void actionPerformed(ActionEvent e) {
276
-                    getModel().mapViewPosition.zoomOut();
277
-                }
278
-            });
279
-        }
280
-        catch (IOException e) {
281
-            e.printStackTrace();
282
-        }
283
-    }
284
-
285
-    /*
286
-     * (non-Javadoc)
287
-     * 
288
-     * @see org.mapsforge.map.awt.view.MapView#paint(java.awt.Graphics)
289
-     */
290
-    @Override
291
-    public void paint(Graphics graphics) {
292
-        super.paint(graphics);
293
-        if (this.zoomControls != null) {
294
-            this.zoomControls.setZoomLevel(this.getModel().mapViewPosition.getZoomLevel());
295
-            this.zoomControls.draw((Graphics2D) graphics,
296
-                    getWidth() - this.zoomControls.getWidth() - 20,
297
-                    this.getHeight() - this.zoomControls.getHeight() - 10, this);
298
-        }
299
-
300
-    }
301
-
302
-    /*
303
-     * (non-Javadoc)
304
-     * 
305
-     * @see org.insa.graphics.drawing.Drawing#clear()
306
-     */
307
-    @Override
308
-    public void clear() {
309
-        getLayerManager().getLayers().clear();
310
-        repaint();
311
-    }
312
-
313
-    /*
314
-     * (non-Javadoc)
315
-     * 
316
-     * @see org.insa.graphics.drawing.Drawing#clearOverlays()
317
-     */
318
-    @Override
319
-    public void clearOverlays() {
320
-        Layers layers = getLayerManager().getLayers();
321
-        for (Layer layer: layers) {
322
-            if (layer instanceof PolylineAutoScaling || layer instanceof MarkerAutoScaling) {
323
-                getLayerManager().getLayers().remove(layer, false);
324
-            }
325
-        }
326
-        repaint();
327
-    }
328
-
329
-    protected LatLong convertPoint(Point point) {
330
-        return new LatLong(point.getLatitude(), point.getLongitude());
331
-    }
332
-
333
-    private TileRendererLayer createTileRendererLayer(TileCache tileCache,
334
-            MapDataStore mapDataStore, MapViewPosition mapViewPosition,
335
-            HillsRenderConfig hillsRenderConfig) {
336
-        TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
337
-                mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
338
-            @Override
339
-            public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY,
340
-                    org.mapsforge.core.model.Point tapXY) {
341
-                if (zoomControls.contains(new java.awt.Point((int) tapXY.x, (int) tapXY.y))) {
342
-                    return false;
343
-                }
344
-                Point pt = new Point((float) tapLatLong.getLongitude(),
345
-                        (float) tapLatLong.getLatitude());
346
-                for (DrawingClickListener listener: MapViewDrawing.this.drawingClickListeners) {
347
-                    listener.mouseClicked(pt);
348
-                }
349
-                return true;
350
-            }
351
-        };
352
-        tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
353
-        return tileRendererLayer;
354
-    }
355
-
356
-    @Override
357
-    public void addDrawingClickListener(DrawingClickListener listener) {
358
-        this.drawingClickListeners.add(listener);
359
-    }
360
-
361
-    @Override
362
-    public void removeDrawingClickListener(DrawingClickListener listener) {
363
-        this.drawingClickListeners.remove(listener);
364
-    }
365
-
366
-    protected MarkerAutoScaling createMarker(Point point, Color outer, Color inner,
367
-            AlphaMode mode) {
368
-        Image image = MarkerUtils.getMarkerForColor(outer, inner, mode);
369
-        return new MarkerAutoScaling(convertPoint(point), image);
370
-    }
371
-
372
-    @Override
373
-    public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
374
-        return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner,
375
-                mode);
376
-    }
377
-
378
-    @Override
379
-    public PointSetOverlay createPointSetOverlay() {
380
-        return new MapViewPointSetOverlay();
381
-    }
382
-
383
-    @Override
384
-    public PointSetOverlay createPointSetOverlay(int width, Color color) {
385
-        PointSetOverlay ps = new MapViewPointSetOverlay();
386
-        ps.setWidthAndColor(width, color);
387
-        return ps;
388
-    }
389
-
390
-    public void drawGraph(File file) {
391
-
392
-        // Tile cache
393
-        TileCache tileCache = AwtUtil.createTileCache(tileSize,
394
-                getModel().frameBufferModel.getOverdrawFactor(), 1024,
395
-                new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
396
-
397
-        // Layers
398
-        Layers layers = getLayerManager().getLayers();
399
-
400
-        MapDataStore mapDataStore = new MapFile(file);
401
-        TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache, mapDataStore,
402
-                getModel().mapViewPosition, null);
403
-        layers.add(tileRendererLayer);
404
-        BoundingBox boundingBox = mapDataStore.boundingBox();
405
-
406
-        final Model model = getModel();
407
-        if (model.mapViewPosition.getZoomLevel() == 0
408
-                || !boundingBox.contains(model.mapViewPosition.getCenter())) {
409
-            byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
410
-                    boundingBox, model.displayModel.getTileSize());
411
-            model.mapViewPosition
412
-                    .setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
413
-            zoomControls.setZoomLevel(zoomLevel);
414
-        }
415
-
416
-    }
417
-
418
-    @Override
419
-    public void drawGraph(Graph graph, GraphPalette palette) {
420
-        throw new RuntimeException("Not implemented, use drawGraph(File).");
421
-    }
422
-
423
-    @Override
424
-    public void drawGraph(Graph graph) {
425
-        throw new RuntimeException("Not implemented, use drawGraph(File).");
426
-    }
427
-
428
-    @Override
429
-    public PathOverlay drawPath(Path path, Color color, boolean markers) {
430
-        PolylineAutoScaling line = new PolylineAutoScaling(1, color);
431
-        ArrayList<Point> points = new ArrayList<>(path.getArcs().size() * 4);
432
-        for (Arc arc: path.getArcs()) {
433
-            points.addAll(arc.getPoints());
434
-        }
435
-        line.addAll(points);
436
-        PathOverlay overlay = null;
437
-        if (markers) {
438
-            MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), color, color,
439
-                    AlphaMode.TRANSPARENT),
440
-                    destination = createMarker(path.getDestination().getPoint(), color, color,
441
-                            AlphaMode.TRANSPARENT);
442
-            overlay = new MapViewPathOverlay(line, origin, destination);
443
-        }
444
-        else {
445
-            overlay = new MapViewPathOverlay(line);
446
-        }
447
-        return overlay;
448
-    }
449
-
450
-    @Override
451
-    public PathOverlay drawPath(Path path, Color color) {
452
-        return drawPath(path, color, true);
453
-    }
454
-
455
-    @Override
456
-    public PathOverlay drawPath(Path path) {
457
-        return drawPath(path, DEFAULT_PATH_COLOR, true);
458
-    }
459
-
460
-    @Override
461
-    public PathOverlay drawPath(Path path, boolean markers) {
462
-        return drawPath(path, DEFAULT_PATH_COLOR, markers);
463
-    }
464
-
465
-}
1
+package org.insa.graphs.gui.drawing.components;
2
+
3
+import java.awt.Color;
4
+import java.awt.Graphics;
5
+import java.awt.Graphics2D;
6
+import java.awt.Image;
7
+import java.awt.event.ActionEvent;
8
+import java.awt.event.ActionListener;
9
+import java.io.File;
10
+import java.io.IOException;
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+import java.util.UUID;
14
+import java.util.stream.Collectors;
15
+
16
+import org.insa.graphs.gui.drawing.Drawing;
17
+import org.insa.graphs.gui.drawing.DrawingClickListener;
18
+import org.insa.graphs.gui.drawing.GraphPalette;
19
+import org.insa.graphs.gui.drawing.overlays.MarkerAutoScaling;
20
+import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
21
+import org.insa.graphs.gui.drawing.overlays.MarkerUtils;
22
+import org.insa.graphs.gui.drawing.overlays.Overlay;
23
+import org.insa.graphs.gui.drawing.overlays.PathOverlay;
24
+import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
25
+import org.insa.graphs.gui.drawing.overlays.PolylineAutoScaling;
26
+import org.insa.graphs.model.Arc;
27
+import org.insa.graphs.model.Graph;
28
+import org.insa.graphs.model.Path;
29
+import org.insa.graphs.model.Point;
30
+import org.mapsforge.core.graphics.GraphicFactory;
31
+import org.mapsforge.core.model.BoundingBox;
32
+import org.mapsforge.core.model.LatLong;
33
+import org.mapsforge.core.model.MapPosition;
34
+import org.mapsforge.core.util.LatLongUtils;
35
+import org.mapsforge.core.util.Parameters;
36
+import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
37
+import org.mapsforge.map.awt.util.AwtUtil;
38
+import org.mapsforge.map.awt.view.MapView;
39
+import org.mapsforge.map.datastore.MapDataStore;
40
+import org.mapsforge.map.layer.Layer;
41
+import org.mapsforge.map.layer.Layers;
42
+import org.mapsforge.map.layer.cache.TileCache;
43
+import org.mapsforge.map.layer.hills.HillsRenderConfig;
44
+import org.mapsforge.map.layer.overlay.Marker;
45
+import org.mapsforge.map.layer.overlay.Polygon;
46
+import org.mapsforge.map.layer.renderer.TileRendererLayer;
47
+import org.mapsforge.map.model.DisplayModel;
48
+import org.mapsforge.map.model.IMapViewPosition;
49
+import org.mapsforge.map.model.Model;
50
+import org.mapsforge.map.reader.MapFile;
51
+import org.mapsforge.map.rendertheme.InternalRenderTheme;
52
+
53
+/**
54
+ *
55
+ */
56
+public class MapViewDrawing extends MapView implements Drawing {
57
+
58
+    /**
59
+     * 
60
+     */
61
+    private static final long serialVersionUID = 8606967833704938092L;
62
+
63
+    /**
64
+     * Base Overlay for MapViewDrawing overlays.
65
+     *
66
+     */
67
+    private abstract class MapViewOverlay implements Overlay {
68
+
69
+        // Marker associated.
70
+        protected Layer[] layers;
71
+
72
+        // Current color
73
+        protected Color color;
74
+
75
+        public MapViewOverlay(Layer[] layers, Color color) {
76
+            this.layers = layers;
77
+            for (Layer layer: this.layers) {
78
+                MapViewDrawing.this.getLayerManager().getLayers().add(layer);
79
+            }
80
+            this.color = color;
81
+        }
82
+
83
+        @Override
84
+        public void setColor(Color color) {
85
+            this.color = color;
86
+        }
87
+
88
+        @Override
89
+        public Color getColor() {
90
+            return this.color;
91
+        }
92
+
93
+        @Override
94
+        public void setVisible(boolean visible) {
95
+            for (Layer layer: layers) {
96
+                layer.setVisible(visible);
97
+            }
98
+        }
99
+
100
+        @Override
101
+        public boolean isVisible() {
102
+            if (this.layers.length == 0) {
103
+                return true;
104
+            }
105
+            return this.layers[0].isVisible();
106
+        }
107
+
108
+        @Override
109
+        public void delete() {
110
+            Layers mlayers = MapViewDrawing.this.getLayerManager().getLayers();
111
+            for (Layer layer: layers) {
112
+                mlayers.remove(layer);
113
+            }
114
+        }
115
+
116
+        @Override
117
+        public void redraw() {
118
+            MapViewDrawing.this.getLayerManager().redrawLayers();
119
+        }
120
+    };
121
+
122
+    /**
123
+     * MarkerOverlay for MapViewDrawing.
124
+     *
125
+     */
126
+    private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
127
+
128
+        private final AlphaMode alphaMode;
129
+        private Color innerColor;
130
+
131
+        public MapViewMarkerOverlay(Marker marker, Color outer, Color innerColor,
132
+                AlphaMode alphaMode) {
133
+            super(new Layer[] { marker }, outer);
134
+            this.innerColor = innerColor;
135
+            this.alphaMode = alphaMode;
136
+        }
137
+
138
+        @Override
139
+        public Point getPoint() {
140
+            Marker marker = (Marker) super.layers[0];
141
+            return new Point((float) marker.getLatLong().getLongitude(),
142
+                    (float) marker.getLatLong().getLatitude());
143
+        }
144
+
145
+        @Override
146
+        public void setColor(Color outer) {
147
+            this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
148
+            super.setColor(color);
149
+            MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
150
+            marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
151
+        }
152
+
153
+        @Override
154
+        public void moveTo(Point point) {
155
+            MarkerAutoScaling marker = (MarkerAutoScaling) this.layers[0];
156
+            this.delete();
157
+            marker = new MarkerAutoScaling(convertPoint(point), marker.getImage());
158
+            this.layers[0] = marker;
159
+            MapViewDrawing.this.getLayerManager().getLayers().add(marker);
160
+        }
161
+
162
+    };
163
+
164
+    /**
165
+     * PathOverlay for MapViewDrawing.
166
+     *
167
+     */
168
+    private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay {
169
+
170
+        public MapViewPathOverlay(PolylineAutoScaling path, MarkerAutoScaling origin,
171
+                MarkerAutoScaling destination) {
172
+            super(new Layer[] { path, origin, destination }, path.getColor());
173
+        }
174
+
175
+        public MapViewPathOverlay(PolylineAutoScaling path) {
176
+            super(new Layer[] { path }, path.getColor());
177
+        }
178
+
179
+        @Override
180
+        public void setColor(Color color) {
181
+            super.setColor(color);
182
+            ((PolylineAutoScaling) this.layers[0]).setColor(color);
183
+            ((MarkerAutoScaling) this.layers[1])
184
+                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
185
+            ((MarkerAutoScaling) this.layers[2])
186
+                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
187
+        }
188
+
189
+    }
190
+
191
+    /**
192
+     * PointSetOverlay for MapViewDrawing - Not currently implemented.
193
+     *
194
+     */
195
+    private class MapViewPointSetOverlay extends MapViewOverlay implements PointSetOverlay {
196
+
197
+        private List<Point> points = new ArrayList<>();
198
+        private final Polygon polygon;
199
+
200
+        private List<Point> convexHull(List<Point> p) {
201
+            if (p.isEmpty()) {
202
+                return new ArrayList<>();
203
+            }
204
+            p.sort((p1, p2) -> Float.compare(p1.getLongitude(), p2.getLongitude()));
205
+            List<Point> h = new ArrayList<>();
206
+
207
+            // lower hull
208
+            for (Point pt: p) {
209
+                while (h.size() >= 2 && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
210
+                    h.remove(h.size() - 1);
211
+                }
212
+                h.add(pt);
213
+            }
214
+
215
+            // upper hull
216
+            int t = h.size() + 1;
217
+            for (int i = p.size() - 1; i >= 0; i--) {
218
+                Point pt = p.get(i);
219
+                while (h.size() >= t && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
220
+                    h.remove(h.size() - 1);
221
+                }
222
+                h.add(pt);
223
+            }
224
+
225
+            h.remove(h.size() - 1);
226
+            return h;
227
+        }
228
+
229
+        // ccw returns true if the three points make a counter-clockwise turn
230
+        private boolean ccw(Point a, Point b, Point c) {
231
+            return ((b.getLongitude() - a.getLongitude())
232
+                    * (c.getLatitude() - a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
233
+                            * (c.getLongitude() - a.getLongitude()));
234
+        }
235
+
236
+        public MapViewPointSetOverlay() {
237
+            super(new Layer[] { new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
238
+                    Color.BLACK);
239
+            polygon = (Polygon) this.layers[0];
240
+        }
241
+
242
+        @Override
243
+        public void setColor(Color color) {
244
+            super.setColor(color);
245
+            polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100, color.getRed(),
246
+                    color.getGreen(), color.getBlue()));
247
+        }
248
+
249
+        @Override
250
+        public void setWidth(int width) {
251
+        }
252
+
253
+        @Override
254
+        public void setWidthAndColor(int width, Color color) {
255
+            setWidth(width);
256
+            setColor(color);
257
+        }
258
+
259
+        @Override
260
+        public void addPoint(Point point) {
261
+            points.add(point);
262
+            this.points = convexHull(points);
263
+            polygon.setPoints(this.points.stream().map(MapViewDrawing.this::convertPoint)
264
+                    .collect(Collectors.toList()));
265
+            polygon.requestRedraw();
266
+        }
267
+
268
+        @Override
269
+        public void addPoint(Point point, int width) {
270
+            setWidth(width);
271
+            addPoint(point);
272
+        }
273
+
274
+        @Override
275
+        public void addPoint(Point point, Color color) {
276
+            setColor(color);
277
+            addPoint(point);
278
+        }
279
+
280
+        @Override
281
+        public void addPoint(Point point, int width, Color color) {
282
+            setWidth(width);
283
+            setColor(color);
284
+            addPoint(point);
285
+        }
286
+
287
+    };
288
+
289
+    // Default path color.
290
+    public static final Color DEFAULT_PATH_COLOR = new Color(66, 134, 244);
291
+
292
+    // Graphic factory.
293
+    private static final GraphicFactory GRAPHIC_FACTORY = AwtGraphicFactory.INSTANCE;
294
+
295
+    // Default tile size.
296
+    private static final int DEFAULT_TILE_SIZE = 512;
297
+
298
+    // List of listeners.
299
+    private ArrayList<DrawingClickListener> drawingClickListeners = new ArrayList<>();
300
+
301
+    // Tile size
302
+    private int tileSize;
303
+
304
+    // Zoom controls
305
+    private MapZoomControls zoomControls;
306
+
307
+    public MapViewDrawing() {
308
+        super();
309
+        Parameters.NUMBER_OF_THREADS = 2;
310
+        Parameters.SQUARE_FRAME_BUFFER = false;
311
+
312
+        getMapScaleBar().setVisible(true);
313
+        DisplayModel model = getModel().displayModel;
314
+        this.tileSize = DEFAULT_TILE_SIZE;
315
+        model.setFixedTileSize(this.tileSize);
316
+
317
+        this.setZoomLevelMin((byte) 0);
318
+        this.setZoomLevelMax((byte) 20);
319
+
320
+        // Try...
321
+        try {
322
+            this.zoomControls = new MapZoomControls(this, 0, 0, 20);
323
+            this.zoomControls.addZoomInListener(new ActionListener() {
324
+                @Override
325
+                public void actionPerformed(ActionEvent e) {
326
+                    getModel().mapViewPosition.zoomIn();
327
+                }
328
+            });
329
+            this.zoomControls.addZoomOutListener(new ActionListener() {
330
+                @Override
331
+                public void actionPerformed(ActionEvent e) {
332
+                    getModel().mapViewPosition.zoomOut();
333
+                }
334
+            });
335
+        }
336
+        catch (IOException e) {
337
+            e.printStackTrace();
338
+        }
339
+    }
340
+
341
+    /*
342
+     * (non-Javadoc)
343
+     * 
344
+     * @see org.mapsforge.map.awt.view.MapView#paint(java.awt.Graphics)
345
+     */
346
+    @Override
347