Browse Source

Disable checkbox for graphic visualization when drawing is mapview.

Holt59 3 years ago
parent
commit
8661e63728

+ 36
- 10
src/main/org/insa/graphics/AlgorithmPanel.java View File

@@ -32,13 +32,15 @@ import org.insa.algo.AlgorithmFactory;
32 32
 import org.insa.algo.ArcFilterFactory;
33 33
 import org.insa.graph.Node;
34 34
 import org.insa.graphics.NodesInputPanel.InputChangedEvent;
35
+import org.insa.graphics.drawing.Drawing;
36
+import org.insa.graphics.drawing.components.MapViewDrawing;
35 37
 
36
-public class AlgorithmPanel extends JPanel {
38
+public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
37 39
 
38 40
     /**
39 41
      * 
40 42
      */
41
-    private static final long serialVersionUID = 406148710808045035L;
43
+    private static final long serialVersionUID = 1L;
42 44
 
43 45
     public class StartActionEvent extends ActionEvent {
44 46
 
@@ -125,6 +127,12 @@ public class AlgorithmPanel extends JPanel {
125 127
     // Component that can be enabled/disabled.
126 128
     private ArrayList<JComponent> components = new ArrayList<>();
127 129
 
130
+    // Graphic / Text checkbox observer
131
+    private final JCheckBox graphicObserverCheckbox, textualObserverCheckbox;
132
+
133
+    // Drawing
134
+    private Drawing drawing = null;
135
+
128 136
     private JButton startAlgoButton;
129 137
 
130 138
     // Start listeners
@@ -171,9 +179,9 @@ public class AlgorithmPanel extends JPanel {
171 179
         group.add(lengthModeButton);
172 180
         group.add(timeModeButton);
173 181
 
174
-        JCheckBox graphicObserver = new JCheckBox("Graphic");
175
-        graphicObserver.setSelected(true);
176
-        JCheckBox textObserver = new JCheckBox("Textual");
182
+        graphicObserverCheckbox = new JCheckBox("Graphic");
183
+        graphicObserverCheckbox.setSelected(true);
184
+        textualObserverCheckbox = new JCheckBox("Textual");
177 185
 
178 186
         GridBagConstraints c = new GridBagConstraints();
179 187
 
@@ -198,10 +206,10 @@ public class AlgorithmPanel extends JPanel {
198 206
         modeAndObserverPanel.add(new JLabel("Visualization: "), c);
199 207
         c.gridx = 1;
200 208
         c.weightx = 1;
201
-        modeAndObserverPanel.add(graphicObserver, c);
209
+        modeAndObserverPanel.add(graphicObserverCheckbox, c);
202 210
         c.gridx = 2;
203 211
         c.weightx = 1;
204
-        modeAndObserverPanel.add(textObserver, c);
212
+        modeAndObserverPanel.add(textualObserverCheckbox, c);
205 213
 
206 214
         if (enableArcFilterSelection) {
207 215
             c.gridy = 1;
@@ -217,8 +225,7 @@ public class AlgorithmPanel extends JPanel {
217 225
         components.add(timeModeButton);
218 226
         components.add(lengthModeButton);
219 227
         components.add(arcFilterSelect);
220
-        components.add(graphicObserver);
221
-        components.add(textObserver);
228
+        components.add(textualObserverCheckbox);
222 229
 
223 230
         add(modeAndObserverPanel);
224 231
 
@@ -247,7 +254,8 @@ public class AlgorithmPanel extends JPanel {
247 254
                                     (String) algoSelect.getSelectedItem()),
248 255
                             nodesInputPanel.getNodeForInputs(), mode,
249 256
                             (AbstractInputData.ArcFilter) arcFilterSelect.getSelectedItem(),
250
-                            graphicObserver.isSelected(), textObserver.isSelected()));
257
+                            graphicObserverCheckbox.isSelected(),
258
+                            textualObserverCheckbox.isSelected()));
251 259
                 }
252 260
             }
253 261
         });
@@ -366,6 +374,7 @@ public class AlgorithmPanel extends JPanel {
366 374
         for (JComponent component: components) {
367 375
             component.setEnabled(enabled);
368 376
         }
377
+        graphicObserverCheckbox.setEnabled(enabled && !(drawing instanceof MapViewDrawing));
369 378
         enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs());
370 379
         startAlgoButton.setEnabled(enabled);
371 380
     }
@@ -379,4 +388,21 @@ public class AlgorithmPanel extends JPanel {
379 388
         this.startActionListeners.add(listener);
380 389
     }
381 390
 
391
+    @Override
392
+    public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
393
+        if (newDrawing instanceof MapViewDrawing) {
394
+            graphicObserverCheckbox.setSelected(false);
395
+            graphicObserverCheckbox.setEnabled(false);
396
+        }
397
+        else {
398
+            graphicObserverCheckbox.setSelected(true);
399
+            graphicObserverCheckbox.setEnabled(true);
400
+        }
401
+        this.drawing = newDrawing;
402
+    }
403
+
404
+    @Override
405
+    public void onRedrawRequest() {
406
+    }
407
+
382 408
 }

+ 1
- 0
src/main/org/insa/graphics/MainWindow.java View File

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

Loading…
Cancel
Save