Browse Source

Merge master.

Holt59 6 years ago
parent
commit
c7d4dc8077

+ 1
- 1
src/main/org/insa/algo/AlgorithmFactory.java View File

@@ -83,7 +83,7 @@ public class AlgorithmFactory {
83 83
             Class<?>[] params = c.getParameterTypes();
84 84
             if (params.length == 1 && params[0].isAssignableFrom(data.getClass())) {
85 85
                 c.setAccessible(true);
86
-                constructed = (AbstractAlgorithm<?>) c.newInstance(new Object[]{ data });
86
+                constructed = (AbstractAlgorithm<?>) c.newInstance(new Object[] { data });
87 87
                 break;
88 88
             }
89 89
         }

+ 2
- 3
src/main/org/insa/graphics/AlgorithmPanel.java View File

@@ -34,6 +34,7 @@ import org.insa.graph.Node;
34 34
 import org.insa.graphics.NodesInputPanel.InputChangedEvent;
35 35
 import org.insa.graphics.drawing.Drawing;
36 36
 import org.insa.graphics.drawing.components.MapViewDrawing;
37
+import org.insa.graphics.utils.ColorUtils;
37 38
 
38 39
 public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
39 40
 
@@ -366,12 +367,10 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
366 367
      * @return A new NodesInputPanel containing inputs for the given names.
367 368
      */
368 369
     protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
369
-        final Color[] nodeColors = { new Color(57, 172, 115), new Color(255, 77, 77),
370
-                new Color(77, 77, 255), new Color(77, 255, 77) };
371 370
         NodesInputPanel panel = new NodesInputPanel();
372 371
         panel.setAlignmentX(Component.LEFT_ALIGNMENT);
373 372
         for (int i = 0; i < nodeNames.length; ++i) {
374
-            panel.addTextField(nodeNames[i] + ": ", nodeColors[i % nodeColors.length]);
373
+            panel.addTextField(nodeNames[i] + ": ", ColorUtils.getColor(i));
375 374
         }
376 375
         panel.setEnabled(false);
377 376
         return panel;

+ 4
- 2
src/main/org/insa/graphics/NodesInputPanel.java View File

@@ -25,6 +25,7 @@ import org.insa.graph.Graph;
25 25
 import org.insa.graph.Node;
26 26
 import org.insa.graph.Point;
27 27
 import org.insa.graphics.drawing.Drawing;
28
+import org.insa.graphics.drawing.Drawing.AlphaMode;
28 29
 import org.insa.graphics.drawing.DrawingClickListener;
29 30
 import org.insa.graphics.drawing.overlays.MarkerOverlay;
30 31
 
@@ -247,7 +248,8 @@ public class NodesInputPanel extends JPanel
247 248
                 MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
248 249
                 if (curnode != null) {
249 250
                     if (tracker == null) {
250
-                        tracker = drawing.drawMarker(curnode.getPoint(), markerColor);
251
+                        tracker = drawing.drawMarker(curnode.getPoint(), markerColor, markerColor,
252
+                                AlphaMode.OPAQUE);
251 253
                         markerTrackers.put(textField, tracker);
252 254
                     }
253 255
                     else {
@@ -412,7 +414,7 @@ public class NodesInputPanel extends JPanel
412 414
             MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
413 415
             if (tracker != null) {
414 416
                 MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
415
-                        tracker.getColor());
417
+                        tracker.getColor(), tracker.getColor(), AlphaMode.OPAQUE);
416 418
                 markerTrackers.put(input, newMarker);
417 419
                 newMarker.setVisible(tracker.isVisible());
418 420
                 tracker.delete();

+ 5
- 3
src/main/org/insa/graphics/PathsPanel.java View File

@@ -38,6 +38,7 @@ import org.insa.graph.Path;
38 38
 import org.insa.graph.io.BinaryPathWriter;
39 39
 import org.insa.graphics.drawing.Drawing;
40 40
 import org.insa.graphics.drawing.overlays.PathOverlay;
41
+import org.insa.graphics.utils.ColorUtils;
41 42
 import org.insa.graphics.utils.FileUtils;
42 43
 import org.insa.graphics.utils.FileUtils.FolderType;
43 44
 
@@ -109,14 +110,14 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
109 110
          * @throws IOException If a resource was not found.
110 111
          * 
111 112
          */
112
-        public PathPanel(Path path) throws IOException {
113
+        public PathPanel(Path path, Color color) throws IOException {
113 114
             super();
114 115
             setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
115 116
             setBorder(BorderFactory.createCompoundBorder(
116 117
                     BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY),
117 118
                     new EmptyBorder(5, 0, 5, 0)));
118 119
             this.path = path;
119
-            this.overlay = drawing.drawPath(this.path);
120
+            this.overlay = drawing.drawPath(this.path, color);
120 121
 
121 122
             JCheckBox checkbox = new JCheckBox();
122 123
             checkbox.setSelected(true);
@@ -286,6 +287,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
286 287
 
287 288
         /*
288 289
          * (non-Javadoc)
290
+         * 
289 291
          * @see java.lang.Object#toString()
290 292
          */
291 293
         public String toString() {
@@ -310,7 +312,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
310 312
 
311 313
     public void addPath(Path path) {
312 314
         try {
313
-            this.add(new PathPanel(path));
315
+            this.add(new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
314 316
             this.setVisible(true);
315 317
             this.revalidate();
316 318
             this.repaint();

+ 23
- 3
src/main/org/insa/graphics/drawing/Drawing.java View File

@@ -12,6 +12,23 @@ import org.insa.graphics.drawing.overlays.PointSetOverlay;
12 12
 public interface Drawing {
13 13
 
14 14
     /**
15
+     * Available fill mode for the creation of markers, see the documentation of
16
+     * each value for more details.
17
+     */
18
+    enum AlphaMode {
19
+
20
+        /**
21
+         * Do not use the original transparency of the inner part to fill it.
22
+         */
23
+        OPAQUE,
24
+
25
+        /**
26
+         * Use the original transparency of the inner part to fill it.
27
+         */
28
+        TRANSPARENT
29
+    }
30
+
31
+    /**
15 32
      * Add a listener to click to this drawing.
16 33
      * 
17 34
      * @param listener DrawingClickListener to add to this Drawing.
@@ -36,14 +53,17 @@ public interface Drawing {
36 53
     public void clearOverlays();
37 54
 
38 55
     /**
39
-     * Draw a marker at the given position with the given color.
56
+     * Draw a marker at the given position using the given colors and according to
57
+     * the given mode.
40 58
      * 
41 59
      * @param point Position of the marker to draw.
42
-     * @param color Color of the marker to draw.
60
+     * @param outer Color for the outer part of the marker to draw.
61
+     * @param inner Color for the inner part of the marker to draw.
62
+     * @param mode Mode for filling the inner par of the marker.
43 63
      * 
44 64
      * @return A MarkerOverlay instance representing the newly drawn marker.
45 65
      */
46
-    public MarkerOverlay drawMarker(Point point, Color color);
66
+    public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode);
47 67
 
48 68
     /**
49 69
      * Create a new PointSetOverlay that can be used to add overlay points to this

+ 23
- 10
src/main/org/insa/graphics/drawing/components/BasicDrawing.java View File

@@ -120,11 +120,16 @@ public class BasicDrawing extends JPanel implements Drawing {
120 120
         // Image to draw
121 121
         private Image image;
122 122
 
123
-        public BasicMarkerOverlay(Point point, Color color) {
123
+        // Inner color and fill mode.
124
+        private Color innerColor;
125
+        private final AlphaMode alphaMode;
126
+
127
+        public BasicMarkerOverlay(Point point, Color color, Color inner, AlphaMode alphaMode) {
124 128
             super(color);
125 129
             this.point = point;
126
-            this.color = color;
127
-            this.image = MarkerUtils.getMarkerForColor(color);
130
+            this.image = MarkerUtils.getMarkerForColor(color, inner, alphaMode);
131
+            this.innerColor = inner;
132
+            this.alphaMode = alphaMode;
128 133
         }
129 134
 
130 135
         @Override
@@ -134,8 +139,9 @@ public class BasicDrawing extends JPanel implements Drawing {
134 139
 
135 140
         @Override
136 141
         public void setColor(Color color) {
142
+            this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
137 143
             super.setColor(color);
138
-            this.image = MarkerUtils.getMarkerForColor(color);
144
+            this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
139 145
         }
140 146
 
141 147
         @Override
@@ -347,6 +353,7 @@ public class BasicDrawing extends JPanel implements Drawing {
347 353
         }
348 354
 
349 355
         this.addMouseListener(new MouseAdapter() {
356
+
350 357
             @Override
351 358
             public void mouseClicked(MouseEvent evt) {
352 359
                 if (zoomControls.contains(evt.getPoint())) {
@@ -363,6 +370,7 @@ public class BasicDrawing extends JPanel implements Drawing {
363 370
                     listener.mouseClicked(lonlat);
364 371
                 }
365 372
             }
373
+
366 374
         });
367 375
     }
368 376
 
@@ -398,6 +406,7 @@ public class BasicDrawing extends JPanel implements Drawing {
398 406
 
399 407
     /*
400 408
      * (non-Javadoc)
409
+     * 
401 410
      * @see org.insa.graphics.drawing.Drawing#clear()
402 411
      */
403 412
     @Override
@@ -413,6 +422,7 @@ public class BasicDrawing extends JPanel implements Drawing {
413 422
 
414 423
     /*
415 424
      * (non-Javadoc)
425
+     * 
416 426
      * @see org.insa.graphics.drawing.Drawing#clearOverlays()
417 427
      */
418 428
     @Override
@@ -456,6 +466,7 @@ public class BasicDrawing extends JPanel implements Drawing {
456 466
 
457 467
     /*
458 468
      * (non-Javadoc)
469
+     * 
459 470
      * @see
460 471
      * org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
461 472
      * drawing.DrawingClickListener)
@@ -467,6 +478,7 @@ public class BasicDrawing extends JPanel implements Drawing {
467 478
 
468 479
     /*
469 480
      * (non-Javadoc)
481
+     * 
470 482
      * @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
471 483
      * graphics.drawing.DrawingClickListener)
472 484
      */
@@ -475,13 +487,13 @@ public class BasicDrawing extends JPanel implements Drawing {
475 487
         this.drawingClickListeners.remove(listener);
476 488
     }
477 489
 
478
-    public BasicMarkerOverlay createMarker(Point point, Color color) {
479
-        return new BasicMarkerOverlay(point, color);
490
+    public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner, AlphaMode mode) {
491
+        return new BasicMarkerOverlay(point, outer, inner, mode);
480 492
     }
481 493
 
482 494
     @Override
483
-    public MarkerOverlay drawMarker(Point point, Color color) {
484
-        BasicMarkerOverlay marker = createMarker(point, color);
495
+    public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
496
+        BasicMarkerOverlay marker = createMarker(point, outer, inner, mode);
485 497
         synchronized (overlays) {
486 498
             this.overlays.add(marker);
487 499
         }
@@ -646,8 +658,9 @@ public class BasicDrawing extends JPanel implements Drawing {
646 658
         }
647 659
         BasicMarkerOverlay origin = null, destination = null;
648 660
         if (markers && !path.isEmpty()) {
649
-            origin = createMarker(path.getOrigin().getPoint(), color);
650
-            destination = createMarker(path.getDestination().getPoint(), color);
661
+            origin = createMarker(path.getOrigin().getPoint(), color, color, AlphaMode.TRANSPARENT);
662
+            destination = createMarker(path.getDestination().getPoint(), color, color,
663
+                    AlphaMode.TRANSPARENT);
651 664
         }
652 665
         BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
653 666
         synchronized (overlays) {

+ 21
- 0
src/main/org/insa/graphics/utils/ColorUtils.java View File

@@ -0,0 +1,21 @@
1
+package org.insa.graphics.utils;
2
+
3
+import java.awt.Color;
4
+
5
+public class ColorUtils {
6
+
7
+    private static final Color[] COLORS = { // List of available colors
8
+            new Color(57, 172, 115), // Forest (Green)
9
+            new Color(246, 67, 63), // Red
10
+            new Color(110, 56, 172), // Purple
11
+            new Color(53, 191, 179), // Cyan
12
+            new Color(219, 136, 48), // Orange / Brown
13
+            new Color(110, 110, 110), // Gray
14
+            new Color(56, 104, 172) // Blue
15
+    };
16
+
17
+    public static Color getColor(int i) {
18
+        return COLORS[i % COLORS.length];
19
+    }
20
+
21
+}

Loading…
Cancel
Save