Move solution panel inside shortest-path panel.
This commit is contained in:
parent
d442a7e910
commit
19832321aa
@ -98,7 +98,6 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
// Shortest path panel
|
// Shortest path panel
|
||||||
private ShortestPathPanel spPanel;
|
private ShortestPathPanel spPanel;
|
||||||
private ShortestPathSolutionPanel spSolPanel;
|
|
||||||
|
|
||||||
// List of items that cannot be used without a graph
|
// List of items that cannot be used without a graph
|
||||||
private ArrayList<JMenuItem> graphLockItems = new ArrayList<JMenuItem>();
|
private ArrayList<JMenuItem> graphLockItems = new ArrayList<JMenuItem>();
|
||||||
@ -139,7 +138,7 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
this.drawing = this.basicDrawing;
|
this.drawing = this.basicDrawing;
|
||||||
|
|
||||||
spPanel = new ShortestPathPanel();
|
spPanel = new ShortestPathPanel(this);
|
||||||
spPanel.addStartActionListener(new ActionListener() {
|
spPanel.addStartActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -163,17 +162,14 @@ public class MainWindow extends JFrame {
|
|||||||
});
|
});
|
||||||
spPanel.setVisible(false);
|
spPanel.setVisible(false);
|
||||||
|
|
||||||
spSolPanel = new ShortestPathSolutionPanel(this, drawing);
|
|
||||||
spSolPanel.setVisible(false);
|
|
||||||
|
|
||||||
// Add click listeners to both drawing.
|
// Add click listeners to both drawing.
|
||||||
basicDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
|
basicDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
|
||||||
mapViewDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
|
mapViewDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
|
||||||
|
|
||||||
this.graphChangeListeneres.add(spPanel.nodesInputPanel);
|
this.graphChangeListeneres.add(spPanel.nodesInputPanel);
|
||||||
this.graphChangeListeneres.add(spSolPanel);
|
this.graphChangeListeneres.add(spPanel.solutionPanel);
|
||||||
this.drawingChangeListeners.add(spPanel.nodesInputPanel);
|
this.drawingChangeListeners.add(spPanel.nodesInputPanel);
|
||||||
this.drawingChangeListeners.add(spSolPanel);
|
this.drawingChangeListeners.add(spPanel.solutionPanel);
|
||||||
|
|
||||||
// Create action factory.
|
// Create action factory.
|
||||||
this.currentThread = new ThreadWrapper(this);
|
this.currentThread = new ThreadWrapper(this);
|
||||||
@ -219,12 +215,6 @@ public class MainWindow extends JFrame {
|
|||||||
c = new GridBagConstraints();
|
c = new GridBagConstraints();
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
c.gridy = 1;
|
c.gridy = 1;
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
rightComponent.add(spSolPanel, c);
|
|
||||||
|
|
||||||
c = new GridBagConstraints();
|
|
||||||
c.gridx = 0;
|
|
||||||
c.gridy = 2;
|
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
c.weighty = 1;
|
c.weighty = 1;
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
@ -279,8 +269,8 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displayShortestPathSolution(ShortestPathSolution solution) {
|
private void displayShortestPathSolution(ShortestPathSolution solution) {
|
||||||
spSolPanel.addSolution(solution);
|
spPanel.solutionPanel.addSolution(solution);
|
||||||
spSolPanel.setVisible(true);
|
spPanel.solutionPanel.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchShortestPathThread(ShortestPathAlgorithm spAlgorithm) {
|
private void launchShortestPathThread(ShortestPathAlgorithm spAlgorithm) {
|
||||||
|
@ -49,8 +49,8 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
private final Mode mode;
|
private final Mode mode;
|
||||||
private final Class<? extends ShortestPathAlgorithm> algoClass;
|
private final Class<? extends ShortestPathAlgorithm> algoClass;
|
||||||
|
|
||||||
public StartActionEvent(Class<? extends ShortestPathAlgorithm> algoClass, Node origin, Node destination,
|
public StartActionEvent(Class<? extends ShortestPathAlgorithm> algoClass, Node origin,
|
||||||
Mode mode) {
|
Node destination, Mode mode) {
|
||||||
super(ShortestPathPanel.this, START_EVENT_ID, START_EVENT_COMMAND);
|
super(ShortestPathPanel.this, START_EVENT_ID, START_EVENT_COMMAND);
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
@ -91,6 +91,9 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
// Input panels for node.
|
// Input panels for node.
|
||||||
protected NodesInputPanel nodesInputPanel;
|
protected NodesInputPanel nodesInputPanel;
|
||||||
|
|
||||||
|
// Solution
|
||||||
|
protected ShortestPathSolutionPanel solutionPanel;
|
||||||
|
|
||||||
// Component that can be enabled/disabled.
|
// Component that can be enabled/disabled.
|
||||||
private ArrayList<JComponent> components = new ArrayList<>();
|
private ArrayList<JComponent> components = new ArrayList<>();
|
||||||
|
|
||||||
@ -101,7 +104,7 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public ShortestPathPanel() {
|
public ShortestPathPanel(Component parent) {
|
||||||
super();
|
super();
|
||||||
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||||
|
|
||||||
@ -156,6 +159,12 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
components.add(timeModeButton);
|
components.add(timeModeButton);
|
||||||
components.add(lengthModeButton);
|
components.add(lengthModeButton);
|
||||||
|
|
||||||
|
solutionPanel = new ShortestPathSolutionPanel(parent);
|
||||||
|
solutionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
|
solutionPanel.setVisible(false);
|
||||||
|
add(Box.createVerticalStrut(10));
|
||||||
|
add(solutionPanel);
|
||||||
|
|
||||||
// Bottom panel
|
// Bottom panel
|
||||||
JPanel bottomPanel = new JPanel();
|
JPanel bottomPanel = new JPanel();
|
||||||
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
|
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
|
||||||
@ -171,7 +180,8 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
|
|
||||||
for (ActionListener lis: startActionListeners) {
|
for (ActionListener lis: startActionListeners) {
|
||||||
lis.actionPerformed(new StartActionEvent(
|
lis.actionPerformed(new StartActionEvent(
|
||||||
ShortestPathAlgorithmFactory.getAlgorithmClass((String) algoSelect.getSelectedItem()),
|
ShortestPathAlgorithmFactory
|
||||||
|
.getAlgorithmClass((String) algoSelect.getSelectedItem()),
|
||||||
origin, destination, mode));
|
origin, destination, mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,6 +246,7 @@ public class ShortestPathPanel extends JPanel {
|
|||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
nodesInputPanel.setEnabled(enabled);
|
nodesInputPanel.setEnabled(enabled);
|
||||||
|
solutionPanel.setEnabled(enabled);
|
||||||
for (JComponent component: components) {
|
for (JComponent component: components) {
|
||||||
component.setEnabled(enabled);
|
component.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ import javax.swing.JFileChooser;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
@ -112,27 +114,32 @@ public class ShortestPathSolutionPanel extends JPanel
|
|||||||
private final JComboBox<ShortestPathBundle> solutionSelect;
|
private final JComboBox<ShortestPathBundle> solutionSelect;
|
||||||
|
|
||||||
// Map solution -> panel
|
// Map solution -> panel
|
||||||
private final JLabel informationPanel;
|
private final JTextArea informationPanel;
|
||||||
|
|
||||||
// Current bundle
|
// Current bundle
|
||||||
private ShortestPathBundle currentBundle = null;
|
private ShortestPathBundle currentBundle = null;
|
||||||
|
|
||||||
public ShortestPathSolutionPanel(Component parent, Drawing drawing) {
|
public ShortestPathSolutionPanel(Component parent) {
|
||||||
super();
|
super();
|
||||||
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||||
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK),
|
setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.LIGHT_GRAY),
|
||||||
new EmptyBorder(15, 15, 15, 15)));
|
new EmptyBorder(10, 0, 10, 0)));
|
||||||
|
|
||||||
this.drawing = drawing;
|
|
||||||
|
|
||||||
solutionSelect = new JComboBox<>();
|
solutionSelect = new JComboBox<>();
|
||||||
solutionSelect.setBackground(Color.WHITE);
|
solutionSelect.setBackground(Color.WHITE);
|
||||||
solutionSelect.setAlignmentX(Component.LEFT_ALIGNMENT);
|
solutionSelect.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||||
add(solutionSelect);
|
add(solutionSelect);
|
||||||
|
|
||||||
informationPanel = new JLabel();
|
informationPanel = new JTextArea();
|
||||||
|
informationPanel.setWrapStyleWord(true);
|
||||||
|
informationPanel.setLineWrap(true);
|
||||||
|
informationPanel.setOpaque(true);
|
||||||
|
informationPanel.setFocusable(false);
|
||||||
|
informationPanel.setEditable(false);
|
||||||
|
informationPanel.setBackground(UIManager.getColor("Label.background"));
|
||||||
|
informationPanel.setFont(UIManager.getFont("Label.font"));
|
||||||
|
informationPanel.setBorder(UIManager.getBorder("Label.border"));
|
||||||
informationPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
|
informationPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
|
||||||
informationPanel.setHorizontalAlignment(JLabel.LEFT);
|
|
||||||
add(informationPanel);
|
add(informationPanel);
|
||||||
|
|
||||||
JButton clearButton = new JButton("Hide");
|
JButton clearButton = new JButton("Hide");
|
||||||
@ -230,24 +237,42 @@ public class ShortestPathSolutionPanel extends JPanel
|
|||||||
ShortestPathData data = bundle.getData();
|
ShortestPathData data = bundle.getData();
|
||||||
String info = null;
|
String info = null;
|
||||||
if (!bundle.getSolution().isFeasible()) {
|
if (!bundle.getSolution().isFeasible()) {
|
||||||
info = String.format("Shortest path: No path found from node #%d to node #%d.",
|
info = String.format("No path found from node #%d to node #%d.",
|
||||||
data.getOrigin().getId(), data.getDestination().getId());
|
data.getOrigin().getId(), data.getDestination().getId());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info = String.format("Shortest path: Found a path from node #%d to node #%d",
|
info = String.format("Found a path from node #%d to node #%d", data.getOrigin().getId(),
|
||||||
data.getOrigin().getId(), data.getDestination().getId());
|
data.getDestination().getId());
|
||||||
if (data.getMode() == Mode.LENGTH) {
|
if (data.getMode() == Mode.LENGTH) {
|
||||||
info = String.format("%s, %.2f kilometers.", info,
|
info = String.format("%s, %.4f kilometers.", info,
|
||||||
(bundle.getSolution().getPath().getLength() / 1000.0));
|
(bundle.getSolution().getPath().getLength() / 1000.0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info = String.format("%s, %.2f minutes.", info,
|
info = String.format("%s, %.4f minutes.", info,
|
||||||
(bundle.getSolution().getPath().getMinimumTravelTime() / 60.0));
|
(bundle.getSolution().getPath().getMinimumTravelTime() / 60.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
informationPanel.setText(info);
|
informationPanel.setText(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
solutionSelect.setEnabled(enabled);
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
// Trigger event
|
||||||
|
solutionSelect.actionPerformed(null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ShortestPathBundle bundle = (ShortestPathBundle) this.solutionSelect.getSelectedItem();
|
||||||
|
if (bundle != null && bundle.getOverlay() != null) {
|
||||||
|
bundle.getOverlay().setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newGraphLoaded(Graph graph) {
|
public void newGraphLoaded(Graph graph) {
|
||||||
this.solutionSelect.removeAllItems();
|
this.solutionSelect.removeAllItems();
|
||||||
|
Loading…
Reference in New Issue
Block a user