Browse Source

Merge master.

Holt59 6 years ago
parent
commit
c7d4dc8077

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

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

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

34
 import org.insa.graphics.NodesInputPanel.InputChangedEvent;
34
 import org.insa.graphics.NodesInputPanel.InputChangedEvent;
35
 import org.insa.graphics.drawing.Drawing;
35
 import org.insa.graphics.drawing.Drawing;
36
 import org.insa.graphics.drawing.components.MapViewDrawing;
36
 import org.insa.graphics.drawing.components.MapViewDrawing;
37
+import org.insa.graphics.utils.ColorUtils;
37
 
38
 
38
 public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
39
 public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
39
 
40
 
366
      * @return A new NodesInputPanel containing inputs for the given names.
367
      * @return A new NodesInputPanel containing inputs for the given names.
367
      */
368
      */
368
     protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
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
         NodesInputPanel panel = new NodesInputPanel();
370
         NodesInputPanel panel = new NodesInputPanel();
372
         panel.setAlignmentX(Component.LEFT_ALIGNMENT);
371
         panel.setAlignmentX(Component.LEFT_ALIGNMENT);
373
         for (int i = 0; i < nodeNames.length; ++i) {
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
         panel.setEnabled(false);
375
         panel.setEnabled(false);
377
         return panel;
376
         return panel;

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

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

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

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

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

12
 public interface Drawing {
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
      * Add a listener to click to this drawing.
32
      * Add a listener to click to this drawing.
16
      * 
33
      * 
17
      * @param listener DrawingClickListener to add to this Drawing.
34
      * @param listener DrawingClickListener to add to this Drawing.
36
     public void clearOverlays();
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
      * @param point Position of the marker to draw.
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
      * @return A MarkerOverlay instance representing the newly drawn marker.
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
      * Create a new PointSetOverlay that can be used to add overlay points to this
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
         // Image to draw
120
         // Image to draw
121
         private Image image;
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
             super(color);
128
             super(color);
125
             this.point = point;
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
         @Override
135
         @Override
134
 
139
 
135
         @Override
140
         @Override
136
         public void setColor(Color color) {
141
         public void setColor(Color color) {
142
+            this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
137
             super.setColor(color);
143
             super.setColor(color);
138
-            this.image = MarkerUtils.getMarkerForColor(color);
144
+            this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
139
         }
145
         }
140
 
146
 
141
         @Override
147
         @Override
347
         }
353
         }
348
 
354
 
349
         this.addMouseListener(new MouseAdapter() {
355
         this.addMouseListener(new MouseAdapter() {
356
+
350
             @Override
357
             @Override
351
             public void mouseClicked(MouseEvent evt) {
358
             public void mouseClicked(MouseEvent evt) {
352
                 if (zoomControls.contains(evt.getPoint())) {
359
                 if (zoomControls.contains(evt.getPoint())) {
363
                     listener.mouseClicked(lonlat);
370
                     listener.mouseClicked(lonlat);
364
                 }
371
                 }
365
             }
372
             }
373
+
366
         });
374
         });
367
     }
375
     }
368
 
376
 
398
 
406
 
399
     /*
407
     /*
400
      * (non-Javadoc)
408
      * (non-Javadoc)
409
+     * 
401
      * @see org.insa.graphics.drawing.Drawing#clear()
410
      * @see org.insa.graphics.drawing.Drawing#clear()
402
      */
411
      */
403
     @Override
412
     @Override
413
 
422
 
414
     /*
423
     /*
415
      * (non-Javadoc)
424
      * (non-Javadoc)
425
+     * 
416
      * @see org.insa.graphics.drawing.Drawing#clearOverlays()
426
      * @see org.insa.graphics.drawing.Drawing#clearOverlays()
417
      */
427
      */
418
     @Override
428
     @Override
456
 
466
 
457
     /*
467
     /*
458
      * (non-Javadoc)
468
      * (non-Javadoc)
469
+     * 
459
      * @see
470
      * @see
460
      * org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
471
      * org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
461
      * drawing.DrawingClickListener)
472
      * drawing.DrawingClickListener)
467
 
478
 
468
     /*
479
     /*
469
      * (non-Javadoc)
480
      * (non-Javadoc)
481
+     * 
470
      * @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
482
      * @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
471
      * graphics.drawing.DrawingClickListener)
483
      * graphics.drawing.DrawingClickListener)
472
      */
484
      */
475
         this.drawingClickListeners.remove(listener);
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
     @Override
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
         synchronized (overlays) {
497
         synchronized (overlays) {
486
             this.overlays.add(marker);
498
             this.overlays.add(marker);
487
         }
499
         }
646
         }
658
         }
647
         BasicMarkerOverlay origin = null, destination = null;
659
         BasicMarkerOverlay origin = null, destination = null;
648
         if (markers && !path.isEmpty()) {
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
         BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
665
         BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
653
         synchronized (overlays) {
666
         synchronized (overlays) {

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

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