From c6028e69a340ecdd37b4f0b7cc5a6937e2d8ea1e Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 15 Mar 2010 14:46:47 +0000 Subject: [PATCH] Mouse release event to h2d. Context menu uses that event ( release(right) ) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14926 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/h2d/canvas/EditorCanvas.java | 13 ++++-- .../org/simantics/h2d/event/ReleaseEvent.java | 42 +++++++++++++++++++ .../sysdyn/ui/actions/OpenContextMenu.java | 4 +- .../sysdyn/ui/editor/SysdynDiagramEditor.java | 2 +- .../sysdyn/ui/elements/TextElement.java | 9 ++-- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java diff --git a/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java b/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java index b2d8e4dd..f3df5fff 100644 --- a/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java +++ b/org.simantics.h2d/src/org/simantics/h2d/canvas/EditorCanvas.java @@ -16,7 +16,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; @@ -31,12 +30,12 @@ import java.awt.geom.Point2D; import java.awt.image.VolatileImage; import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.editor.impl.DiagramEditor; import org.simantics.h2d.event.ClickEvent; import org.simantics.h2d.event.DragEvent; import org.simantics.h2d.event.DragEventPhase; import org.simantics.h2d.event.KeyboardEvent; import org.simantics.h2d.event.Modifiers; +import org.simantics.h2d.event.ReleaseEvent; import org.simantics.h2d.event.WheelEvent; import org.simantics.scenegraph.g2d.G2DRenderingHints; @@ -166,7 +165,15 @@ public class EditorCanvas extends Canvas { if(dragEvent != null && dragEvent.phase == DragEventPhase.dragUpdate) { dragEvent.phase = DragEventPhase.dragEnd; editor.handleEvent(dragEvent); - } + } + + ReleaseEvent event = new ReleaseEvent( + Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()), + editor.screenToDiagram(e.getPoint()), + e.getLocationOnScreen() + ); + event.pickedElements = dragEvent.pickedElements; + editor.handleEvent(event); } @Override diff --git a/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java b/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java new file mode 100644 index 00000000..c6d57de3 --- /dev/null +++ b/org.simantics.h2d/src/org/simantics/h2d/event/ReleaseEvent.java @@ -0,0 +1,42 @@ +package org.simantics.h2d.event; + +import java.awt.geom.Point2D; +import java.util.List; + +import org.simantics.h2d.element.IElement; + +public class ReleaseEvent implements ILocatableEvent { + final public String modifiers; + + // Release location in diagram coordinates + final public Point2D point; + final public Point2D dispPoint; + + public List pickedElements; + + public ReleaseEvent(String modifiers, Point2D point, Point2D dispPoint) { + this.modifiers = modifiers; + this.dispPoint = dispPoint; + this.point = point; + } + + @Override + public Point2D getLocation() { + return point; + } + + @Override + public List getPickedElements() { + return pickedElements; + } + + @Override + public String getType() { + return getType(modifiers); + } + + public static String getType(String modifiers) { + return "release(" + modifiers + ")"; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java index 37e856fb..f2a092e5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java @@ -22,8 +22,8 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPartSite; import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.ClickEvent; import org.simantics.h2d.event.IEvent; +import org.simantics.h2d.event.ReleaseEvent; import org.simantics.h2d.event.handler.IEventHandler; import org.simantics.ui.action.GraphMenuManager; @@ -54,7 +54,7 @@ public class OpenContextMenu implements IEventHandler { @Override public boolean handle(final IDiagramEditor editor, IEvent _event) { - final ClickEvent event = (ClickEvent)_event; + final ReleaseEvent event = (ReleaseEvent)_event; control.getDisplay().asyncExec(new Runnable() { @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java index 190b6b2e..3333f394 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java @@ -202,7 +202,7 @@ public class SysdynDiagramEditor extends ResourceEditorPart { editor.addEventHandler(1, "key(C)", new CreateCloud()); editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency()); editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow()); - editor.addEventHandler(1, "click(right)", openContextMenu); + editor.addEventHandler(1, "release(right)", openContextMenu); canvas = new EditorCanvas(editor); frame.add(canvas); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java index ad451404..8e1e82a1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java @@ -17,10 +17,6 @@ import java.awt.font.FontRenderContext; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.util.List; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; import org.simantics.h2d.action.IAction; import org.simantics.h2d.editor.IDiagramEditor; import org.simantics.h2d.element.IElement; @@ -34,9 +30,7 @@ import org.simantics.h2d.node.ITextListener; import org.simantics.h2d.node.TextNode; import org.simantics.objmap.annotations.GraphType; import org.simantics.objmap.annotations.RelatedValue; -import org.simantics.objmap.annotations.UpdateMethod; import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.sysdyn.SysdynResource; @GraphType("http://www.simantics.org/Sysdyn-1.0/Auxiliary") public class TextElement extends RectangularElement implements Movable, Connectable, IEventHandler { @@ -212,6 +206,8 @@ public class TextElement extends RectangularElement implements Movable, Connecta } boolean oldHasEquation = false; + boolean hasEquation = true; + /* boolean hasEquation = false; @UpdateMethod @@ -228,4 +224,5 @@ public class TextElement extends RectangularElement implements Movable, Connecta } return false; } + */ } -- 2.47.1