Merge master.
This commit is contained in:
parent
38efb0ccea
commit
c7d4dc8077
@ -34,6 +34,7 @@ import org.insa.graph.Node;
|
|||||||
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
|
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
|
||||||
import org.insa.graphics.drawing.Drawing;
|
import org.insa.graphics.drawing.Drawing;
|
||||||
import org.insa.graphics.drawing.components.MapViewDrawing;
|
import org.insa.graphics.drawing.components.MapViewDrawing;
|
||||||
|
import org.insa.graphics.utils.ColorUtils;
|
||||||
|
|
||||||
public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||||
|
|
||||||
@ -366,12 +367,10 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
|||||||
* @return A new NodesInputPanel containing inputs for the given names.
|
* @return A new NodesInputPanel containing inputs for the given names.
|
||||||
*/
|
*/
|
||||||
protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
|
protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
|
||||||
final Color[] nodeColors = { new Color(57, 172, 115), new Color(255, 77, 77),
|
|
||||||
new Color(77, 77, 255), new Color(77, 255, 77) };
|
|
||||||
NodesInputPanel panel = new NodesInputPanel();
|
NodesInputPanel panel = new NodesInputPanel();
|
||||||
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
for (int i = 0; i < nodeNames.length; ++i) {
|
for (int i = 0; i < nodeNames.length; ++i) {
|
||||||
panel.addTextField(nodeNames[i] + ": ", nodeColors[i % nodeColors.length]);
|
panel.addTextField(nodeNames[i] + ": ", ColorUtils.getColor(i));
|
||||||
}
|
}
|
||||||
panel.setEnabled(false);
|
panel.setEnabled(false);
|
||||||
return panel;
|
return panel;
|
||||||
|
@ -25,6 +25,7 @@ import org.insa.graph.Graph;
|
|||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
import org.insa.graph.Point;
|
import org.insa.graph.Point;
|
||||||
import org.insa.graphics.drawing.Drawing;
|
import org.insa.graphics.drawing.Drawing;
|
||||||
|
import org.insa.graphics.drawing.Drawing.AlphaMode;
|
||||||
import org.insa.graphics.drawing.DrawingClickListener;
|
import org.insa.graphics.drawing.DrawingClickListener;
|
||||||
import org.insa.graphics.drawing.overlays.MarkerOverlay;
|
import org.insa.graphics.drawing.overlays.MarkerOverlay;
|
||||||
|
|
||||||
@ -247,7 +248,8 @@ public class NodesInputPanel extends JPanel
|
|||||||
MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
|
MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
|
||||||
if (curnode != null) {
|
if (curnode != null) {
|
||||||
if (tracker == null) {
|
if (tracker == null) {
|
||||||
tracker = drawing.drawMarker(curnode.getPoint(), markerColor);
|
tracker = drawing.drawMarker(curnode.getPoint(), markerColor, markerColor,
|
||||||
|
AlphaMode.OPAQUE);
|
||||||
markerTrackers.put(textField, tracker);
|
markerTrackers.put(textField, tracker);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -412,7 +414,7 @@ public class NodesInputPanel extends JPanel
|
|||||||
MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
|
MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
|
||||||
if (tracker != null) {
|
if (tracker != null) {
|
||||||
MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
|
MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
|
||||||
tracker.getColor());
|
tracker.getColor(), tracker.getColor(), AlphaMode.OPAQUE);
|
||||||
markerTrackers.put(input, newMarker);
|
markerTrackers.put(input, newMarker);
|
||||||
newMarker.setVisible(tracker.isVisible());
|
newMarker.setVisible(tracker.isVisible());
|
||||||
tracker.delete();
|
tracker.delete();
|
||||||
|
@ -38,6 +38,7 @@ import org.insa.graph.Path;
|
|||||||
import org.insa.graph.io.BinaryPathWriter;
|
import org.insa.graph.io.BinaryPathWriter;
|
||||||
import org.insa.graphics.drawing.Drawing;
|
import org.insa.graphics.drawing.Drawing;
|
||||||
import org.insa.graphics.drawing.overlays.PathOverlay;
|
import org.insa.graphics.drawing.overlays.PathOverlay;
|
||||||
|
import org.insa.graphics.utils.ColorUtils;
|
||||||
import org.insa.graphics.utils.FileUtils;
|
import org.insa.graphics.utils.FileUtils;
|
||||||
import org.insa.graphics.utils.FileUtils.FolderType;
|
import org.insa.graphics.utils.FileUtils.FolderType;
|
||||||
|
|
||||||
@ -109,14 +110,14 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
|||||||
* @throws IOException If a resource was not found.
|
* @throws IOException If a resource was not found.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public PathPanel(Path path) throws IOException {
|
public PathPanel(Path path, Color color) throws IOException {
|
||||||
super();
|
super();
|
||||||
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
|
||||||
setBorder(BorderFactory.createCompoundBorder(
|
setBorder(BorderFactory.createCompoundBorder(
|
||||||
BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY),
|
BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY),
|
||||||
new EmptyBorder(5, 0, 5, 0)));
|
new EmptyBorder(5, 0, 5, 0)));
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.overlay = drawing.drawPath(this.path);
|
this.overlay = drawing.drawPath(this.path, color);
|
||||||
|
|
||||||
JCheckBox checkbox = new JCheckBox();
|
JCheckBox checkbox = new JCheckBox();
|
||||||
checkbox.setSelected(true);
|
checkbox.setSelected(true);
|
||||||
@ -286,6 +287,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@ -310,7 +312,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
|||||||
|
|
||||||
public void addPath(Path path) {
|
public void addPath(Path path) {
|
||||||
try {
|
try {
|
||||||
this.add(new PathPanel(path));
|
this.add(new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
|
@ -11,6 +11,23 @@ import org.insa.graphics.drawing.overlays.PointSetOverlay;
|
|||||||
|
|
||||||
public interface Drawing {
|
public interface Drawing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available fill mode for the creation of markers, see the documentation of
|
||||||
|
* each value for more details.
|
||||||
|
*/
|
||||||
|
enum AlphaMode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not use the original transparency of the inner part to fill it.
|
||||||
|
*/
|
||||||
|
OPAQUE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the original transparency of the inner part to fill it.
|
||||||
|
*/
|
||||||
|
TRANSPARENT
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a listener to click to this drawing.
|
* Add a listener to click to this drawing.
|
||||||
*
|
*
|
||||||
@ -36,14 +53,17 @@ public interface Drawing {
|
|||||||
public void clearOverlays();
|
public void clearOverlays();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a marker at the given position with the given color.
|
* Draw a marker at the given position using the given colors and according to
|
||||||
|
* the given mode.
|
||||||
*
|
*
|
||||||
* @param point Position of the marker to draw.
|
* @param point Position of the marker to draw.
|
||||||
* @param color Color of the marker to draw.
|
* @param outer Color for the outer part of the marker to draw.
|
||||||
|
* @param inner Color for the inner part of the marker to draw.
|
||||||
|
* @param mode Mode for filling the inner par of the marker.
|
||||||
*
|
*
|
||||||
* @return A MarkerOverlay instance representing the newly drawn marker.
|
* @return A MarkerOverlay instance representing the newly drawn marker.
|
||||||
*/
|
*/
|
||||||
public MarkerOverlay drawMarker(Point point, Color color);
|
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PointSetOverlay that can be used to add overlay points to this
|
* Create a new PointSetOverlay that can be used to add overlay points to this
|
||||||
|
@ -120,11 +120,16 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
// Image to draw
|
// Image to draw
|
||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
public BasicMarkerOverlay(Point point, Color color) {
|
// Inner color and fill mode.
|
||||||
|
private Color innerColor;
|
||||||
|
private final AlphaMode alphaMode;
|
||||||
|
|
||||||
|
public BasicMarkerOverlay(Point point, Color color, Color inner, AlphaMode alphaMode) {
|
||||||
super(color);
|
super(color);
|
||||||
this.point = point;
|
this.point = point;
|
||||||
this.color = color;
|
this.image = MarkerUtils.getMarkerForColor(color, inner, alphaMode);
|
||||||
this.image = MarkerUtils.getMarkerForColor(color);
|
this.innerColor = inner;
|
||||||
|
this.alphaMode = alphaMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -134,8 +139,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColor(Color color) {
|
public void setColor(Color color) {
|
||||||
|
this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
|
||||||
super.setColor(color);
|
super.setColor(color);
|
||||||
this.image = MarkerUtils.getMarkerForColor(color);
|
this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -347,6 +353,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addMouseListener(new MouseAdapter() {
|
this.addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent evt) {
|
public void mouseClicked(MouseEvent evt) {
|
||||||
if (zoomControls.contains(evt.getPoint())) {
|
if (zoomControls.contains(evt.getPoint())) {
|
||||||
@ -363,6 +370,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
listener.mouseClicked(lonlat);
|
listener.mouseClicked(lonlat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,6 +406,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -413,6 +422,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -456,6 +466,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see
|
* @see
|
||||||
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
||||||
* drawing.DrawingClickListener)
|
* drawing.DrawingClickListener)
|
||||||
@ -467,6 +478,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
||||||
* graphics.drawing.DrawingClickListener)
|
* graphics.drawing.DrawingClickListener)
|
||||||
*/
|
*/
|
||||||
@ -475,13 +487,13 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
this.drawingClickListeners.remove(listener);
|
this.drawingClickListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicMarkerOverlay createMarker(Point point, Color color) {
|
public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner, AlphaMode mode) {
|
||||||
return new BasicMarkerOverlay(point, color);
|
return new BasicMarkerOverlay(point, outer, inner, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MarkerOverlay drawMarker(Point point, Color color) {
|
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
|
||||||
BasicMarkerOverlay marker = createMarker(point, color);
|
BasicMarkerOverlay marker = createMarker(point, outer, inner, mode);
|
||||||
synchronized (overlays) {
|
synchronized (overlays) {
|
||||||
this.overlays.add(marker);
|
this.overlays.add(marker);
|
||||||
}
|
}
|
||||||
@ -646,8 +658,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
}
|
}
|
||||||
BasicMarkerOverlay origin = null, destination = null;
|
BasicMarkerOverlay origin = null, destination = null;
|
||||||
if (markers && !path.isEmpty()) {
|
if (markers && !path.isEmpty()) {
|
||||||
origin = createMarker(path.getOrigin().getPoint(), color);
|
origin = createMarker(path.getOrigin().getPoint(), color, color, AlphaMode.TRANSPARENT);
|
||||||
destination = createMarker(path.getDestination().getPoint(), color);
|
destination = createMarker(path.getDestination().getPoint(), color, color,
|
||||||
|
AlphaMode.TRANSPARENT);
|
||||||
}
|
}
|
||||||
BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
|
BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
|
||||||
synchronized (overlays) {
|
synchronized (overlays) {
|
||||||
|
21
src/main/org/insa/graphics/utils/ColorUtils.java
Normal file
21
src/main/org/insa/graphics/utils/ColorUtils.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package org.insa.graphics.utils;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class ColorUtils {
|
||||||
|
|
||||||
|
private static final Color[] COLORS = { // List of available colors
|
||||||
|
new Color(57, 172, 115), // Forest (Green)
|
||||||
|
new Color(246, 67, 63), // Red
|
||||||
|
new Color(110, 56, 172), // Purple
|
||||||
|
new Color(53, 191, 179), // Cyan
|
||||||
|
new Color(219, 136, 48), // Orange / Brown
|
||||||
|
new Color(110, 110, 110), // Gray
|
||||||
|
new Color(56, 104, 172) // Blue
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Color getColor(int i) {
|
||||||
|
return COLORS[i % COLORS.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user