diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
| commit | b086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch) | |
| tree | 8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /src/main/java/com/c2kernel/graph/controller/StartVertexController.java | |
| parent | 22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff) | |
Initial Maven Conversion
Diffstat (limited to 'src/main/java/com/c2kernel/graph/controller/StartVertexController.java')
| -rw-r--r-- | src/main/java/com/c2kernel/graph/controller/StartVertexController.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/graph/controller/StartVertexController.java b/src/main/java/com/c2kernel/graph/controller/StartVertexController.java new file mode 100644 index 0000000..3984cb7 --- /dev/null +++ b/src/main/java/com/c2kernel/graph/controller/StartVertexController.java @@ -0,0 +1,79 @@ +package com.c2kernel.graph.controller;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.swing.JButton;
+
+import com.c2kernel.graph.event.SelectionChangedEvent;
+import com.c2kernel.graph.model.GraphModelManager;
+import com.c2kernel.graph.model.Vertex;
+
+
+// The start vertex controller is responsible for selecting
+// the vertex at the start of the graph.
+//
+// The controller listens to:
+// * The graph model to determine if there is a single
+// vertex selected
+// * The start vertex button
+//
+// The controller modifies:
+// * The graph model to select the start vertex
+// * The start button to enable it only when there is a
+// single vertex selected
+public class StartVertexController implements Observer, ActionListener
+{
+ private GraphModelManager mGraphModelManager = null;
+ private JButton mStartButton = null;
+
+
+ public void setGraphModelManager(GraphModelManager graphModelManager)
+ {
+ mGraphModelManager = graphModelManager;
+ mGraphModelManager.addObserver(this);
+ }
+
+
+ public void setStartButton(JButton startButton)
+ {
+ mStartButton = startButton;
+ mStartButton.addActionListener(this);
+ }
+
+
+ @Override
+ public void update(Observable o, Object arg)
+ {
+ SelectionChangedEvent event = null;
+ Vertex[] selectedVertices = null;
+
+ // If the selected vertex has changed
+ if(arg instanceof SelectionChangedEvent && mStartButton != null)
+ {
+ event = (SelectionChangedEvent)arg;
+ selectedVertices = event.mSelection.mVertices;
+
+ if(selectedVertices == null)
+ {
+ mStartButton.setEnabled(false);
+ }
+ else if (mGraphModelManager.isEditable())
+ {
+ mStartButton.setEnabled(selectedVertices.length == 1);
+ }
+ }
+ }
+
+
+ @Override
+ public void actionPerformed(ActionEvent ae)
+ {
+ if(mGraphModelManager != null)
+ {
+ mGraphModelManager.getModel().setSelectedVertexToBeStart();
+ }
+ }
+}
|
