Disable checkbox for graphic visualization when drawing is mapview.

This commit is contained in:
Holt59 2018-03-11 00:19:50 +01:00
parent a2d03a0857
commit 8661e63728
2 changed files with 37 additions and 10 deletions

View File

@ -32,13 +32,15 @@ import org.insa.algo.AlgorithmFactory;
import org.insa.algo.ArcFilterFactory; import org.insa.algo.ArcFilterFactory;
import org.insa.graph.Node; import org.insa.graph.Node;
import org.insa.graphics.NodesInputPanel.InputChangedEvent; import org.insa.graphics.NodesInputPanel.InputChangedEvent;
import org.insa.graphics.drawing.Drawing;
import org.insa.graphics.drawing.components.MapViewDrawing;
public class AlgorithmPanel extends JPanel { public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
/** /**
* *
*/ */
private static final long serialVersionUID = 406148710808045035L; private static final long serialVersionUID = 1L;
public class StartActionEvent extends ActionEvent { public class StartActionEvent extends ActionEvent {
@ -125,6 +127,12 @@ public class AlgorithmPanel extends JPanel {
// Component that can be enabled/disabled. // Component that can be enabled/disabled.
private ArrayList<JComponent> components = new ArrayList<>(); private ArrayList<JComponent> components = new ArrayList<>();
// Graphic / Text checkbox observer
private final JCheckBox graphicObserverCheckbox, textualObserverCheckbox;
// Drawing
private Drawing drawing = null;
private JButton startAlgoButton; private JButton startAlgoButton;
// Start listeners // Start listeners
@ -171,9 +179,9 @@ public class AlgorithmPanel extends JPanel {
group.add(lengthModeButton); group.add(lengthModeButton);
group.add(timeModeButton); group.add(timeModeButton);
JCheckBox graphicObserver = new JCheckBox("Graphic"); graphicObserverCheckbox = new JCheckBox("Graphic");
graphicObserver.setSelected(true); graphicObserverCheckbox.setSelected(true);
JCheckBox textObserver = new JCheckBox("Textual"); textualObserverCheckbox = new JCheckBox("Textual");
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
@ -198,10 +206,10 @@ public class AlgorithmPanel extends JPanel {
modeAndObserverPanel.add(new JLabel("Visualization: "), c); modeAndObserverPanel.add(new JLabel("Visualization: "), c);
c.gridx = 1; c.gridx = 1;
c.weightx = 1; c.weightx = 1;
modeAndObserverPanel.add(graphicObserver, c); modeAndObserverPanel.add(graphicObserverCheckbox, c);
c.gridx = 2; c.gridx = 2;
c.weightx = 1; c.weightx = 1;
modeAndObserverPanel.add(textObserver, c); modeAndObserverPanel.add(textualObserverCheckbox, c);
if (enableArcFilterSelection) { if (enableArcFilterSelection) {
c.gridy = 1; c.gridy = 1;
@ -217,8 +225,7 @@ public class AlgorithmPanel extends JPanel {
components.add(timeModeButton); components.add(timeModeButton);
components.add(lengthModeButton); components.add(lengthModeButton);
components.add(arcFilterSelect); components.add(arcFilterSelect);
components.add(graphicObserver); components.add(textualObserverCheckbox);
components.add(textObserver);
add(modeAndObserverPanel); add(modeAndObserverPanel);
@ -247,7 +254,8 @@ public class AlgorithmPanel extends JPanel {
(String) algoSelect.getSelectedItem()), (String) algoSelect.getSelectedItem()),
nodesInputPanel.getNodeForInputs(), mode, nodesInputPanel.getNodeForInputs(), mode,
(AbstractInputData.ArcFilter) arcFilterSelect.getSelectedItem(), (AbstractInputData.ArcFilter) arcFilterSelect.getSelectedItem(),
graphicObserver.isSelected(), textObserver.isSelected())); graphicObserverCheckbox.isSelected(),
textualObserverCheckbox.isSelected()));
} }
} }
}); });
@ -366,6 +374,7 @@ public class AlgorithmPanel extends JPanel {
for (JComponent component: components) { for (JComponent component: components) {
component.setEnabled(enabled); component.setEnabled(enabled);
} }
graphicObserverCheckbox.setEnabled(enabled && !(drawing instanceof MapViewDrawing));
enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs()); enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs());
startAlgoButton.setEnabled(enabled); startAlgoButton.setEnabled(enabled);
} }
@ -379,4 +388,21 @@ public class AlgorithmPanel extends JPanel {
this.startActionListeners.add(listener); this.startActionListeners.add(listener);
} }
@Override
public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
if (newDrawing instanceof MapViewDrawing) {
graphicObserverCheckbox.setSelected(false);
graphicObserverCheckbox.setEnabled(false);
}
else {
graphicObserverCheckbox.setSelected(true);
graphicObserverCheckbox.setEnabled(true);
}
this.drawing = newDrawing;
}
@Override
public void onRedrawRequest() {
}
} }

View File

@ -288,6 +288,7 @@ public class MainWindow extends JFrame {
this.graphChangeListeneres.add(panel.solutionPanel); this.graphChangeListeneres.add(panel.solutionPanel);
this.drawingChangeListeners.add(panel.nodesInputPanel); this.drawingChangeListeners.add(panel.nodesInputPanel);
this.drawingChangeListeners.add(panel.solutionPanel); this.drawingChangeListeners.add(panel.solutionPanel);
this.drawingChangeListeners.add(panel);
} }
this.graphChangeListeneres.add(pathPanel); this.graphChangeListeneres.add(pathPanel);