[clean] Apply formatting and add formatter configuration.
This commit is contained in:
committed by
Mikael CAPELLE
parent
2f936d44ec
commit
730cda6426
@@ -34,14 +34,14 @@ import org.insa.graphs.model.Node;
|
||||
public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public class StartActionEvent extends ActionEvent {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4090710269781229078L;
|
||||
|
||||
@@ -57,8 +57,8 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
private final boolean graphicVisualization;
|
||||
private final boolean textualVisualization;
|
||||
|
||||
public StartActionEvent(Class<? extends AbstractAlgorithm<?>> algoClass, List<Node> nodes,
|
||||
ArcInspector arcFilter, boolean graphicVisualization,
|
||||
public StartActionEvent(Class<? extends AbstractAlgorithm<?>> algoClass,
|
||||
List<Node> nodes, ArcInspector arcFilter, boolean graphicVisualization,
|
||||
boolean textualVisualization) {
|
||||
super(AlgorithmPanel.this, START_EVENT_ID, START_EVENT_COMMAND);
|
||||
this.nodes = nodes;
|
||||
@@ -124,19 +124,18 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Create a new AlgorithmPanel with the given parameters.
|
||||
*
|
||||
* @param parent Parent component for this panel. Only use for centering
|
||||
* dialogs.
|
||||
*
|
||||
* @param parent Parent component for this panel. Only use for centering dialogs.
|
||||
* @param baseAlgorithm Base algorithm for this algorithm panel.
|
||||
* @param title Title of the panel.
|
||||
* @param nodeNames Names of the input nodes.
|
||||
* @param enableArcFilterSelection <code>true</code> to enable
|
||||
* {@link ArcInspector} selection.
|
||||
*
|
||||
* @param enableArcFilterSelection <code>true</code> to enable {@link ArcInspector}
|
||||
* selection.
|
||||
* @see ArcInspectorFactory
|
||||
*/
|
||||
public AlgorithmPanel(Component parent, Class<? extends AbstractAlgorithm<?>> baseAlgorithm,
|
||||
String title, String[] nodeNames, boolean enableArcFilterSelection) {
|
||||
public AlgorithmPanel(Component parent,
|
||||
Class<? extends AbstractAlgorithm<?>> baseAlgorithm, String title,
|
||||
String[] nodeNames, boolean enableArcFilterSelection) {
|
||||
super();
|
||||
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||
|
||||
@@ -217,7 +216,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
startAlgoButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (ActionListener lis: startActionListeners) {
|
||||
for (ActionListener lis : startActionListeners) {
|
||||
lis.actionPerformed(new StartActionEvent(
|
||||
AlgorithmFactory.getAlgorithmClass(baseAlgorithm,
|
||||
(String) algoSelect.getSelectedItem()),
|
||||
@@ -278,9 +277,8 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Create the title JLabel for this panel.
|
||||
*
|
||||
*
|
||||
* @param title Title for the label.
|
||||
*
|
||||
* @return A new JLabel containing the given title with proper font.
|
||||
*/
|
||||
protected JLabel createTitleLabel(String title) {
|
||||
@@ -296,18 +294,15 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Create the combo box for the algorithm selection.
|
||||
*
|
||||
* @param baseAlgorithm Base algorithm for which the select box should be
|
||||
* created.
|
||||
*
|
||||
*
|
||||
* @param baseAlgorithm Base algorithm for which the select box should be created.
|
||||
* @return A new JComboBox containing algorithms for the given base algorithm.
|
||||
*
|
||||
* @see AlgorithmFactory
|
||||
*/
|
||||
protected JComboBox<String> createAlgoritmSelectComboBox(
|
||||
Class<? extends AbstractAlgorithm<?>> baseAlgorithm) {
|
||||
JComboBox<String> algoSelect = new JComboBox<>(
|
||||
AlgorithmFactory.getAlgorithmNames(baseAlgorithm).toArray(new String[0]));
|
||||
JComboBox<String> algoSelect = new JComboBox<>(AlgorithmFactory
|
||||
.getAlgorithmNames(baseAlgorithm).toArray(new String[0]));
|
||||
algoSelect.setBackground(Color.WHITE);
|
||||
algoSelect.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
return algoSelect;
|
||||
@@ -316,9 +311,8 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Create a node input panel with the given node input names.
|
||||
*
|
||||
*
|
||||
* @param nodeNames Field names for the inputs to create.
|
||||
*
|
||||
* @return A new NodesInputPanel containing inputs for the given names.
|
||||
*/
|
||||
protected NodesInputPanel createNodesInputPanel(String[] nodeNames) {
|
||||
@@ -332,17 +326,15 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given list of nodes does not contain any <code>null</code>
|
||||
* value.
|
||||
*
|
||||
* Check if the given list of nodes does not contain any <code>null</code> value.
|
||||
*
|
||||
* @param nodes List of {@link Node} to check.
|
||||
*
|
||||
* @return <code>true</code> if the list does not contain any <code>null</code>
|
||||
* value, <code>false</code> otherwise.
|
||||
*/
|
||||
protected boolean allNotNull(List<Node> nodes) {
|
||||
boolean allNotNull = true;
|
||||
for (Node node: nodes) {
|
||||
for (Node node : nodes) {
|
||||
allNotNull = allNotNull && node != null;
|
||||
}
|
||||
return allNotNull;
|
||||
@@ -353,7 +345,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
super.setEnabled(enabled);
|
||||
nodesInputPanel.setEnabled(enabled);
|
||||
solutionPanel.setEnabled(enabled);
|
||||
for (JComponent component: components) {
|
||||
for (JComponent component : components) {
|
||||
component.setEnabled(enabled);
|
||||
}
|
||||
graphicObserverCheckbox.setEnabled(enabled);
|
||||
@@ -363,7 +355,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Add a new start action listener to this class.
|
||||
*
|
||||
*
|
||||
* @param listener Listener to add.
|
||||
*/
|
||||
public void addStartActionListener(ActionListener listener) {
|
||||
@@ -371,11 +363,9 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
|
||||
}
|
||||
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {}
|
||||
|
||||
@Override
|
||||
public void onRedrawRequest() {
|
||||
}
|
||||
public void onRedrawRequest() {}
|
||||
|
||||
}
|
||||
|
@@ -6,18 +6,16 @@ public interface DrawingChangeListener {
|
||||
|
||||
/**
|
||||
* Event fired when a new drawing is loaded.
|
||||
*
|
||||
* @param oldDrawing Old drawing, may be null if no drawing exits prior to this
|
||||
* one.
|
||||
*
|
||||
* @param oldDrawing Old drawing, may be null if no drawing exits prior to this one.
|
||||
* @param newDrawing New drawing.
|
||||
*/
|
||||
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing);
|
||||
|
||||
/**
|
||||
* Event fired when a redraw request is emitted - This is typically emitted
|
||||
* after a onDrawingLoaded event, but not always, and request that elements are
|
||||
* drawn again on the new drawing.
|
||||
*
|
||||
* Event fired when a redraw request is emitted - This is typically emitted after a
|
||||
* onDrawingLoaded event, but not always, and request that elements are drawn again
|
||||
* on the new drawing.
|
||||
*/
|
||||
public void onRedrawRequest();
|
||||
|
||||
|
@@ -6,7 +6,7 @@ public interface GraphChangeListener {
|
||||
|
||||
/**
|
||||
* Event fire when a new graph has been loaded.
|
||||
*
|
||||
*
|
||||
* @param graph The new graph.
|
||||
*/
|
||||
public void newGraphLoaded(Graph graph);
|
||||
|
@@ -19,14 +19,13 @@ import org.insa.graphs.model.io.GraphReaderObserver;
|
||||
/**
|
||||
* One-time use GraphReaderObserver that display progress in three different
|
||||
* JProgressBar.
|
||||
*
|
||||
* @author Mikael
|
||||
*
|
||||
* @author Mikael
|
||||
*/
|
||||
public class GraphReaderProgressBar extends JDialog implements GraphReaderObserver {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class GraphReaderProgressBar extends JDialog implements GraphReaderObserv
|
||||
private final JProgressBar[] progressBars = new JProgressBar[3];
|
||||
|
||||
// Current element read, and modulo.
|
||||
private int[] counters = new int[]{ 0, 0, 0 };
|
||||
private int[] counters = new int[] { 0, 0, 0 };
|
||||
private int[] modulos = new int[3];
|
||||
|
||||
public GraphReaderProgressBar(JFrame owner) {
|
||||
|
@@ -75,17 +75,17 @@ import org.insa.graphs.model.io.MapMismatchException;
|
||||
public class MainWindow extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final String WINDOW_TITLE = "BE Graphes INSA";
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final int THREAD_TIMER_DELAY = 1000; // in milliseconds
|
||||
|
||||
@@ -162,7 +162,8 @@ public class MainWindow extends JFrame {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StartActionEvent evt = (StartActionEvent) e;
|
||||
WeaklyConnectedComponentsData data = new WeaklyConnectedComponentsData(graph);
|
||||
WeaklyConnectedComponentsData data =
|
||||
new WeaklyConnectedComponentsData(graph);
|
||||
|
||||
WeaklyConnectedComponentsAlgorithm wccAlgorithm = null;
|
||||
try {
|
||||
@@ -181,10 +182,12 @@ public class MainWindow extends JFrame {
|
||||
wccPanel.setEnabled(false);
|
||||
|
||||
if (evt.isGraphicVisualizationEnabled()) {
|
||||
wccAlgorithm.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
||||
wccAlgorithm.addObserver(
|
||||
new WeaklyConnectedComponentGraphicObserver(drawing));
|
||||
}
|
||||
if (evt.isTextualVisualizationEnabled()) {
|
||||
wccAlgorithm.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
||||
wccAlgorithm.addObserver(
|
||||
new WeaklyConnectedComponentTextObserver(printStream));
|
||||
}
|
||||
|
||||
// We love Java...
|
||||
@@ -207,8 +210,9 @@ public class MainWindow extends JFrame {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StartActionEvent evt = (StartActionEvent) e;
|
||||
ShortestPathData data = new ShortestPathData(graph, evt.getNodes().get(0),
|
||||
evt.getNodes().get(1), evt.getArcFilter());
|
||||
ShortestPathData data =
|
||||
new ShortestPathData(graph, evt.getNodes().get(0),
|
||||
evt.getNodes().get(1), evt.getArcFilter());
|
||||
|
||||
ShortestPathAlgorithm spAlgorithm = null;
|
||||
try {
|
||||
@@ -254,12 +258,15 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling", new String[] {
|
||||
"Origin Car", "Origin Pedestrian", "Destination Car", "Destination Pedestrian" },
|
||||
cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling",
|
||||
new String[] { "Origin Car", "Origin Pedestrian", "Destination Car",
|
||||
"Destination Pedestrian" },
|
||||
true);
|
||||
|
||||
psPanel = new AlgorithmPanel(this, PackageSwitchAlgorithm.class, "Car-Pooling",
|
||||
new String[] { "Oribin A", "Origin B", "Destination A", "Destination B" }, true);
|
||||
psPanel = new AlgorithmPanel(
|
||||
this, PackageSwitchAlgorithm.class, "Car-Pooling", new String[] {
|
||||
"Oribin A", "Origin B", "Destination A", "Destination B" },
|
||||
true);
|
||||
|
||||
// add algorithm panels
|
||||
algoPanels.add(wccPanel);
|
||||
@@ -271,7 +278,7 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Add click listeners to both drawing.
|
||||
|
||||
for (AlgorithmPanel panel: algoPanels) {
|
||||
for (AlgorithmPanel panel : algoPanels) {
|
||||
this.basicDrawing.addDrawingClickListener(panel.nodesInputPanel);
|
||||
this.mapViewDrawing.addDrawingClickListener(panel.nodesInputPanel);
|
||||
this.graphChangeListeneres.add(panel.nodesInputPanel);
|
||||
@@ -294,10 +301,12 @@ public class MainWindow extends JFrame {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser chooser = FileUtils.createFileChooser(FolderType.Map);
|
||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||
if (chooser.showOpenDialog(
|
||||
MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||
graphFilePath = chooser.getSelectedFile().getAbsolutePath();
|
||||
|
||||
// Note: Don't use a try-resources block since loadGraph is asynchronous.
|
||||
// Note: Don't use a try-resources block since loadGraph is
|
||||
// asynchronous.
|
||||
final DataInputStream stream;
|
||||
try {
|
||||
stream = new DataInputStream(new BufferedInputStream(
|
||||
@@ -329,8 +338,8 @@ public class MainWindow extends JFrame {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
int confirmed = JOptionPane.showConfirmDialog(MainWindow.this,
|
||||
"Are you sure you want to close the application?", "Exit Confirmation",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
"Are you sure you want to close the application?",
|
||||
"Exit Confirmation", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (confirmed == JOptionPane.YES_OPTION) {
|
||||
dispose();
|
||||
@@ -360,7 +369,7 @@ public class MainWindow extends JFrame {
|
||||
rightComponent.add(pathPanel, c);
|
||||
|
||||
c.gridy = 1;
|
||||
for (AlgorithmPanel panel: algoPanels) {
|
||||
for (AlgorithmPanel panel : algoPanels) {
|
||||
panel.setVisible(false);
|
||||
rightComponent.add(panel, c);
|
||||
}
|
||||
@@ -428,19 +437,19 @@ public class MainWindow extends JFrame {
|
||||
* Notify all listeners that a new graph has been loaded.
|
||||
*/
|
||||
private void notifyNewGraphLoaded() {
|
||||
for (GraphChangeListener listener: graphChangeListeneres) {
|
||||
for (GraphChangeListener listener : graphChangeListeneres) {
|
||||
listener.newGraphLoaded(graph);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all listeners that a new drawing has been set up.
|
||||
*
|
||||
*
|
||||
* @param oldDrawing
|
||||
* @param newDrawing
|
||||
*/
|
||||
private void notifyDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
|
||||
for (DrawingChangeListener listener: drawingChangeListeners) {
|
||||
for (DrawingChangeListener listener : drawingChangeListeners) {
|
||||
listener.onDrawingLoaded(oldDrawing, newDrawing);
|
||||
}
|
||||
}
|
||||
@@ -449,7 +458,7 @@ public class MainWindow extends JFrame {
|
||||
* Notify all listeners that a redraw request is emitted.
|
||||
*/
|
||||
private void notifyRedrawRequest() {
|
||||
for (DrawingChangeListener listener: drawingChangeListeners) {
|
||||
for (DrawingChangeListener listener : drawingChangeListeners) {
|
||||
listener.onRedrawRequest();
|
||||
}
|
||||
}
|
||||
@@ -478,8 +487,9 @@ public class MainWindow extends JFrame {
|
||||
// We need to draw MapView, we have to check if the file exists.
|
||||
File mfile = null;
|
||||
if (isMapView) {
|
||||
String mfpath = graphFilePath.substring(0, graphFilePath.lastIndexOf(".map"))
|
||||
+ ".mapfg";
|
||||
String mfpath =
|
||||
graphFilePath.substring(0, graphFilePath.lastIndexOf(".map"))
|
||||
+ ".mapfg";
|
||||
mfile = new File(mfpath);
|
||||
if (!mfile.exists()) {
|
||||
if (JOptionPane.showConfirmDialog(this,
|
||||
@@ -566,7 +576,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private void drawGraph() {
|
||||
drawGraph(null, this.currentPalette);
|
||||
@@ -576,7 +586,8 @@ public class MainWindow extends JFrame {
|
||||
launchThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GraphReaderProgressBar progressBar = new GraphReaderProgressBar(MainWindow.this);
|
||||
GraphReaderProgressBar progressBar =
|
||||
new GraphReaderProgressBar(MainWindow.this);
|
||||
progressBar.setLocationRelativeTo(mainPanel.getLeftComponent());
|
||||
reader.addObserver(progressBar);
|
||||
try {
|
||||
@@ -601,19 +612,20 @@ public class MainWindow extends JFrame {
|
||||
|
||||
String info = graph.getMapId();
|
||||
if (graph.getMapName() != null && !graph.getMapName().isEmpty()) {
|
||||
// The \u200e character is the left-to-right mark, we need to avoid issue with
|
||||
// The \u200e character is the left-to-right mark, we need to avoid
|
||||
// issue with
|
||||
// name that are right-to-left (e.g. arabic names).
|
||||
info += " - " + graph.getMapName() + "\u200e";
|
||||
}
|
||||
info += ", " + graph.size() + " nodes, " + graph.getGraphInformation().getArcCount()
|
||||
+ " arcs.";
|
||||
info += ", " + graph.size() + " nodes, "
|
||||
+ graph.getGraphInformation().getArcCount() + " arcs.";
|
||||
graphInfoPanel.setText(info);
|
||||
|
||||
drawGraph();
|
||||
|
||||
notifyNewGraphLoaded();
|
||||
|
||||
for (JMenuItem item: graphLockItems) {
|
||||
for (JMenuItem item : graphLockItems) {
|
||||
item.setEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -622,12 +634,12 @@ public class MainWindow extends JFrame {
|
||||
|
||||
/**
|
||||
* Show and enable the given AlgorithmPanel (and hide all others).
|
||||
*
|
||||
*
|
||||
* @param algorithmPanel
|
||||
*/
|
||||
private void enableAlgorithmPanel(AlgorithmPanel algorithmPanel) {
|
||||
int dividerLocation = mainPanel.getDividerLocation();
|
||||
for (AlgorithmPanel panel: algoPanels) {
|
||||
for (AlgorithmPanel panel : algoPanels) {
|
||||
panel.setVisible(panel == algorithmPanel);
|
||||
}
|
||||
mainPanel.setDividerLocation(dividerLocation);
|
||||
@@ -637,20 +649,25 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Open Map item...
|
||||
JMenuItem openMapItem = new JMenuItem("Open Map... ", KeyEvent.VK_O);
|
||||
openMapItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
||||
openMapItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
||||
openMapItem.addActionListener(baf.createBlockingAction(openMapActionListener));
|
||||
|
||||
// Open Path item...
|
||||
JMenuItem openPathItem = new JMenuItem("Open Path... ", KeyEvent.VK_P);
|
||||
openPathItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
||||
openPathItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
||||
openPathItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser chooser = FileUtils.createFileChooser(FolderType.PathInput);
|
||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||
try (BinaryPathReader reader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(
|
||||
new FileInputStream(chooser.getSelectedFile()))))){
|
||||
JFileChooser chooser =
|
||||
FileUtils.createFileChooser(FolderType.PathInput);
|
||||
if (chooser.showOpenDialog(
|
||||
MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||
try (BinaryPathReader reader = new BinaryPathReader(
|
||||
new DataInputStream(new BufferedInputStream(
|
||||
new FileInputStream(chooser.getSelectedFile()))))) {
|
||||
Path path = reader.readPath(graph);
|
||||
pathPanel.addPath(path);
|
||||
}
|
||||
@@ -673,7 +690,8 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Close item
|
||||
JMenuItem closeItem = new JMenuItem("Quit", KeyEvent.VK_Q);
|
||||
closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
|
||||
closeItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
|
||||
closeItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -691,7 +709,8 @@ public class MainWindow extends JFrame {
|
||||
|
||||
// Second menu
|
||||
JMenuItem drawGraphItem = new JMenuItem("Redraw", KeyEvent.VK_R);
|
||||
drawGraphItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
|
||||
drawGraphItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
|
||||
drawGraphItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -700,23 +719,26 @@ public class MainWindow extends JFrame {
|
||||
}));
|
||||
graphLockItems.add(drawGraphItem);
|
||||
JMenuItem drawGraphBWItem = new JMenuItem("Redraw (B&W)", KeyEvent.VK_B);
|
||||
drawGraphBWItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.ALT_MASK));
|
||||
drawGraphBWItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drawGraph(BasicDrawing.class, blackAndWhitePalette);
|
||||
}
|
||||
}));
|
||||
drawGraphBWItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.ALT_MASK));
|
||||
drawGraphBWItem
|
||||
.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drawGraph(BasicDrawing.class, blackAndWhitePalette);
|
||||
}
|
||||
}));
|
||||
graphLockItems.add(drawGraphBWItem);
|
||||
JMenuItem drawGraphMapsforgeItem = new JMenuItem("Redraw (Map)", KeyEvent.VK_M);
|
||||
drawGraphMapsforgeItem.setAccelerator(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
||||
drawGraphMapsforgeItem
|
||||
.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
||||
drawGraphMapsforgeItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drawGraph(MapViewDrawing.class);
|
||||
}
|
||||
}));
|
||||
.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drawGraph(MapViewDrawing.class);
|
||||
}
|
||||
}));
|
||||
graphLockItems.add(drawGraphMapsforgeItem);
|
||||
|
||||
JMenu graphMenu = new JMenu("Graph");
|
||||
@@ -782,7 +804,7 @@ public class MainWindow extends JFrame {
|
||||
menuBar.add(graphMenu);
|
||||
menuBar.add(algoMenu);
|
||||
|
||||
for (JMenuItem item: graphLockItems) {
|
||||
for (JMenuItem item : graphLockItems) {
|
||||
item.setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -792,9 +814,9 @@ public class MainWindow extends JFrame {
|
||||
private JPanel createStatusBar() {
|
||||
// create the status bar panel and shove it down the bottom of the frame
|
||||
JPanel statusPanel = new JPanel();
|
||||
statusPanel.setBorder(
|
||||
new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
|
||||
new EmptyBorder(0, 15, 0, 15)));
|
||||
statusPanel.setBorder(new CompoundBorder(
|
||||
BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
|
||||
new EmptyBorder(0, 15, 0, 15)));
|
||||
statusPanel.setPreferredSize(new Dimension(getWidth(), 38));
|
||||
statusPanel.setLayout(new BorderLayout());
|
||||
|
||||
|
@@ -33,16 +33,14 @@ public class NodesInputPanel extends JPanel
|
||||
implements DrawingClickListener, DrawingChangeListener, GraphChangeListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Color DEFAULT_MARKER_COLOR = Color.BLUE;
|
||||
|
||||
/**
|
||||
* Utility class that can be used to find a node from coordinates in a "fast"
|
||||
* way.
|
||||
*
|
||||
* Utility class that can be used to find a node from coordinates in a "fast" way.
|
||||
*/
|
||||
private static class NodeFinder {
|
||||
|
||||
@@ -58,14 +56,13 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
/**
|
||||
* @param point
|
||||
*
|
||||
* @return the closest node to the given point, or null if no node is "close
|
||||
* enough".
|
||||
*/
|
||||
public Node findClosestNode(Point point) {
|
||||
Node minNode = null;
|
||||
double minDis = Double.POSITIVE_INFINITY;
|
||||
for (Node node: graph.getNodes()) {
|
||||
for (Node node : graph.getNodes()) {
|
||||
double dlon = point.getLongitude() - node.getPoint().getLongitude();
|
||||
double dlat = point.getLatitude() - node.getPoint().getLatitude();
|
||||
double dis = dlon * dlon + dlat * dlat; // No need to square
|
||||
@@ -81,12 +78,11 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
/**
|
||||
* Event data send when a node input has changed.
|
||||
*
|
||||
*/
|
||||
public class InputChangedEvent extends ActionEvent {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3440024811352247731L;
|
||||
|
||||
@@ -98,7 +94,8 @@ public class NodesInputPanel extends JPanel
|
||||
List<Node> nodes;
|
||||
|
||||
public InputChangedEvent(List<Node> nodes2) {
|
||||
super(NodesInputPanel.this, ALL_INPUT_FILLED_EVENT_ID, ALL_INPUT_FILLED_EVENT_COMMAND);
|
||||
super(NodesInputPanel.this, ALL_INPUT_FILLED_EVENT_ID,
|
||||
ALL_INPUT_FILLED_EVENT_COMMAND);
|
||||
this.nodes = nodes2;
|
||||
}
|
||||
|
||||
@@ -110,7 +107,8 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
// Node inputs and markers.
|
||||
private final ArrayList<JTextField> nodeInputs = new ArrayList<>();
|
||||
private final Map<JTextField, MarkerOverlay> markerTrackers = new IdentityHashMap<JTextField, MarkerOverlay>();
|
||||
private final Map<JTextField, MarkerOverlay> markerTrackers =
|
||||
new IdentityHashMap<JTextField, MarkerOverlay>();
|
||||
|
||||
// Component that can be enabled/disabled.
|
||||
private ArrayList<JComponent> components = new ArrayList<>();
|
||||
@@ -126,7 +124,6 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
/**
|
||||
* Create a new NodesInputPanel.
|
||||
*
|
||||
*/
|
||||
public NodesInputPanel() {
|
||||
super(new GridBagLayout());
|
||||
@@ -134,12 +131,11 @@ public class NodesInputPanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an InputChanged listener to this panel. This listener will be notified by
|
||||
* a {@link InputChangedEvent} each time an input in this panel change (click,
|
||||
* clear, manual input).
|
||||
*
|
||||
* Add an InputChanged listener to this panel. This listener will be notified by a
|
||||
* {@link InputChangedEvent} each time an input in this panel change (click, clear,
|
||||
* manual input).
|
||||
*
|
||||
* @param listener Listener to add.
|
||||
*
|
||||
* @see InputChangedEvent
|
||||
*/
|
||||
public void addInputChangedListener(ActionListener listener) {
|
||||
@@ -149,7 +145,7 @@ public class NodesInputPanel extends JPanel
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
for (JTextField input: nodeInputs) {
|
||||
for (JTextField input : nodeInputs) {
|
||||
MarkerOverlay marker = markerTrackers.getOrDefault(input, null);
|
||||
if (marker != null) {
|
||||
marker.setVisible(visible && !input.getText().trim().isEmpty());
|
||||
@@ -159,7 +155,7 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
for (JComponent component: components) {
|
||||
for (JComponent component : components) {
|
||||
component.setEnabled(enabled);
|
||||
}
|
||||
super.setEnabled(enabled);
|
||||
@@ -176,7 +172,7 @@ public class NodesInputPanel extends JPanel
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (JTextField field: nodeInputs) {
|
||||
for (JTextField field : nodeInputs) {
|
||||
field.setText("");
|
||||
markerTrackers.put(field, null);
|
||||
}
|
||||
@@ -248,8 +244,8 @@ public class NodesInputPanel extends JPanel
|
||||
MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
|
||||
if (curnode != null) {
|
||||
if (tracker == null) {
|
||||
tracker = drawing.drawMarker(curnode.getPoint(), markerColor, Color.BLACK,
|
||||
AlphaMode.TRANSPARENT);
|
||||
tracker = drawing.drawMarker(curnode.getPoint(), markerColor,
|
||||
Color.BLACK, AlphaMode.TRANSPARENT);
|
||||
markerTrackers.put(textField, tracker);
|
||||
}
|
||||
else {
|
||||
@@ -268,7 +264,7 @@ public class NodesInputPanel extends JPanel
|
||||
List<Node> nodes = getNodeForInputs();
|
||||
|
||||
// Trigger change event.
|
||||
for (ActionListener lis: inputChangeListeners) {
|
||||
for (ActionListener lis : inputChangeListeners) {
|
||||
lis.actionPerformed(new InputChangedEvent(nodes));
|
||||
}
|
||||
}
|
||||
@@ -317,21 +313,21 @@ public class NodesInputPanel extends JPanel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of nodes associated with the input. Some nodes may be null if
|
||||
* their associated input is invalid.
|
||||
* @return List of nodes associated with the input. Some nodes may be null if their
|
||||
* associated input is invalid.
|
||||
*/
|
||||
public List<Node> getNodeForInputs() {
|
||||
List<Node> nodes = new ArrayList<>(nodeInputs.size());
|
||||
for (JTextField input: nodeInputs) {
|
||||
for (JTextField input : nodeInputs) {
|
||||
nodes.add(getNodeForInput(input));
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next input that should be filled by a click, or null if none should
|
||||
* be filled.
|
||||
*
|
||||
* Get the next input that should be filled by a click, or null if none should be
|
||||
* filled.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected JTextField getInputToFill() {
|
||||
@@ -350,7 +346,7 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
/**
|
||||
* Set the next input to fill to the given text field.
|
||||
*
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
protected void setInputToFill(JTextField input) {
|
||||
@@ -410,7 +406,7 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
@Override
|
||||
public void onRedrawRequest() {
|
||||
for (JTextField input: nodeInputs) {
|
||||
for (JTextField input : nodeInputs) {
|
||||
MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
|
||||
if (tracker != null) {
|
||||
MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
|
||||
|
@@ -41,23 +41,23 @@ import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.io.BinaryPathWriter;
|
||||
|
||||
public class PathsPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
|
||||
public class PathsPanel extends JPanel
|
||||
implements DrawingChangeListener, GraphChangeListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private class PathPanel extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Simple icon that represents a unicolor rectangle.
|
||||
*
|
||||
*/
|
||||
protected class ColorIcon implements Icon {
|
||||
|
||||
@@ -103,11 +103,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
/**
|
||||
* Create a new bundle with the given path and create a new overlay
|
||||
* corresponding to the path.
|
||||
*
|
||||
*
|
||||
* @param path Path for this bundle, must not be null.
|
||||
*
|
||||
* @throws IOException If a resource was not found.
|
||||
*
|
||||
*/
|
||||
public PathPanel(Path path, Color color) throws IOException {
|
||||
super();
|
||||
@@ -181,21 +179,24 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
chooser.getSelectionModel().addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
icon.setColor(chooser.getSelectionModel().getSelectedColor());
|
||||
icon.setColor(
|
||||
chooser.getSelectionModel().getSelectedColor());
|
||||
colorButton.repaint();
|
||||
overlay.setColor(chooser.getSelectionModel().getSelectedColor());
|
||||
overlay.setColor(
|
||||
chooser.getSelectionModel().getSelectedColor());
|
||||
overlay.redraw();
|
||||
}
|
||||
});
|
||||
|
||||
JColorChooser.createDialog(getTopLevelAncestor(), "Pick a new color", true,
|
||||
chooser, new ActionListener() {
|
||||
JColorChooser.createDialog(getTopLevelAncestor(),
|
||||
"Pick a new color", true, chooser, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
icon.setColor(chooser.getSelectionModel().getSelectedColor());
|
||||
icon.setColor(chooser.getSelectionModel()
|
||||
.getSelectedColor());
|
||||
colorButton.repaint();
|
||||
overlay.setColor(
|
||||
chooser.getSelectionModel().getSelectedColor());
|
||||
overlay.setColor(chooser.getSelectionModel()
|
||||
.getSelectedColor());
|
||||
overlay.redraw();
|
||||
}
|
||||
}, new ActionListener() {
|
||||
@@ -206,14 +207,14 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
overlay.setColor(originalColor);
|
||||
overlay.redraw();
|
||||
}
|
||||
}).setVisible(true);
|
||||
;
|
||||
}).setVisible(true);;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Image saveImg = ImageIO.read(getClass().getResourceAsStream("/save-icon.png"))
|
||||
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
|
||||
Image saveImg =
|
||||
ImageIO.read(getClass().getResourceAsStream("/save-icon.png"))
|
||||
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
|
||||
JButton saveButton = new JButton(new ImageIcon(saveImg));
|
||||
saveButton.setFocusPainted(false);
|
||||
saveButton.setFocusable(false);
|
||||
@@ -224,16 +225,18 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String filepath = String.format("path_%s_%d_%d.path",
|
||||
path.getGraph().getMapId().toLowerCase().replaceAll("[^a-z0-9_]", ""),
|
||||
path.getGraph().getMapId().toLowerCase()
|
||||
.replaceAll("[^a-z0-9_]", ""),
|
||||
path.getOrigin().getId(), path.getDestination().getId());
|
||||
JFileChooser chooser = FileUtils.createFileChooser(FolderType.PathOutput,
|
||||
filepath);
|
||||
JFileChooser chooser = FileUtils
|
||||
.createFileChooser(FolderType.PathOutput, filepath);
|
||||
|
||||
if (chooser
|
||||
.showSaveDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
|
||||
if (chooser.showSaveDialog(
|
||||
getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
|
||||
File file = chooser.getSelectedFile();
|
||||
try (BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
|
||||
new BufferedOutputStream(new FileOutputStream(file))))) {
|
||||
try (BinaryPathWriter writer = new BinaryPathWriter(
|
||||
new DataOutputStream(new BufferedOutputStream(
|
||||
new FileOutputStream(file))))) {
|
||||
writer.writePath(path);
|
||||
}
|
||||
catch (IOException e1) {
|
||||
@@ -245,8 +248,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
}
|
||||
});
|
||||
|
||||
Image newimg = ImageIO.read(getClass().getResourceAsStream("/delete-icon.png"))
|
||||
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
|
||||
Image newimg =
|
||||
ImageIO.read(getClass().getResourceAsStream("/delete-icon.png"))
|
||||
.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH);
|
||||
JButton deleteButton = new JButton(new ImageIcon(newimg));
|
||||
deleteButton.setFocusPainted(false);
|
||||
deleteButton.setFocusable(false);
|
||||
@@ -273,7 +277,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
|
||||
/**
|
||||
* Re-draw the current overlay (if any) on the new drawing.
|
||||
*
|
||||
*/
|
||||
public void updateOverlay() {
|
||||
PathOverlay oldOverlay = this.overlay;
|
||||
@@ -287,7 +290,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
@@ -312,7 +315,8 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
|
||||
public void addPath(Path path) {
|
||||
try {
|
||||
this.add(new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
|
||||
this.add(
|
||||
new PathPanel(path, ColorUtils.getColor(this.getComponentCount())));
|
||||
this.setVisible(true);
|
||||
this.revalidate();
|
||||
this.repaint();
|
||||
@@ -333,7 +337,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
|
||||
@Override
|
||||
public void newGraphLoaded(Graph graph) {
|
||||
for (Component c: this.getComponents()) {
|
||||
for (Component c : this.getComponents()) {
|
||||
if (c instanceof PathPanel) {
|
||||
((PathPanel) c).overlay.delete();
|
||||
}
|
||||
@@ -351,7 +355,7 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
|
||||
@Override
|
||||
public void onRedrawRequest() {
|
||||
for (Component c: this.getComponents()) {
|
||||
for (Component c : this.getComponents()) {
|
||||
if (c instanceof PathPanel) {
|
||||
((PathPanel) c).updateOverlay();
|
||||
}
|
||||
|
@@ -26,10 +26,11 @@ import org.insa.graphs.gui.drawing.overlays.PathOverlay;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
public class SolutionPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
|
||||
public class SolutionPanel extends JPanel
|
||||
implements DrawingChangeListener, GraphChangeListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -44,9 +45,8 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
/**
|
||||
* Create a new bundle with the given solution and create a new overlay
|
||||
* corresponding to the solution (if the solution is feasible).
|
||||
*
|
||||
*
|
||||
* @param solution Solution for this bundle, must not be null.
|
||||
*
|
||||
*/
|
||||
public SolutionBundle(AbstractSolution solution, boolean createOverlays) {
|
||||
this.solution = solution;
|
||||
@@ -85,7 +85,6 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
|
||||
/**
|
||||
* Re-draw the current overlay (if any) on the new drawing.
|
||||
*
|
||||
*/
|
||||
public void updateOverlays() {
|
||||
if (this.overlays.isEmpty()) {
|
||||
@@ -102,7 +101,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
List<PathOverlay> overlays = new ArrayList<>();
|
||||
if (solution.isFeasible()) {
|
||||
Method[] methods = this.solution.getClass().getDeclaredMethods();
|
||||
for (Method method: methods) {
|
||||
for (Method method : methods) {
|
||||
if (method.getReturnType().equals(Path.class)
|
||||
&& method.getParameterCount() == 0) {
|
||||
try {
|
||||
@@ -122,7 +121,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
@@ -145,7 +144,8 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
public SolutionPanel(Component parent) {
|
||||
super();
|
||||
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.LIGHT_GRAY),
|
||||
setBorder(new CompoundBorder(
|
||||
BorderFactory.createMatteBorder(1, 0, 1, 0, Color.LIGHT_GRAY),
|
||||
new EmptyBorder(10, 0, 10, 0)));
|
||||
|
||||
solutionSelect = new JComboBox<>();
|
||||
@@ -167,7 +167,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (PathOverlay overlay: currentBundle.getOverlays()) {
|
||||
for (PathOverlay overlay : currentBundle.getOverlays()) {
|
||||
if (overlay.isVisible()) {
|
||||
overlay.setVisible(false);
|
||||
clearButton.setText("Show");
|
||||
@@ -193,21 +193,23 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if (currentBundle != null) {
|
||||
for (PathOverlay overlay: currentBundle.getOverlays()) {
|
||||
for (PathOverlay overlay : currentBundle.getOverlays()) {
|
||||
overlay.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
SolutionBundle bundle = (SolutionBundle) solutionSelect.getSelectedItem();
|
||||
SolutionBundle bundle =
|
||||
(SolutionBundle) solutionSelect.getSelectedItem();
|
||||
|
||||
if (bundle != null) {
|
||||
|
||||
updateInformationLabel(bundle);
|
||||
buttonPanel
|
||||
.setVisible(bundle.getSolution().isFeasible() && bundle.hasOverlays());
|
||||
clearButton.setText(bundle.getSolution().isFeasible() ? "Hide" : "Show");
|
||||
buttonPanel.setVisible(
|
||||
bundle.getSolution().isFeasible() && bundle.hasOverlays());
|
||||
clearButton.setText(
|
||||
bundle.getSolution().isFeasible() ? "Hide" : "Show");
|
||||
|
||||
for (PathOverlay overlay: bundle.getOverlays()) {
|
||||
for (PathOverlay overlay : bundle.getOverlays()) {
|
||||
overlay.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -224,10 +226,9 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
|
||||
/**
|
||||
* Add the given solution to the panel.
|
||||
*
|
||||
*
|
||||
* @param solution the solution to add to the panel
|
||||
* @param createOverlays Whether or not overlay should be created for this
|
||||
* solution.
|
||||
* @param createOverlays Whether or not overlay should be created for this solution.
|
||||
*/
|
||||
public void addSolution(AbstractSolution solution, boolean createOverlays) {
|
||||
SolutionBundle bundle = new SolutionBundle(solution, createOverlays);
|
||||
@@ -251,9 +252,10 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
solutionSelect.setSelectedItem(currentBundle);
|
||||
}
|
||||
else {
|
||||
SolutionBundle bundle = (SolutionBundle) this.solutionSelect.getSelectedItem();
|
||||
SolutionBundle bundle =
|
||||
(SolutionBundle) this.solutionSelect.getSelectedItem();
|
||||
if (bundle != null) {
|
||||
for (PathOverlay overlay: bundle.getOverlays()) {
|
||||
for (PathOverlay overlay : bundle.getOverlays()) {
|
||||
overlay.setVisible(false);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +265,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
|
||||
@Override
|
||||
public void newGraphLoaded(Graph graph) {
|
||||
for (int i = 0; i < this.solutionSelect.getItemCount(); ++i) {
|
||||
for (PathOverlay overlay: this.solutionSelect.getItemAt(i).getOverlays()) {
|
||||
for (PathOverlay overlay : this.solutionSelect.getItemAt(i).getOverlays()) {
|
||||
overlay.delete();
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class StreamCapturer extends OutputStream {
|
||||
|
||||
/**
|
||||
* Create a new StreamCapturer without prefix.
|
||||
*
|
||||
*
|
||||
* @param output Output JTextArea to which this stream should print.
|
||||
*/
|
||||
public StreamCapturer(JTextArea output) {
|
||||
|
@@ -17,28 +17,28 @@ public class BasicGraphPalette implements GraphPalette {
|
||||
public Color getColorForArc(Arc arc) {
|
||||
RoadType type = arc.getRoadInformation().getType();
|
||||
switch (type) {
|
||||
case MOTORWAY:
|
||||
return MOTORWAY_COLOR;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
return BIG_ROAD_COLOR;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
case PEDESTRIAN:
|
||||
case CYCLEWAY:
|
||||
case TRACK:
|
||||
return SMALL_ROAD_COLOR;
|
||||
case COASTLINE:
|
||||
return COASTLINE_COLOR;
|
||||
case MOTORWAY:
|
||||
return MOTORWAY_COLOR;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
return BIG_ROAD_COLOR;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
case PEDESTRIAN:
|
||||
case CYCLEWAY:
|
||||
case TRACK:
|
||||
return SMALL_ROAD_COLOR;
|
||||
case COASTLINE:
|
||||
return COASTLINE_COLOR;
|
||||
}
|
||||
|
||||
return Color.BLACK;
|
||||
@@ -49,32 +49,32 @@ public class BasicGraphPalette implements GraphPalette {
|
||||
RoadType type = arc.getRoadInformation().getType();
|
||||
int width = 1;
|
||||
switch (type) {
|
||||
case MOTORWAY:
|
||||
width = 2;
|
||||
break;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
width = 1;
|
||||
break;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
case PEDESTRIAN:
|
||||
case CYCLEWAY:
|
||||
case TRACK:
|
||||
width = 1;
|
||||
break;
|
||||
case COASTLINE:
|
||||
width = 4;
|
||||
break;
|
||||
case MOTORWAY:
|
||||
width = 2;
|
||||
break;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
width = 1;
|
||||
break;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
case PEDESTRIAN:
|
||||
case CYCLEWAY:
|
||||
case TRACK:
|
||||
width = 1;
|
||||
break;
|
||||
case COASTLINE:
|
||||
width = 4;
|
||||
break;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
@@ -7,8 +7,9 @@ import org.insa.graphs.model.Arc;
|
||||
public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
|
||||
|
||||
// Road colors (index
|
||||
private final static Color[] ROAD_COLOR_FROM_WIDTH = { null, new Color(140, 140, 140),
|
||||
new Color(80, 80, 80), new Color(40, 40, 40), new Color(30, 30, 30) };
|
||||
private final static Color[] ROAD_COLOR_FROM_WIDTH =
|
||||
{ null, new Color(140, 140, 140), new Color(80, 80, 80),
|
||||
new Color(40, 40, 40), new Color(30, 30, 30) };
|
||||
|
||||
@Override
|
||||
public Color getColorForArc(Arc arc) {
|
||||
|
@@ -12,8 +12,8 @@ import org.insa.graphs.model.Point;
|
||||
public interface Drawing {
|
||||
|
||||
/**
|
||||
* Available fill mode for the creation of markers, see the documentation of
|
||||
* each value for more details.
|
||||
* Available fill mode for the creation of markers, see the documentation of each
|
||||
* value for more details.
|
||||
*/
|
||||
enum AlphaMode {
|
||||
|
||||
@@ -30,14 +30,14 @@ public interface Drawing {
|
||||
|
||||
/**
|
||||
* Add a listener to click to this drawing.
|
||||
*
|
||||
*
|
||||
* @param listener DrawingClickListener to add to this Drawing.
|
||||
*/
|
||||
public void addDrawingClickListener(DrawingClickListener listener);
|
||||
|
||||
/**
|
||||
* Remove the given listener from the drawing.
|
||||
*
|
||||
*
|
||||
* @param listener DrawingClickListener to remove from this Drawing.
|
||||
*/
|
||||
public void removeDrawingClickListener(DrawingClickListener listener);
|
||||
@@ -53,47 +53,43 @@ public interface Drawing {
|
||||
public void clearOverlays();
|
||||
|
||||
/**
|
||||
* Draw a marker at the given position using the given colors and according to
|
||||
* the given mode.
|
||||
*
|
||||
* 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 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 outer, Color inner, AlphaMode mode);
|
||||
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
|
||||
* drawing.
|
||||
*
|
||||
* PointSetOverlay are heavy memory resources, do not use one for each point!
|
||||
*
|
||||
* drawing. PointSetOverlay are heavy memory resources, do not use one for each
|
||||
* point!
|
||||
*
|
||||
* @return A new PointSetOverlay for this drawing.
|
||||
*/
|
||||
public PointSetOverlay createPointSetOverlay();
|
||||
|
||||
/**
|
||||
* Create a new PointSetOverlay with the given initial width and color that can
|
||||
* be used to add overlay points to this drawing.
|
||||
*
|
||||
* PointSetOverlay are heavy memory resources, do not use one for each point!
|
||||
*
|
||||
* Create a new PointSetOverlay with the given initial width and color that can be
|
||||
* used to add overlay points to this drawing. PointSetOverlay are heavy memory
|
||||
* resources, do not use one for each point!
|
||||
*
|
||||
* @param width Initial width of points in the overlay.
|
||||
* @param color Initial width of points in the overlay.
|
||||
*
|
||||
* @return A new PointSetOverlay for this drawing.
|
||||
*/
|
||||
public PointSetOverlay createPointSetOverlay(int width, Color color);
|
||||
|
||||
/**
|
||||
* Draw the given graph using the given palette.
|
||||
*
|
||||
*
|
||||
* @param graph Graph to draw.
|
||||
* @param palette Palette to use to draw the graph.
|
||||
*
|
||||
* @see BasicGraphPalette
|
||||
* @see BlackAndWhiteGraphPalette
|
||||
*/
|
||||
@@ -101,42 +97,37 @@ public interface Drawing {
|
||||
|
||||
/**
|
||||
* Draw the given graph using a default palette specific to the implementation.
|
||||
*
|
||||
*
|
||||
* @param graph Graph to draw.
|
||||
*/
|
||||
public void drawGraph(Graph graph);
|
||||
|
||||
/**
|
||||
* Draw a path using the given color.
|
||||
*
|
||||
*
|
||||
* @param path Path to draw.
|
||||
* @param color Color of the path to draw.
|
||||
* @param markers true to show origin and destination markers.
|
||||
*
|
||||
* @return A PathOverlay instance representing the newly drawn path.
|
||||
*/
|
||||
public PathOverlay drawPath(Path path, Color color, boolean markers);
|
||||
|
||||
/**
|
||||
* Draw a path with both origin and destination markers using the given color.
|
||||
*
|
||||
*
|
||||
* @param path Path to draw.
|
||||
* @param color Color of the path to draw.
|
||||
*
|
||||
* @return A PathOverlay instance representing the newly drawn path.
|
||||
*
|
||||
* @see Drawing#drawPath(Path, Color, boolean)
|
||||
*/
|
||||
public PathOverlay drawPath(Path path, Color color);
|
||||
|
||||
/**
|
||||
* Draw a path using a default color specific to the implementation
|
||||
*
|
||||
*
|
||||
* @param path Path to draw.
|
||||
* @param markers true to show origin and destination markers.
|
||||
*
|
||||
* @return A PathOverlay instance representing the newly drawn path.
|
||||
*
|
||||
* @see Drawing#drawPath(Path, Color, boolean)
|
||||
*/
|
||||
public PathOverlay drawPath(Path path, boolean markers);
|
||||
@@ -144,12 +135,9 @@ public interface Drawing {
|
||||
/**
|
||||
* Draw a path with both origin and destination markers using a default color
|
||||
* specific to the implementation
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param path Path to draw.
|
||||
*
|
||||
* @return A PathOverlay instance representing the newly drawn path.
|
||||
*
|
||||
* @see Drawing#drawPath(Path, Color, boolean)
|
||||
*/
|
||||
public PathOverlay drawPath(Path path);
|
||||
|
@@ -6,7 +6,7 @@ public interface DrawingClickListener {
|
||||
|
||||
/**
|
||||
* Event triggered when a click is made on the map.
|
||||
*
|
||||
*
|
||||
* @param point Position (on the map) of the mouse click.
|
||||
*/
|
||||
public void mouseClicked(Point point);
|
||||
|
@@ -8,14 +8,12 @@ public interface GraphPalette {
|
||||
|
||||
/**
|
||||
* @param arc Arc for which color should be retrieved.
|
||||
*
|
||||
* @return Color associated with the given arc.
|
||||
*/
|
||||
public Color getColorForArc(Arc arc);
|
||||
|
||||
/**
|
||||
* @param arc Arc for which width should be retrieved.
|
||||
*
|
||||
* @return Width associated with the given arc.
|
||||
*/
|
||||
public int getWidthForArc(Arc arc);
|
||||
|
@@ -28,10 +28,10 @@ public class MercatorProjection implements Projection {
|
||||
/**
|
||||
* Create a new MercatorProjection corresponding to the given BoundingBox and
|
||||
* maxSize.
|
||||
*
|
||||
*
|
||||
* @param boundingBox Box for this projection.
|
||||
* @param maxSize Maximum size of any side (width / height) of the image to
|
||||
* which this projection should draw.
|
||||
* @param maxSize Maximum size of any side (width / height) of the image to which
|
||||
* this projection should draw.
|
||||
*/
|
||||
public MercatorProjection(BoundingBox boundingBox, int maxSize) {
|
||||
// Find minimum/maximum longitude and latitude.
|
||||
@@ -51,9 +51,8 @@ public class MercatorProjection implements Projection {
|
||||
|
||||
/**
|
||||
* Compute the projection (without scaling) of the given latitude.
|
||||
*
|
||||
*
|
||||
* @param latitude Latitude to project.
|
||||
*
|
||||
* @return Projection of the given latitude (without scaling).
|
||||
*/
|
||||
private static double projectY(double latitude) {
|
||||
@@ -62,11 +61,10 @@ public class MercatorProjection implements Projection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the dimension required for drawing a projection of the given box on
|
||||
* an image, ensuring that none of the side of image is greater than maxSize.
|
||||
*
|
||||
* Compute the dimension required for drawing a projection of the given box on an
|
||||
* image, ensuring that none of the side of image is greater than maxSize.
|
||||
*
|
||||
* @param maxSize Maximum side of any side of the image.
|
||||
*
|
||||
* @return Dimension corresponding to the preferred size for the image.
|
||||
*/
|
||||
protected Dimension computeImageSize(int maxSize) {
|
||||
@@ -97,7 +95,8 @@ public class MercatorProjection implements Projection {
|
||||
|
||||
@Override
|
||||
public int longitudeToPixelX(float longitude) {
|
||||
return (int) (width * (longitude - minLongitude) / (maxLongitude - minLongitude));
|
||||
return (int) (width * (longitude - minLongitude)
|
||||
/ (maxLongitude - minLongitude));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -13,10 +13,10 @@ public class PlateCarreProjection implements Projection {
|
||||
/**
|
||||
* Create a new PlateCarreProjection corresponding to the given BoundingBox and
|
||||
* maxSize.
|
||||
*
|
||||
*
|
||||
* @param boundingBox Box for this projection.
|
||||
* @param maxSize Maximum size of any side (width / height) of the image to
|
||||
* which this projection should draw.
|
||||
* @param maxSize Maximum size of any side (width / height) of the image to which
|
||||
* this projection should draw.
|
||||
*/
|
||||
public PlateCarreProjection(BoundingBox boundingBox, int maxSize) {
|
||||
// Find minimum/maximum longitude and latitude.
|
||||
@@ -25,7 +25,8 @@ public class PlateCarreProjection implements Projection {
|
||||
this.minLatitude = boundingBox.getBottomRightPoint().getLatitude();
|
||||
this.maxLatitude = boundingBox.getTopLeftPoint().getLatitude();
|
||||
|
||||
float diffLon = maxLongitude - minLongitude, diffLat = maxLatitude - minLatitude;
|
||||
float diffLon = maxLongitude - minLongitude,
|
||||
diffLat = maxLatitude - minLatitude;
|
||||
|
||||
this.width = diffLon < diffLat ? (int) (maxSize * diffLon / diffLat) : maxSize;
|
||||
this.height = diffLon < diffLat ? maxSize : (int) (maxSize * diffLat / diffLon);
|
||||
|
@@ -14,36 +14,32 @@ public interface Projection {
|
||||
|
||||
/**
|
||||
* Project the given latitude on the image.
|
||||
*
|
||||
*
|
||||
* @param latitude Latitude to project.
|
||||
*
|
||||
* @return Projected position of the latitude on the image.
|
||||
*/
|
||||
public int latitudeToPixelY(float latitude);
|
||||
|
||||
/**
|
||||
* Project the given longitude on the image.
|
||||
*
|
||||
*
|
||||
* @param longitude Longitude to project.
|
||||
*
|
||||
* @return Projected position of the longitude on the image.
|
||||
*/
|
||||
public int longitudeToPixelX(float longitude);
|
||||
|
||||
/**
|
||||
* Retrieve the latitude associated to the given projected point.
|
||||
*
|
||||
*
|
||||
* @param py Projected y-position for which latitude should be retrieved.
|
||||
*
|
||||
* @return The original latitude of the point.
|
||||
*/
|
||||
public float pixelYToLatitude(double py);
|
||||
|
||||
/**
|
||||
* Retrieve the longitude associated to the given projected point.
|
||||
*
|
||||
*
|
||||
* @param px Projected x-position for which longitude should be retrieved.
|
||||
*
|
||||
* @return The original longitude of the point.
|
||||
*/
|
||||
public float pixelXToLongitude(double px);
|
||||
|
@@ -45,7 +45,7 @@ import org.insa.graphs.model.GraphStatistics.BoundingBox;
|
||||
public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 96779785877771827L;
|
||||
|
||||
@@ -125,7 +125,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
private Color innerColor;
|
||||
private final AlphaMode alphaMode;
|
||||
|
||||
public BasicMarkerOverlay(Point point, Color color, Color inner, AlphaMode alphaMode) {
|
||||
public BasicMarkerOverlay(Point point, Color color, Color inner,
|
||||
AlphaMode alphaMode) {
|
||||
super(color);
|
||||
this.point = point;
|
||||
this.image = MarkerUtils.getMarkerForColor(color, inner, alphaMode);
|
||||
@@ -146,7 +147,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
public void setColor(Color color) {
|
||||
this.innerColor = this.innerColor.equals(this.color) ? color : innerColor;
|
||||
super.setColor(color);
|
||||
this.image = MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
|
||||
this.image =
|
||||
MarkerUtils.getMarkerForColor(color, this.innerColor, alphaMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,8 +163,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
int px = projection.longitudeToPixelX(getPoint().getLongitude());
|
||||
int py = projection.latitudeToPixelY(getPoint().getLatitude());
|
||||
|
||||
graphics.drawImage(this.image, px - MARKER_WIDTH / 2, py - MARKER_HEIGHT, MARKER_WIDTH,
|
||||
MARKER_HEIGHT, BasicDrawing.this);
|
||||
graphics.drawImage(this.image, px - MARKER_WIDTH / 2, py - MARKER_HEIGHT,
|
||||
MARKER_WIDTH, MARKER_HEIGHT, BasicDrawing.this);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -175,8 +177,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
// Origin / Destination markers.
|
||||
private BasicMarkerOverlay origin, destination;
|
||||
|
||||
public BasicPathOverlay(List<Point> points, Color color, BasicMarkerOverlay origin,
|
||||
BasicMarkerOverlay destination) {
|
||||
public BasicPathOverlay(List<Point> points, Color color,
|
||||
BasicMarkerOverlay origin, BasicMarkerOverlay destination) {
|
||||
super(color);
|
||||
this.points = points;
|
||||
this.origin = origin;
|
||||
@@ -244,8 +246,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
public BasicPointSetOverlay() {
|
||||
super(Color.BLACK);
|
||||
this.image = new BufferedImage(BasicDrawing.this.width, BasicDrawing.this.height,
|
||||
BufferedImage.TYPE_4BYTE_ABGR);
|
||||
this.image = new BufferedImage(BasicDrawing.this.width,
|
||||
BasicDrawing.this.height, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
this.graphics = image.createGraphics();
|
||||
this.graphics.setBackground(new Color(0, 0, 0, 0));
|
||||
}
|
||||
@@ -307,7 +309,6 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/**
|
||||
* Class encapsulating a set of overlays.
|
||||
*
|
||||
*/
|
||||
private class BasicOverlays {
|
||||
|
||||
@@ -316,8 +317,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
public synchronized void draw(Graphics2D g) {
|
||||
// Clear overlays.
|
||||
for (ArrayList<BasicOverlay> arr: this.overlays) {
|
||||
for (BasicOverlay overlay: arr) {
|
||||
for (ArrayList<BasicOverlay> arr : this.overlays) {
|
||||
for (BasicOverlay overlay : arr) {
|
||||
overlay.draw(g);
|
||||
}
|
||||
}
|
||||
@@ -334,7 +335,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
public void clear(boolean repaint) {
|
||||
// Clear overlays.
|
||||
for (ArrayList<BasicOverlay> arr: this.overlays) {
|
||||
for (ArrayList<BasicOverlay> arr : this.overlays) {
|
||||
arr.clear();
|
||||
}
|
||||
// Repaint if requested.
|
||||
@@ -397,7 +398,6 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/**
|
||||
* Create a new BasicDrawing.
|
||||
*
|
||||
*/
|
||||
public BasicDrawing() {
|
||||
setLayout(null);
|
||||
@@ -440,7 +440,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
catch (NoninvertibleTransformException e) {
|
||||
return;
|
||||
}
|
||||
for (DrawingClickListener listener: drawingClickListeners) {
|
||||
for (DrawingClickListener listener : drawingClickListeners) {
|
||||
listener.mouseClicked(lonlat);
|
||||
}
|
||||
}
|
||||
@@ -476,7 +476,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||
*/
|
||||
@Override
|
||||
@@ -490,7 +490,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||
*/
|
||||
@Override
|
||||
@@ -508,16 +508,14 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
/**
|
||||
* Return the longitude and latitude corresponding to the given position of the
|
||||
* MouseEvent.
|
||||
*
|
||||
*
|
||||
* @param event MouseEvent from which longitude/latitude should be retrieved.
|
||||
*
|
||||
* @return Point representing the projection of the MouseEvent position in the
|
||||
* graph/map.
|
||||
*
|
||||
* @throws NoninvertibleTransformException if the actual transformation is
|
||||
* invalid.
|
||||
* @throws NoninvertibleTransformException if the actual transformation is invalid.
|
||||
*/
|
||||
protected Point getLongitudeLatitude(MouseEvent event) throws NoninvertibleTransformException {
|
||||
protected Point getLongitudeLatitude(MouseEvent event)
|
||||
throws NoninvertibleTransformException {
|
||||
// Get the point using the inverse transform of the Zoom/Pan object, this gives
|
||||
// us
|
||||
// a point within the drawing box (between [0, 0] and [width, height]).
|
||||
@@ -531,9 +529,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
||||
* drawing.DrawingClickListener)
|
||||
*/
|
||||
@Override
|
||||
@@ -543,7 +540,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
||||
* graphics.drawing.DrawingClickListener)
|
||||
*/
|
||||
@@ -552,13 +549,16 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
this.drawingClickListeners.remove(listener);
|
||||
}
|
||||
|
||||
public BasicMarkerOverlay createMarker(Point point, Color outer, Color inner, AlphaMode mode) {
|
||||
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 outer, Color inner, AlphaMode mode) {
|
||||
return (MarkerOverlay) this.overlays.add(createMarker(point, outer, inner, mode));
|
||||
public MarkerOverlay drawMarker(Point point, Color outer, Color inner,
|
||||
AlphaMode mode) {
|
||||
return (MarkerOverlay) this.overlays
|
||||
.add(createMarker(point, outer, inner, mode));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -575,17 +575,18 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/**
|
||||
* Draw the given arc.
|
||||
*
|
||||
*
|
||||
* @param arc Arc to draw.
|
||||
* @param palette Palette to use to retrieve color and width for arc, or null to
|
||||
* use current settings.
|
||||
* @param palette Palette to use to retrieve color and width for arc, or null to use
|
||||
* current settings.
|
||||
*/
|
||||
protected void drawArc(Arc arc, GraphPalette palette, boolean repaint) {
|
||||
List<Point> pts = arc.getPoints();
|
||||
if (!pts.isEmpty()) {
|
||||
if (palette != null) {
|
||||
this.graphGraphics.setColor(palette.getColorForArc(arc));
|
||||
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
|
||||
this.graphGraphics
|
||||
.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
|
||||
}
|
||||
Iterator<Point> it1 = pts.iterator();
|
||||
Point prev = it1.next();
|
||||
@@ -608,7 +609,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
/**
|
||||
* Initialize the drawing for the given graph.
|
||||
*
|
||||
*
|
||||
* @param graph
|
||||
*/
|
||||
protected void initialize(Graph graph) {
|
||||
@@ -633,7 +634,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
// Special projection for non-realistic maps...
|
||||
if (graph.getMapId().startsWith("0x")) {
|
||||
projection = new PlateCarreProjection(extendedBox, MAXIMUM_DRAWING_WIDTH / 4);
|
||||
projection =
|
||||
new PlateCarreProjection(extendedBox, MAXIMUM_DRAWING_WIDTH / 4);
|
||||
}
|
||||
else {
|
||||
projection = new MercatorProjection(extendedBox, MAXIMUM_DRAWING_WIDTH);
|
||||
@@ -679,8 +681,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
this.removeMouseMotionListener(zoomAndPanListener);
|
||||
this.removeMouseWheelListener(zoomAndPanListener);
|
||||
|
||||
for (Node node: graph.getNodes()) {
|
||||
for (Arc arc: node.getSuccessors()) {
|
||||
for (Node node : graph.getNodes()) {
|
||||
for (Arc arc : node.getSuccessors()) {
|
||||
// Draw arcs only if there are one-way arcs or if origin is lower than
|
||||
// destination, avoid drawing two-ways arc twice.
|
||||
if (arc.getRoadInformation().isOneWay()
|
||||
@@ -710,7 +712,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
List<Point> points = new ArrayList<Point>();
|
||||
if (!path.isEmpty()) {
|
||||
points.add(path.getOrigin().getPoint());
|
||||
for (Arc arc: path.getArcs()) {
|
||||
for (Arc arc : path.getArcs()) {
|
||||
Iterator<Point> itPoint = arc.getPoints().iterator();
|
||||
// Discard origin each time
|
||||
itPoint.next();
|
||||
@@ -721,7 +723,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
}
|
||||
BasicMarkerOverlay origin = null, destination = null;
|
||||
if (markers && !path.isEmpty()) {
|
||||
origin = createMarker(path.getOrigin().getPoint(), color, color, AlphaMode.TRANSPARENT);
|
||||
origin = createMarker(path.getOrigin().getPoint(), color, color,
|
||||
AlphaMode.TRANSPARENT);
|
||||
destination = createMarker(path.getDestination().getPoint(), color, color,
|
||||
AlphaMode.TRANSPARENT);
|
||||
}
|
||||
|
@@ -56,13 +56,12 @@ import org.mapsforge.map.rendertheme.InternalRenderTheme;
|
||||
public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8606967833704938092L;
|
||||
|
||||
/**
|
||||
* Base Overlay for MapViewDrawing overlays.
|
||||
*
|
||||
*/
|
||||
private abstract class MapViewOverlay implements Overlay {
|
||||
|
||||
@@ -74,7 +73,7 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
public MapViewOverlay(Layer[] layers, Color color) {
|
||||
this.layers = layers;
|
||||
for (Layer layer: this.layers) {
|
||||
for (Layer layer : this.layers) {
|
||||
MapViewDrawing.this.getLayerManager().getLayers().add(layer);
|
||||
}
|
||||
this.color = color;
|
||||
@@ -92,7 +91,7 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
for (Layer layer: layers) {
|
||||
for (Layer layer : layers) {
|
||||
layer.setVisible(visible);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +107,7 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
@Override
|
||||
public void delete() {
|
||||
Layers mlayers = MapViewDrawing.this.getLayerManager().getLayers();
|
||||
for (Layer layer: layers) {
|
||||
for (Layer layer : layers) {
|
||||
mlayers.remove(layer);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +120,6 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/**
|
||||
* MarkerOverlay for MapViewDrawing.
|
||||
*
|
||||
*/
|
||||
private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
|
||||
|
||||
@@ -144,10 +142,12 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
@Override
|
||||
public void setColor(Color outer) {
|
||||
this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
|
||||
this.innerColor =
|
||||
this.innerColor.equals(this.color) ? outer : this.innerColor;
|
||||
super.setColor(color);
|
||||
MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
|
||||
marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
|
||||
marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor,
|
||||
this.alphaMode));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +163,6 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/**
|
||||
* PathOverlay for MapViewDrawing.
|
||||
*
|
||||
*/
|
||||
private class MapViewPathOverlay extends MapViewOverlay implements PathOverlay {
|
||||
|
||||
@@ -180,19 +179,19 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
public void setColor(Color color) {
|
||||
super.setColor(color);
|
||||
((PolylineAutoScaling) this.layers[0]).setColor(color);
|
||||
((MarkerAutoScaling) this.layers[1])
|
||||
.setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
|
||||
((MarkerAutoScaling) this.layers[2])
|
||||
.setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
|
||||
((MarkerAutoScaling) this.layers[1]).setImage(
|
||||
MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
|
||||
((MarkerAutoScaling) this.layers[2]).setImage(
|
||||
MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* PointSetOverlay for MapViewDrawing - Not currently implemented.
|
||||
*
|
||||
*/
|
||||
private class MapViewPointSetOverlay extends MapViewOverlay implements PointSetOverlay {
|
||||
private class MapViewPointSetOverlay extends MapViewOverlay
|
||||
implements PointSetOverlay {
|
||||
|
||||
private List<Point> points = new ArrayList<>();
|
||||
private final Polygon polygon;
|
||||
@@ -205,8 +204,9 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
List<Point> h = new ArrayList<>();
|
||||
|
||||
// lower hull
|
||||
for (Point pt: p) {
|
||||
while (h.size() >= 2 && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
|
||||
for (Point pt : p) {
|
||||
while (h.size() >= 2
|
||||
&& !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
|
||||
h.remove(h.size() - 1);
|
||||
}
|
||||
h.add(pt);
|
||||
@@ -216,7 +216,8 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
int t = h.size() + 1;
|
||||
for (int i = p.size() - 1; i >= 0; i--) {
|
||||
Point pt = p.get(i);
|
||||
while (h.size() >= t && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
|
||||
while (h.size() >= t
|
||||
&& !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
|
||||
h.remove(h.size() - 1);
|
||||
}
|
||||
h.add(pt);
|
||||
@@ -228,13 +229,14 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
// ccw returns true if the three points make a counter-clockwise turn
|
||||
private boolean ccw(Point a, Point b, Point c) {
|
||||
return ((b.getLongitude() - a.getLongitude())
|
||||
* (c.getLatitude() - a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
|
||||
return ((b.getLongitude() - a.getLongitude()) * (c.getLatitude()
|
||||
- a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
|
||||
* (c.getLongitude() - a.getLongitude()));
|
||||
}
|
||||
|
||||
public MapViewPointSetOverlay() {
|
||||
super(new Layer[] { new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
|
||||
super(new Layer[] {
|
||||
new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
|
||||
Color.BLACK);
|
||||
polygon = (Polygon) this.layers[0];
|
||||
}
|
||||
@@ -242,13 +244,12 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
super.setColor(color);
|
||||
polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100, color.getRed(),
|
||||
color.getGreen(), color.getBlue()));
|
||||
polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100,
|
||||
color.getRed(), color.getGreen(), color.getBlue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
}
|
||||
public void setWidth(int width) {}
|
||||
|
||||
@Override
|
||||
public void setWidthAndColor(int width, Color color) {
|
||||
@@ -260,8 +261,9 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
public void addPoint(Point point) {
|
||||
points.add(point);
|
||||
this.points = convexHull(points);
|
||||
polygon.setPoints(this.points.stream().map(MapViewDrawing.this::convertPoint)
|
||||
.collect(Collectors.toList()));
|
||||
polygon.setPoints(
|
||||
this.points.stream().map(MapViewDrawing.this::convertPoint)
|
||||
.collect(Collectors.toList()));
|
||||
polygon.requestRedraw();
|
||||
}
|
||||
|
||||
@@ -340,14 +342,15 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.mapsforge.map.awt.view.MapView#paint(java.awt.Graphics)
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics graphics) {
|
||||
super.paint(graphics);
|
||||
if (this.zoomControls != null) {
|
||||
this.zoomControls.setZoomLevel(this.getModel().mapViewPosition.getZoomLevel());
|
||||
this.zoomControls
|
||||
.setZoomLevel(this.getModel().mapViewPosition.getZoomLevel());
|
||||
this.zoomControls.draw((Graphics2D) graphics,
|
||||
getWidth() - this.zoomControls.getWidth() - 20,
|
||||
this.getHeight() - this.zoomControls.getHeight() - 10, this);
|
||||
@@ -357,7 +360,7 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||
*/
|
||||
@Override
|
||||
@@ -368,14 +371,15 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||
*/
|
||||
@Override
|
||||
public void clearOverlays() {
|
||||
Layers layers = getLayerManager().getLayers();
|
||||
for (Layer layer: layers) {
|
||||
if (layer instanceof PolylineAutoScaling || layer instanceof MarkerAutoScaling) {
|
||||
for (Layer layer : layers) {
|
||||
if (layer instanceof PolylineAutoScaling
|
||||
|| layer instanceof MarkerAutoScaling) {
|
||||
getLayerManager().getLayers().remove(layer, false);
|
||||
}
|
||||
}
|
||||
@@ -389,22 +393,25 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
private TileRendererLayer createTileRendererLayer(TileCache tileCache,
|
||||
MapDataStore mapDataStore, IMapViewPosition mapViewPosition,
|
||||
HillsRenderConfig hillsRenderConfig) {
|
||||
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
|
||||
mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
@Override
|
||||
public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY,
|
||||
org.mapsforge.core.model.Point tapXY) {
|
||||
if (zoomControls.contains(new java.awt.Point((int) tapXY.x, (int) tapXY.y))) {
|
||||
return false;
|
||||
}
|
||||
Point pt = new Point((float) tapLatLong.getLongitude(),
|
||||
(float) tapLatLong.getLatitude());
|
||||
for (DrawingClickListener listener: MapViewDrawing.this.drawingClickListeners) {
|
||||
listener.mouseClicked(pt);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
TileRendererLayer tileRendererLayer =
|
||||
new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false,
|
||||
true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
@Override
|
||||
public boolean onTap(LatLong tapLatLong,
|
||||
org.mapsforge.core.model.Point layerXY,
|
||||
org.mapsforge.core.model.Point tapXY) {
|
||||
if (zoomControls.contains(
|
||||
new java.awt.Point((int) tapXY.x, (int) tapXY.y))) {
|
||||
return false;
|
||||
}
|
||||
Point pt = new Point((float) tapLatLong.getLongitude(),
|
||||
(float) tapLatLong.getLatitude());
|
||||
for (DrawingClickListener listener : MapViewDrawing.this.drawingClickListeners) {
|
||||
listener.mouseClicked(pt);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
|
||||
return tileRendererLayer;
|
||||
}
|
||||
@@ -426,9 +433,10 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
|
||||
return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner,
|
||||
mode);
|
||||
public MarkerOverlay drawMarker(Point point, Color outer, Color inner,
|
||||
AlphaMode mode) {
|
||||
return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer,
|
||||
inner, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -448,24 +456,26 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
// Tile cache
|
||||
TileCache tileCache = AwtUtil.createTileCache(tileSize,
|
||||
getModel().frameBufferModel.getOverdrawFactor(), 1024,
|
||||
new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
|
||||
new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString()));
|
||||
|
||||
// Layers
|
||||
Layers layers = getLayerManager().getLayers();
|
||||
|
||||
MapDataStore mapDataStore = new MapFile(file);
|
||||
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache, mapDataStore,
|
||||
getModel().mapViewPosition, null);
|
||||
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache,
|
||||
mapDataStore, getModel().mapViewPosition, null);
|
||||
layers.add(tileRendererLayer);
|
||||
BoundingBox boundingBox = mapDataStore.boundingBox();
|
||||
|
||||
final Model model = getModel();
|
||||
if (model.mapViewPosition.getZoomLevel() == 0
|
||||
|| !boundingBox.contains(model.mapViewPosition.getCenter())) {
|
||||
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
|
||||
boundingBox, model.displayModel.getTileSize());
|
||||
model.mapViewPosition
|
||||
.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
byte zoomLevel =
|
||||
LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
|
||||
boundingBox, model.displayModel.getTileSize());
|
||||
model.mapViewPosition.setMapPosition(
|
||||
new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
zoomControls.setZoomLevel(zoomLevel);
|
||||
}
|
||||
|
||||
@@ -485,16 +495,17 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
public PathOverlay drawPath(Path path, Color color, boolean markers) {
|
||||
PolylineAutoScaling line = new PolylineAutoScaling(1, color);
|
||||
ArrayList<Point> points = new ArrayList<>(path.getArcs().size() * 4);
|
||||
for (Arc arc: path.getArcs()) {
|
||||
for (Arc arc : path.getArcs()) {
|
||||
points.addAll(arc.getPoints());
|
||||
}
|
||||
line.addAll(points);
|
||||
PathOverlay overlay = null;
|
||||
if (markers) {
|
||||
MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), color, color,
|
||||
AlphaMode.TRANSPARENT),
|
||||
destination = createMarker(path.getDestination().getPoint(), color, color,
|
||||
AlphaMode.TRANSPARENT);
|
||||
MarkerAutoScaling origin =
|
||||
createMarker(path.getOrigin().getPoint(), color, color,
|
||||
AlphaMode.TRANSPARENT),
|
||||
destination = createMarker(path.getDestination().getPoint(), color,
|
||||
color, AlphaMode.TRANSPARENT);
|
||||
overlay = new MapViewPathOverlay(line, origin, destination);
|
||||
}
|
||||
else {
|
||||
|
@@ -61,8 +61,8 @@ public class MapZoomControls {
|
||||
private final List<ActionListener> zoomInListeners = new ArrayList<>();
|
||||
private final List<ActionListener> zoomOutListeners = new ArrayList<>();
|
||||
|
||||
public MapZoomControls(Component component, final int defaultZoom, final int minZoom,
|
||||
final int maxZoom) throws IOException {
|
||||
public MapZoomControls(Component component, final int defaultZoom,
|
||||
final int minZoom, final int maxZoom) throws IOException {
|
||||
|
||||
zoomIn = ImageIO.read(getClass().getResourceAsStream("/zoomIn.png"))
|
||||
.getScaledInstance(DEFAULT_HEIGHT, DEFAULT_HEIGHT, Image.SCALE_SMOOTH);
|
||||
@@ -76,7 +76,8 @@ public class MapZoomControls {
|
||||
component.addMouseMotionListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if (zoomInRect.contains(e.getPoint()) || zoomOutRect.contains(e.getPoint())) {
|
||||
if (zoomInRect.contains(e.getPoint())
|
||||
|| zoomOutRect.contains(e.getPoint())) {
|
||||
component.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
else {
|
||||
@@ -90,16 +91,17 @@ public class MapZoomControls {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (zoomInRect.contains(e.getPoint()) && currentLevel < maxLevel) {
|
||||
currentLevel += 1;
|
||||
for (ActionListener al: zoomInListeners) {
|
||||
al.actionPerformed(
|
||||
new ActionEvent(this, ZOOM_IN_ACTION_ID, ZOOM_IN_ACTION_NAME));
|
||||
for (ActionListener al : zoomInListeners) {
|
||||
al.actionPerformed(new ActionEvent(this, ZOOM_IN_ACTION_ID,
|
||||
ZOOM_IN_ACTION_NAME));
|
||||
}
|
||||
}
|
||||
else if (zoomOutRect.contains(e.getPoint()) && currentLevel > minLevel) {
|
||||
else if (zoomOutRect.contains(e.getPoint())
|
||||
&& currentLevel > minLevel) {
|
||||
currentLevel -= 1;
|
||||
for (ActionListener al: zoomOutListeners) {
|
||||
al.actionPerformed(
|
||||
new ActionEvent(this, ZOOM_OUT_ACTION_ID, ZOOM_OUT_ACTION_NAME));
|
||||
for (ActionListener al : zoomOutListeners) {
|
||||
al.actionPerformed(new ActionEvent(this, ZOOM_OUT_ACTION_ID,
|
||||
ZOOM_OUT_ACTION_NAME));
|
||||
}
|
||||
}
|
||||
component.repaint();
|
||||
@@ -109,7 +111,7 @@ public class MapZoomControls {
|
||||
|
||||
/**
|
||||
* Add a zoom-in listener.
|
||||
*
|
||||
*
|
||||
* @param listener Zoom-in listener to add to this MapZoomControls instance.
|
||||
*/
|
||||
public void addZoomInListener(ActionListener listener) {
|
||||
@@ -118,7 +120,7 @@ public class MapZoomControls {
|
||||
|
||||
/**
|
||||
* Add a zoom-out listener.
|
||||
*
|
||||
*
|
||||
* @param listener Zoom-out listener to add to this MapZoomControls instance.
|
||||
*/
|
||||
public void addZoomOutListener(ActionListener listener) {
|
||||
@@ -134,7 +136,7 @@ public class MapZoomControls {
|
||||
|
||||
/**
|
||||
* Set the current zoom level without requesting a redraw.
|
||||
*
|
||||
*
|
||||
* @param level Zoom level to set.
|
||||
*/
|
||||
public void setZoomLevel(int level) {
|
||||
@@ -152,24 +154,23 @@ public class MapZoomControls {
|
||||
* @return Width of this "component" when drawn.
|
||||
*/
|
||||
public int getWidth() {
|
||||
return DEFAULT_HEIGHT + 2 + (this.maxLevel - this.minLevel) * DEFAULT_SPACING + 1 + 2
|
||||
+ DEFAULT_HEIGHT;
|
||||
return DEFAULT_HEIGHT + 2 + (this.maxLevel - this.minLevel) * DEFAULT_SPACING
|
||||
+ 1 + 2 + DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is contained inside an element of this zoom controls, useful
|
||||
* to avoid spurious click listeners.
|
||||
*
|
||||
* Check if a point is contained inside an element of this zoom controls, useful to
|
||||
* avoid spurious click listeners.
|
||||
*
|
||||
* @param point Point to check.
|
||||
*
|
||||
* @return true if the given point correspond to an element of this zoom
|
||||
* controls.
|
||||
* @return true if the given point correspond to an element of this zoom controls.
|
||||
*/
|
||||
public boolean contains(Point point) {
|
||||
return zoomInRect.contains(point) || zoomOutRect.contains(point);
|
||||
}
|
||||
|
||||
protected void draw(Graphics2D g, int xoffset, int yoffset, ImageObserver observer) {
|
||||
protected void draw(Graphics2D g, int xoffset, int yoffset,
|
||||
ImageObserver observer) {
|
||||
|
||||
int height = getHeight();
|
||||
|
||||
|
@@ -11,7 +11,8 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class ZoomAndPanListener implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||
public class ZoomAndPanListener
|
||||
implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||
public static final int DEFAULT_MIN_ZOOM_LEVEL = -20;
|
||||
public static final int DEFAULT_MAX_ZOOM_LEVEL = 10;
|
||||
public static final double DEFAULT_ZOOM_MULTIPLICATION_FACTOR = 1.2;
|
||||
@@ -31,8 +32,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
this.targetComponent = targetComponent;
|
||||
}
|
||||
|
||||
public ZoomAndPanListener(Component targetComponent, int minZoomLevel, int maxZoomLevel,
|
||||
double zoomMultiplicationFactor) {
|
||||
public ZoomAndPanListener(Component targetComponent, int minZoomLevel,
|
||||
int maxZoomLevel, double zoomMultiplicationFactor) {
|
||||
this.targetComponent = targetComponent;
|
||||
this.minZoomLevel = minZoomLevel;
|
||||
this.maxZoomLevel = maxZoomLevel;
|
||||
@@ -44,25 +45,20 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
targetComponent.repaint();
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
dragStartScreen = e.getPoint();
|
||||
dragEndScreen = null;
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
moveCamera(e);
|
||||
@@ -97,9 +93,11 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
if (zoomLevel < maxZoomLevel) {
|
||||
zoomLevel++;
|
||||
Point2D p1 = transformPoint(p);
|
||||
coordTransform.scale(zoomMultiplicationFactor, zoomMultiplicationFactor);
|
||||
coordTransform.scale(zoomMultiplicationFactor,
|
||||
zoomMultiplicationFactor);
|
||||
Point2D p2 = transformPoint(p);
|
||||
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
|
||||
coordTransform.translate(p2.getX() - p1.getX(),
|
||||
p2.getY() - p1.getY());
|
||||
targetComponent.repaint();
|
||||
}
|
||||
}
|
||||
@@ -110,7 +108,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
coordTransform.scale(1 / zoomMultiplicationFactor,
|
||||
1 / zoomMultiplicationFactor);
|
||||
Point2D p2 = transformPoint(p);
|
||||
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
|
||||
coordTransform.translate(p2.getX() - p1.getX(),
|
||||
p2.getY() - p1.getY());
|
||||
targetComponent.repaint();
|
||||
}
|
||||
}
|
||||
@@ -120,7 +119,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
}
|
||||
}
|
||||
|
||||
private Point2D.Float transformPoint(Point p1) throws NoninvertibleTransformException {
|
||||
private Point2D.Float transformPoint(Point p1)
|
||||
throws NoninvertibleTransformException {
|
||||
|
||||
AffineTransform inverse = coordTransform.createInverse();
|
||||
|
||||
@@ -139,7 +139,8 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
|
||||
public void zoomIn() {
|
||||
try {
|
||||
Point p = new Point(targetComponent.getWidth() / 2, targetComponent.getHeight() / 2);
|
||||
Point p = new Point(targetComponent.getWidth() / 2,
|
||||
targetComponent.getHeight() / 2);
|
||||
zoomLevel++;
|
||||
Point2D p1 = transformPoint(p);
|
||||
coordTransform.scale(zoomMultiplicationFactor, zoomMultiplicationFactor);
|
||||
@@ -154,10 +155,12 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
|
||||
public void zoomOut() {
|
||||
try {
|
||||
Point p = new Point(targetComponent.getWidth() / 2, targetComponent.getHeight() / 2);
|
||||
Point p = new Point(targetComponent.getWidth() / 2,
|
||||
targetComponent.getHeight() / 2);
|
||||
zoomLevel--;
|
||||
Point2D p1 = transformPoint(p);
|
||||
coordTransform.scale(1 / zoomMultiplicationFactor, 1 / zoomMultiplicationFactor);
|
||||
coordTransform.scale(1 / zoomMultiplicationFactor,
|
||||
1 / zoomMultiplicationFactor);
|
||||
Point2D p2 = transformPoint(p);
|
||||
coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
|
||||
targetComponent.repaint();
|
||||
@@ -174,4 +177,4 @@ public class ZoomAndPanListener implements MouseListener, MouseMotionListener, M
|
||||
public void setCoordTransform(AffineTransform coordTransform) {
|
||||
this.coordTransform = coordTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,12 +12,10 @@ import org.mapsforge.map.awt.graphics.AwtBitmap;
|
||||
import org.mapsforge.map.layer.overlay.Marker;
|
||||
|
||||
/**
|
||||
* Class extending the default Mapsforge's {@link Marker} with auto-scaling.
|
||||
*
|
||||
* Mapsforge's Markers do not scale with zoom level, this class aims at
|
||||
* correcting this. Internally, this image stores an {@link Image} instance and
|
||||
* scale it when a redraw is requested.
|
||||
*
|
||||
* Class extending the default Mapsforge's {@link Marker} with auto-scaling. Mapsforge's
|
||||
* Markers do not scale with zoom level, this class aims at correcting this. Internally,
|
||||
* this image stores an {@link Image} instance and scale it when a redraw is requested.
|
||||
*
|
||||
* @see MarkerUtils#getMarkerForColor(java.awt.Color, java.awt.Color,
|
||||
* org.insa.graphics.drawing.Drawing.AlphaMode)
|
||||
* @see PaintUtils#getStrokeWidth(int, byte)
|
||||
@@ -29,7 +27,7 @@ public class MarkerAutoScaling extends Marker {
|
||||
|
||||
/**
|
||||
* Create a new MarkerAutoScaling at the given position with the given image.
|
||||
*
|
||||
*
|
||||
* @param latLong Initial position of the marker.
|
||||
* @param image Image for this marker.
|
||||
*/
|
||||
@@ -40,7 +38,7 @@ public class MarkerAutoScaling extends Marker {
|
||||
|
||||
/**
|
||||
* Set a new image for this marker overlay
|
||||
*
|
||||
*
|
||||
* @param image New image to set.
|
||||
*/
|
||||
public void setImage(Image image) {
|
||||
@@ -55,15 +53,15 @@ public class MarkerAutoScaling extends Marker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
|
||||
Point topLeftPoint) {
|
||||
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel,
|
||||
Canvas canvas, Point topLeftPoint) {
|
||||
int width = (int) PaintUtils.getStrokeWidth(8, zoomLevel),
|
||||
height = (int) PaintUtils.getStrokeWidth(16, zoomLevel);
|
||||
BufferedImage bfd = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
BufferedImage bfd =
|
||||
new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g = bfd.createGraphics();
|
||||
g.drawImage(
|
||||
this.image.getScaledInstance(bfd.getWidth(), bfd.getHeight(), Image.SCALE_SMOOTH),
|
||||
0, 0, null);
|
||||
g.drawImage(this.image.getScaledInstance(bfd.getWidth(), bfd.getHeight(),
|
||||
Image.SCALE_SMOOTH), 0, 0, null);
|
||||
setBitmap(new AwtBitmap(bfd));
|
||||
|
||||
setVerticalOffset(-height / 2);
|
||||
|
@@ -11,7 +11,7 @@ public interface MarkerOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Move this marker to the specified location.
|
||||
*
|
||||
*
|
||||
* @param point New position for the marker.
|
||||
*/
|
||||
public void moveTo(Point point);
|
||||
|
@@ -12,11 +12,10 @@ public class MarkerUtils {
|
||||
/**
|
||||
* Create an image to represent a marker using the given color for the outer and
|
||||
* inner part, and the given mode for the inner part.
|
||||
*
|
||||
*
|
||||
* @param outer Outer color of the marker.
|
||||
* @param inner Inner color of the marker.
|
||||
* @param mode Mode to use to fill the inner part of the marker.
|
||||
*
|
||||
* @return An image representing a marker.
|
||||
*/
|
||||
public static Image getMarkerForColor(Color outer, Color inner, AlphaMode mode) {
|
||||
@@ -31,23 +30,28 @@ public class MarkerUtils {
|
||||
for (int j = 0; j < image.getWidth(); ++j) {
|
||||
|
||||
// If we are in the "inner" part of the marker...
|
||||
if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER && j < MAX_X_CENTER
|
||||
&& mask[i][j] != MAXIMUM_INNER_MASK_VALUE) {
|
||||
if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER
|
||||
&& j < MAX_X_CENTER && mask[i][j] != MAXIMUM_INNER_MASK_VALUE) {
|
||||
// Don't ask... https://stackoverflow.com/a/29321264/2666289
|
||||
// Basically, this compute a "middle" color between outer and inner depending on
|
||||
// Basically, this compute a "middle" color between outer and inner
|
||||
// depending on
|
||||
// the current mask value.
|
||||
double t = 1 - (mask[i][j] - MINIMUM_INNER_MASK_VALUE)
|
||||
/ (double) (MAXIMUM_INNER_MASK_VALUE - MINIMUM_INNER_MASK_VALUE);
|
||||
/ (double) (MAXIMUM_INNER_MASK_VALUE
|
||||
- MINIMUM_INNER_MASK_VALUE);
|
||||
int r = (int) Math.sqrt((1 - t) * outer.getRed() * outer.getRed()
|
||||
+ t * inner.getRed() * inner.getRed());
|
||||
int g = (int) Math.sqrt((1 - t) * outer.getGreen() * outer.getGreen()
|
||||
+ t * inner.getGreen() * inner.getGreen());
|
||||
int g = (int) Math
|
||||
.sqrt((1 - t) * outer.getGreen() * outer.getGreen()
|
||||
+ t * inner.getGreen() * inner.getGreen());
|
||||
int b = (int) Math.sqrt((1 - t) * outer.getBlue() * outer.getBlue()
|
||||
+ t * inner.getBlue() * inner.getBlue());
|
||||
int a = mode == AlphaMode.OPAQUE ? MAXIMUM_INNER_MASK_VALUE : mask[i][j];
|
||||
int a = mode == AlphaMode.OPAQUE ? MAXIMUM_INNER_MASK_VALUE
|
||||
: mask[i][j];
|
||||
image.setRGB(j, i, (a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
// Otherwize, just fill with the outer color and set the alpha value properly.
|
||||
// Otherwize, just fill with the outer color and set the alpha value
|
||||
// properly.
|
||||
else {
|
||||
image.setRGB(j, i, outerRGB | (mask[i][j] << 24));
|
||||
}
|
||||
@@ -64,7 +68,8 @@ public class MarkerUtils {
|
||||
// with a different color.
|
||||
private static final int MIN_X_CENTER = 40, MAX_X_CENTER = 101, MIN_Y_CENTER = 40,
|
||||
MAX_Y_CENTER = 100;
|
||||
private static final int MINIMUM_INNER_MASK_VALUE = 116, MAXIMUM_INNER_MASK_VALUE = 249;
|
||||
private static final int MINIMUM_INNER_MASK_VALUE = 116,
|
||||
MAXIMUM_INNER_MASK_VALUE = 249;
|
||||
|
||||
/**
|
||||
* @return Retrieve the mask from the mask file or from the cache.
|
||||
|
@@ -6,7 +6,7 @@ public interface Overlay {
|
||||
|
||||
/**
|
||||
* Set the color of this overlay.
|
||||
*
|
||||
*
|
||||
* @param color New color for the overlay.
|
||||
*/
|
||||
public void setColor(Color color);
|
||||
@@ -18,7 +18,7 @@ public interface Overlay {
|
||||
|
||||
/**
|
||||
* Show or hide this marker - A marker should be visible when created.
|
||||
*
|
||||
*
|
||||
* @param visible true to show the marker, false to hide.
|
||||
*/
|
||||
public void setVisible(boolean visible);
|
||||
|
@@ -14,21 +14,19 @@ public class PaintUtils {
|
||||
|
||||
/**
|
||||
* Convert the given AWT color to a mapsforge compatible color.
|
||||
*
|
||||
*
|
||||
* @param color AWT color to convert.
|
||||
*
|
||||
* @return Integer value representing a corresponding mapsforge color.
|
||||
*/
|
||||
public static int convertColor(Color color) {
|
||||
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(),
|
||||
color.getBlue());
|
||||
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(),
|
||||
color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given mapsforge color to an AWT Color.
|
||||
*
|
||||
*
|
||||
* @param color Integer value representing a mapsforge color.
|
||||
*
|
||||
* @return AWT color corresponding to the given value.
|
||||
*/
|
||||
public static Color convertColor(int color) {
|
||||
@@ -37,12 +35,11 @@ public class PaintUtils {
|
||||
|
||||
/**
|
||||
* Compute an updated value for the given width at the given zoom level. This
|
||||
* function can be used to automatically scale {@link Polyline} or
|
||||
* {@link Marker} when zooming (which is not done by default in Mapsforge).
|
||||
*
|
||||
* function can be used to automatically scale {@link Polyline} or {@link Marker}
|
||||
* when zooming (which is not done by default in Mapsforge).
|
||||
*
|
||||
* @param width Original width to convert.
|
||||
* @param zoomLevel Zoom level for which the width should be computed.
|
||||
*
|
||||
* @return Actual width at the given zoom level.
|
||||
*/
|
||||
public static float getStrokeWidth(int width, byte zoomLevel) {
|
||||
|
@@ -8,14 +8,14 @@ public interface PointSetOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Set the width of this overlay for future addPoint().
|
||||
*
|
||||
*
|
||||
* @param width New default width for this overlay.
|
||||
*/
|
||||
public void setWidth(int width);
|
||||
|
||||
/**
|
||||
* Set color and width for this overlay for future addPoint().
|
||||
*
|
||||
*
|
||||
* @param width New default width for this overlay.
|
||||
* @param color New default color for this overlay.
|
||||
*/
|
||||
@@ -23,9 +23,8 @@ public interface PointSetOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Add a new point using the current width and color.
|
||||
*
|
||||
*
|
||||
* @param point Position of the point to add.
|
||||
*
|
||||
* @see #setWidth(int)
|
||||
* @see #setColor(Color)
|
||||
*/
|
||||
@@ -33,10 +32,9 @@ public interface PointSetOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Set the current width and then add a new point.
|
||||
*
|
||||
*
|
||||
* @param point Position of the point to add.
|
||||
* @param width New default width for this overlay.
|
||||
*
|
||||
* @see #setWidth(int)
|
||||
* @see PointSetOverlay#addPoint(Point)
|
||||
*/
|
||||
@@ -44,23 +42,21 @@ public interface PointSetOverlay extends Overlay {
|
||||
|
||||
/**
|
||||
* Set the current color and then add a new point.
|
||||
*
|
||||
*
|
||||
* @param point Position of the point to add.
|
||||
* @param color New default color for this overlay.
|
||||
*
|
||||
* @see #setColor(Color)
|
||||
* @see PointSetOverlay#addPoint(Point)
|
||||
*/
|
||||
public void addPoint(Point point, Color color);
|
||||
|
||||
/**
|
||||
* Add a new point at the given location, with the given color and width, and
|
||||
* update the current width and color.
|
||||
*
|
||||
* Add a new point at the given location, with the given color and width, and update
|
||||
* the current width and color.
|
||||
*
|
||||
* @param point Position of the point to add.
|
||||
* @param width New default width for this overlay.
|
||||
* @param color New default color for this overlay.
|
||||
*
|
||||
* @see #setWidth(int)
|
||||
* @see #setColor(Color)
|
||||
* @see PointSetOverlay#addPoint(Point)
|
||||
|
@@ -15,11 +15,10 @@ import org.mapsforge.map.layer.overlay.Polyline;
|
||||
|
||||
/**
|
||||
* Class extending the default Mapsforge's {@link Polyline} with auto-scaling.
|
||||
*
|
||||
* Mapsforge's Polylines do not scale with zoom level, this class aims at
|
||||
* correcting this. When a redraw is requested, the width of the line is
|
||||
* recomputed for the current zoom level.
|
||||
*
|
||||
* Mapsforge's Polylines do not scale with zoom level, this class aims at correcting
|
||||
* this. When a redraw is requested, the width of the line is recomputed for the current
|
||||
* zoom level.
|
||||
*
|
||||
* @see PaintUtils#getStrokeWidth(int, byte)
|
||||
*/
|
||||
public class PolylineAutoScaling extends Polyline {
|
||||
@@ -32,10 +31,9 @@ public class PolylineAutoScaling extends Polyline {
|
||||
|
||||
/**
|
||||
* Create a new PolylineAutoScaling with the given width and color.
|
||||
*
|
||||
*
|
||||
* @param width Original width of the line (independent of the zoom level).
|
||||
* @param color Color of the line.
|
||||
*
|
||||
* @see PaintUtils#getStrokeWidth(int, byte)
|
||||
*/
|
||||
public PolylineAutoScaling(int width, Color color) {
|
||||
@@ -47,7 +45,7 @@ public class PolylineAutoScaling extends Polyline {
|
||||
|
||||
/**
|
||||
* Set the color for this polyline.
|
||||
*
|
||||
*
|
||||
* @param color New color for this polyline.
|
||||
*/
|
||||
public void setColor(Color color) {
|
||||
@@ -73,18 +71,19 @@ public class PolylineAutoScaling extends Polyline {
|
||||
*/
|
||||
public void addAll(Collection<? extends Point> points) {
|
||||
ArrayList<LatLong> latlongs = new ArrayList<>(points.size());
|
||||
for (Point point: points) {
|
||||
for (Point point : points) {
|
||||
latlongs.add(new LatLong(point.getLatitude(), point.getLongitude()));
|
||||
}
|
||||
getLatLongs().addAll(latlongs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas,
|
||||
org.mapsforge.core.model.Point topLeftPoint) {
|
||||
public synchronized void draw(BoundingBox boundingBox, byte zoomLevel,
|
||||
Canvas canvas, org.mapsforge.core.model.Point topLeftPoint) {
|
||||
|
||||
// Update paint stroke with width for level
|
||||
this.getPaintStroke().setStrokeWidth(PaintUtils.getStrokeWidth(width, zoomLevel));
|
||||
this.getPaintStroke()
|
||||
.setStrokeWidth(PaintUtils.getStrokeWidth(width, zoomLevel));
|
||||
|
||||
super.draw(boundingBox, zoomLevel, canvas, topLeftPoint);
|
||||
}
|
||||
|
@@ -8,10 +8,11 @@ import org.insa.graphs.gui.drawing.Drawing;
|
||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
|
||||
import org.insa.graphs.model.Node;
|
||||
|
||||
public class WeaklyConnectedComponentGraphicObserver implements WeaklyConnectedComponentObserver {
|
||||
public class WeaklyConnectedComponentGraphicObserver
|
||||
implements WeaklyConnectedComponentObserver {
|
||||
|
||||
private static final Color[] COLORS = { Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW,
|
||||
Color.RED };
|
||||
private static final Color[] COLORS =
|
||||
{ Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW, Color.RED };
|
||||
|
||||
// Drawing + Graph drawing
|
||||
private PointSetOverlay grPoints;
|
||||
|
@@ -14,11 +14,11 @@ import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
public class FileUtils {
|
||||
|
||||
// Preferences
|
||||
private static Preferences preferences = Preferences.userRoot().node(FileUtils.class.getName());
|
||||
private static Preferences preferences =
|
||||
Preferences.userRoot().node(FileUtils.class.getName());
|
||||
|
||||
/**
|
||||
* Type of folder with associated preferred folder and path filters.
|
||||
*
|
||||
*/
|
||||
public enum FolderType {
|
||||
|
||||
@@ -49,34 +49,35 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
// Map folder type -> PreferencesEntry
|
||||
private static final Map<FolderType, PreferencesEntry> folderToEntry = new EnumMap<>(
|
||||
FolderType.class);
|
||||
private static final Map<FolderType, PreferencesEntry> folderToEntry =
|
||||
new EnumMap<>(FolderType.class);
|
||||
|
||||
// Map folder type -> File Filter
|
||||
private static final Map<FolderType, FileFilter> folderToFilter = new EnumMap<>(
|
||||
FolderType.class);
|
||||
private static final Map<FolderType, FileFilter> folderToFilter =
|
||||
new EnumMap<>(FolderType.class);
|
||||
|
||||
static {
|
||||
// Populate folderToEntry
|
||||
folderToEntry.put(FolderType.Map, new PreferencesEntry("DefaultMapFolder",
|
||||
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps"));
|
||||
folderToEntry.put(FolderType.PathInput, new PreferencesEntry("DefaultPathInputFolder",
|
||||
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths"));
|
||||
folderToEntry.put(FolderType.PathInput,
|
||||
new PreferencesEntry("DefaultPathInputFolder",
|
||||
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths"));
|
||||
folderToEntry.put(FolderType.PathOutput,
|
||||
new PreferencesEntry("DefaultPathOutputsFolder", "paths"));
|
||||
|
||||
// Populate folderToFilter
|
||||
folderToFilter.put(FolderType.Map, new FileNameExtensionFilter("Graph files", "mapgr"));
|
||||
folderToFilter.put(FolderType.PathInput, new FileNameExtensionFilter("Path files", "path"));
|
||||
folderToFilter.put(FolderType.Map,
|
||||
new FileNameExtensionFilter("Graph files", "mapgr"));
|
||||
folderToFilter.put(FolderType.PathInput,
|
||||
new FileNameExtensionFilter("Path files", "path"));
|
||||
folderToFilter.put(FolderType.PathOutput,
|
||||
new FileNameExtensionFilter("Path files", "path"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderType Type of folder to retrieve.
|
||||
*
|
||||
* @return A File instance pointing to the preferred folder for the given type.
|
||||
*
|
||||
* @see FolderType
|
||||
*/
|
||||
public static File getPreferredFolder(FolderType folderType) {
|
||||
@@ -92,14 +93,14 @@ public class FileUtils {
|
||||
* @param folderType Type of folder to update.
|
||||
* @param newPreferredFolder New preferred folder.
|
||||
*/
|
||||
public static void updatePreferredFolder(FolderType folderType, File newPreferredFolder) {
|
||||
public static void updatePreferredFolder(FolderType folderType,
|
||||
File newPreferredFolder) {
|
||||
PreferencesEntry entry = folderToEntry.get(folderType);
|
||||
preferences.put(entry.key, newPreferredFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folderType Type of folder for which the filter should be retrieved.
|
||||
*
|
||||
* @return A FileFilter corresponding to input graph files.
|
||||
*/
|
||||
public static FileFilter getFileFilter(FolderType folderType) {
|
||||
@@ -108,18 +109,18 @@ public class FileUtils {
|
||||
|
||||
/**
|
||||
* @param folderType Type of folder for which a file chooser should be created.
|
||||
* @param defaultFileName Default file name to show, or null to not show any
|
||||
* file.
|
||||
*
|
||||
* @param defaultFileName Default file name to show, or null to not show any file.
|
||||
* @return A new JFileChooser pointing to the preferred folder for the given
|
||||
* folderType, with the given default file selected (if given).
|
||||
*/
|
||||
public static JFileChooser createFileChooser(FolderType folderType, String defaultFileName) {
|
||||
public static JFileChooser createFileChooser(FolderType folderType,
|
||||
String defaultFileName) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setCurrentDirectory(getPreferredFolder(folderType));
|
||||
if (defaultFileName != null) {
|
||||
chooser.setSelectedFile(new File(chooser.getCurrentDirectory().getAbsolutePath()
|
||||
+ File.separator + defaultFileName));
|
||||
chooser.setSelectedFile(
|
||||
new File(chooser.getCurrentDirectory().getAbsolutePath()
|
||||
+ File.separator + defaultFileName));
|
||||
}
|
||||
chooser.setFileFilter(getFileFilter(folderType));
|
||||
chooser.addActionListener(new ActionListener() {
|
||||
@@ -138,10 +139,8 @@ public class FileUtils {
|
||||
|
||||
/**
|
||||
* @param folderType Type of folder for which a file chooser should be created.
|
||||
*
|
||||
* @return A new JFileChooser pointing to the preferred folder for the given
|
||||
* folderType.
|
||||
*
|
||||
* @see #createFileChooser(FolderType, String)
|
||||
*/
|
||||
public static JFileChooser createFileChooser(FolderType folderType) {
|
||||
|
Reference in New Issue
Block a user