Merge master.

This commit is contained in:
Holt59 2018-03-13 22:58:27 +01:00
parent 38efb0ccea
commit c7d4dc8077
7 changed files with 79 additions and 22 deletions

View File

@ -34,6 +34,7 @@ import org.insa.graph.Node;
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
import org.insa.graphics.drawing.Drawing;
import org.insa.graphics.drawing.components.MapViewDrawing;
import org.insa.graphics.utils.ColorUtils;
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.
*/
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();
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
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);
return panel;

View File

@ -25,6 +25,7 @@ import org.insa.graph.Graph;
import org.insa.graph.Node;
import org.insa.graph.Point;
import org.insa.graphics.drawing.Drawing;
import org.insa.graphics.drawing.Drawing.AlphaMode;
import org.insa.graphics.drawing.DrawingClickListener;
import org.insa.graphics.drawing.overlays.MarkerOverlay;
@ -247,7 +248,8 @@ public class NodesInputPanel extends JPanel
MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
if (curnode != null) {
if (tracker == null) {
tracker = drawing.drawMarker(curnode.getPoint(), markerColor);
tracker = drawing.drawMarker(curnode.getPoint(), markerColor, markerColor,
AlphaMode.OPAQUE);
markerTrackers.put(textField, tracker);
}
else {
@ -412,7 +414,7 @@ public class NodesInputPanel extends JPanel
MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
if (tracker != null) {
MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
tracker.getColor());
tracker.getColor(), tracker.getColor(), AlphaMode.OPAQUE);
markerTrackers.put(input, newMarker);
newMarker.setVisible(tracker.isVisible());
tracker.delete();

View File

@ -38,6 +38,7 @@ import org.insa.graph.Path;
import org.insa.graph.io.BinaryPathWriter;
import org.insa.graphics.drawing.Drawing;
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.FolderType;
@ -109,14 +110,14 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
* @throws IOException If a resource was not found.
*
*/
public PathPanel(Path path) throws IOException {
public PathPanel(Path path, Color color) throws IOException {
super();
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY),
new EmptyBorder(5, 0, 5, 0)));
this.path = path;
this.overlay = drawing.drawPath(this.path);
this.overlay = drawing.drawPath(this.path, color);
JCheckBox checkbox = new JCheckBox();
checkbox.setSelected(true);
@ -286,6 +287,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
@ -310,7 +312,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
public void addPath(Path path) {
try {
this.add(new PathPanel(path));
this.add(new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
this.setVisible(true);
this.revalidate();
this.repaint();

View File

@ -11,6 +11,23 @@ import org.insa.graphics.drawing.overlays.PointSetOverlay;
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.
*
@ -36,14 +53,17 @@ public interface Drawing {
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 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.
*/
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

View File

@ -120,11 +120,16 @@ public class BasicDrawing extends JPanel implements Drawing {
// Image to draw
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);
this.point = point;
this.color = color;
this.image = MarkerUtils.getMarkerForColor(color);
this.image = MarkerUtils.getMarkerForColor(color, inner, alphaMode);
this.innerColor = inner;
this.alphaMode = alphaMode;
}
@Override
@ -134,8 +139,9 @@ public class BasicDrawing extends JPanel implements Drawing {
@Override
public void setColor(Color color) {
this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
super.setColor(color);
this.image = MarkerUtils.getMarkerForColor(color);
this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
}
@Override
@ -347,6 +353,7 @@ public class BasicDrawing extends JPanel implements Drawing {
}
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
if (zoomControls.contains(evt.getPoint())) {
@ -363,6 +370,7 @@ public class BasicDrawing extends JPanel implements Drawing {
listener.mouseClicked(lonlat);
}
}
});
}
@ -398,6 +406,7 @@ public class BasicDrawing extends JPanel implements Drawing {
/*
* (non-Javadoc)
*
* @see org.insa.graphics.drawing.Drawing#clear()
*/
@Override
@ -413,6 +422,7 @@ public class BasicDrawing extends JPanel implements Drawing {
/*
* (non-Javadoc)
*
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
*/
@Override
@ -456,6 +466,7 @@ public class BasicDrawing extends JPanel implements Drawing {
/*
* (non-Javadoc)
*
* @see
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
* drawing.DrawingClickListener)
@ -467,6 +478,7 @@ public class BasicDrawing extends JPanel implements Drawing {
/*
* (non-Javadoc)
*
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
* graphics.drawing.DrawingClickListener)
*/
@ -475,13 +487,13 @@ public class BasicDrawing extends JPanel implements Drawing {
this.drawingClickListeners.remove(listener);
}
public BasicMarkerOverlay createMarker(Point point, Color color) {
return new BasicMarkerOverlay(point, color);
public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner, AlphaMode mode) {
return new BasicMarkerOverlay(point, outer, inner, mode);
}
@Override
public MarkerOverlay drawMarker(Point point, Color color) {
BasicMarkerOverlay marker = createMarker(point, color);
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
BasicMarkerOverlay marker = createMarker(point, outer, inner, mode);
synchronized (overlays) {
this.overlays.add(marker);
}
@ -646,8 +658,9 @@ public class BasicDrawing extends JPanel implements Drawing {
}
BasicMarkerOverlay origin = null, destination = null;
if (markers && !path.isEmpty()) {
origin = createMarker(path.getOrigin().getPoint(), color);
destination = createMarker(path.getDestination().getPoint(), color);
origin = createMarker(path.getOrigin().getPoint(), color, color, AlphaMode.TRANSPARENT);
destination = createMarker(path.getDestination().getPoint(), color, color,
AlphaMode.TRANSPARENT);
}
BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
synchronized (overlays) {

View 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];
}
}