From 5e4034b5cba89460a62fa958fc78c2b85acb3d5f Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 7 Oct 2014 09:18:33 +0200 Subject: Repackage to org.cristalise --- .../controller/VertexConstructionController.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/org/cristalise/gui/graph/controller/VertexConstructionController.java (limited to 'src/main/java/org/cristalise/gui/graph/controller/VertexConstructionController.java') diff --git a/src/main/java/org/cristalise/gui/graph/controller/VertexConstructionController.java b/src/main/java/org/cristalise/gui/graph/controller/VertexConstructionController.java new file mode 100644 index 0000000..a2f5dc0 --- /dev/null +++ b/src/main/java/org/cristalise/gui/graph/controller/VertexConstructionController.java @@ -0,0 +1,54 @@ +package org.cristalise.gui.graph.controller; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import org.cristalise.gui.MainFrame; +import org.cristalise.gui.graph.view.EditorModeListener; +import org.cristalise.gui.graph.view.EditorToolBar; +import org.cristalise.kernel.graph.model.GraphModelManager; +import org.cristalise.kernel.graph.model.GraphPoint; + + + +public class VertexConstructionController extends MouseAdapter implements EditorModeListener +{ + private GraphModelManager mGraphModelManager = null; + private EditorToolBar mEditorToolBar = null; + private boolean mCreatingVertices = false; + + + public void setGraphModelManager(GraphModelManager graphModelManager) + { + mGraphModelManager = graphModelManager; + } + + + public void setEditorToolBar(EditorToolBar editorToolBar) + { + mEditorToolBar = editorToolBar; + mEditorToolBar.addEditorModeListener(this); + } + + + @Override + public void editorModeChanged(String idOfNewMode) + { + mCreatingVertices = idOfNewMode.equals("Vertex"); + } + + + @Override + public void mouseClicked(MouseEvent me) + { + if(mCreatingVertices && (mGraphModelManager != null) && (mEditorToolBar != null) && mGraphModelManager.isEditable()) + { + try { + mGraphModelManager.getModel().createVertex(new GraphPoint(me.getPoint().x, me.getPoint().y), mEditorToolBar.getSelectedVertexType()); + } catch (Exception e) { + MainFrame.exceptionDialog(e); + } + mEditorToolBar.enterSelectMode(); + } + } +} -- cgit v1.2.3