]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/BoxSelectionMode.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / participant / pointertool / BoxSelectionMode.java
index 8e47498c93de83aa5145e45ff09b1ec54e00705c..6a1d27fd22863b2c04bad1cf34d42dd8ba367ec4 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.diagram.participant.pointertool;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;\r
-import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;\r
-import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
-import org.simantics.g2d.diagram.DiagramHints;\r
-import org.simantics.g2d.diagram.handler.PickContext;\r
-import org.simantics.g2d.diagram.handler.PickRequest;\r
-import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.participant.KeyUtil;\r
-import org.simantics.g2d.participant.RenderingQualityInteractor;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.command.CommandEvent;\r
-import org.simantics.scenegraph.g2d.events.command.Commands;\r
-import org.simantics.scenegraph.g2d.nodes.BoxSelectionNode;\r
-import org.simantics.scenegraph.utils.Quality;\r
-\r
-/**\r
- * @author Toni Kalajainen\r
- */\r
-public class BoxSelectionMode extends AbstractMode {\r
-\r
-    @Reference  RenderingQualityInteractor quality;\r
-    @Dependency TransformUtil util;\r
-    @Dependency Selection selection;\r
-    @Dependency PickContext pickContext;\r
-    @Dependency KeyUtil keyUtil;\r
-\r
-    public final static BasicStroke STROKE         = new BasicStroke(1.0f);\r
-\r
-    public static final int         PAINT_PRIORITY = 30;\r
-\r
-    Point2D                         startingPoint;\r
-    Point2D                         currentPoint;\r
-    int                             mouseButton;\r
-    PickPolicy                      boxSelectMode;\r
-    BoxSelectionNode                node;\r
-\r
-    @SGInit\r
-    public void init(G2DParentNode parent) {\r
-        if (quality != null)\r
-            quality.setStaticQuality(Quality.LOW);\r
-\r
-        node = parent.getOrCreateNode("" + hashCode(), BoxSelectionNode.class);\r
-        node.setZIndex(PAINT_PRIORITY);\r
-        node.setStart(startingPoint);\r
-        node.setEnd(currentPoint);\r
-        node.setStroke(STROKE);\r
-        node.setScaleStroke(true);\r
-        node.setColor(getToolColor());\r
-        node.setMouseButton(mouseButton);\r
-        node.setSelectionListener(new BoxSelectionNode.SelectionListener() {\r
-            @Override\r
-            public void onSelect(Rectangle2D rect, int modifiers) {\r
-                // Disposed?\r
-                if (isRemoved())\r
-                    return;\r
-\r
-                boolean toggle = (modifiers & MouseEvent.CTRL_MASK) != 0;\r
-                boolean accumulate = (modifiers & MouseEvent.SHIFT_MASK) != 0;\r
-\r
-                Set<IElement> boxSelection = new HashSet<IElement>();\r
-                PickRequest request = new PickRequest(rect);\r
-                request.pickPolicy = boxSelectMode;\r
-                pickContext.pick(diagram, request, boxSelection);\r
-\r
-                int selectionId = mouseId;\r
-                if (toggle) {\r
-                    selection.toggle(selectionId, boxSelection);\r
-                } else if (accumulate) {\r
-                    for (IElement elem : boxSelection)\r
-                        selection.add(selectionId, elem);\r
-                } else {\r
-                    selection.setSelection(selectionId, boxSelection);\r
-                }\r
-\r
-                if (node != null) {\r
-                    node.remove();\r
-                    node = null;\r
-                }\r
-\r
-                setDirty();\r
-                remove();\r
-            }\r
-        });\r
-\r
-    }\r
-\r
-    @SGCleanup\r
-    public void cleanup() {\r
-        if (quality != null)\r
-            quality.setStaticQuality(null);\r
-        if (node != null) {\r
-            node.remove();\r
-            node = null;\r
-        }\r
-    }\r
-\r
-    public BoxSelectionMode(Point2D startingPoint, Point2D currentPoint, final int mouseId, final int mouseButton, final PickPolicy boxSelectMode) {\r
-        super(mouseId);\r
-        this.startingPoint = startingPoint;\r
-        this.currentPoint = currentPoint;\r
-        this.mouseButton = mouseButton;\r
-        this.boxSelectMode = boxSelectMode;\r
-        //setHint(RenderingQualityInteractor.KEY_QUALITY_INTERACTOR_ENABLED, Boolean.FALSE);\r
-    }\r
-\r
-    public synchronized Color getToolColor() {\r
-        Color c = getHint(DiagramHints.KEY_SELECTION_FRAME_COLOR);\r
-        if (c != null)\r
-            return c;\r
-        return Color.BLACK;\r
-    }\r
-\r
-    /**\r
-     * Allows user to cancel box selection operations by invoking the CANCEL\r
-     * command (pressing ESC).\r
-     */\r
-    @EventHandler(priority = 100)\r
-    public boolean handleCancel(CommandEvent e) {\r
-        if (e.command.equals( Commands.CANCEL ) ) {\r
-            setDirty();\r
-            remove();\r
-        }\r
-        return false;\r
-    }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.diagram.participant.pointertool;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.handler.PickContext;
+import org.simantics.g2d.diagram.handler.PickRequest;
+import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;
+import org.simantics.g2d.diagram.participant.Selection;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.participant.KeyUtil;
+import org.simantics.g2d.participant.RenderingQualityInteractor;
+import org.simantics.g2d.participant.TransformUtil;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.events.MouseEvent;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.simantics.scenegraph.g2d.events.command.Commands;
+import org.simantics.scenegraph.g2d.nodes.BoxSelectionNode;
+import org.simantics.scenegraph.utils.Quality;
+
+/**
+ * @author Toni Kalajainen
+ */
+public class BoxSelectionMode extends AbstractMode {
+
+    @Reference  RenderingQualityInteractor quality;
+    @Dependency TransformUtil util;
+    @Dependency Selection selection;
+    @Dependency PickContext pickContext;
+    @Dependency KeyUtil keyUtil;
+
+    public final static BasicStroke STROKE         = new BasicStroke(1.0f);
+
+    public static final int         PAINT_PRIORITY = 30;
+
+    Point2D                         startingPoint;
+    Point2D                         currentPoint;
+    int                             mouseButton;
+    PickPolicy                      boxSelectMode;
+    BoxSelectionNode                node;
+
+    @SGInit
+    public void init(G2DParentNode parent) {
+        if (quality != null)
+            quality.setStaticQuality(Quality.LOW);
+
+        node = parent.getOrCreateNode("" + hashCode(), BoxSelectionNode.class);
+        node.setZIndex(PAINT_PRIORITY);
+        node.setStart(startingPoint);
+        node.setEnd(currentPoint);
+        node.setStroke(STROKE);
+        node.setScaleStroke(true);
+        node.setColor(getToolColor());
+        node.setMouseButton(mouseButton);
+        node.setSelectionListener(new BoxSelectionNode.SelectionListener() {
+            @Override
+            public void onSelect(Rectangle2D rect, int modifiers) {
+                // Disposed?
+                if (isRemoved())
+                    return;
+
+                boolean toggle = (modifiers & MouseEvent.CTRL_MASK) != 0;
+                boolean accumulate = (modifiers & MouseEvent.SHIFT_MASK) != 0;
+
+                Set<IElement> boxSelection = new HashSet<IElement>();
+                PickRequest request = new PickRequest(rect);
+                request.pickPolicy = boxSelectMode;
+                pickContext.pick(diagram, request, boxSelection);
+
+                int selectionId = mouseId;
+                if (toggle) {
+                    selection.toggle(selectionId, boxSelection);
+                } else if (accumulate) {
+                    for (IElement elem : boxSelection)
+                        selection.add(selectionId, elem);
+                } else {
+                    selection.setSelection(selectionId, boxSelection);
+                }
+
+                if (node != null) {
+                    node.remove();
+                    node = null;
+                }
+
+                setDirty();
+                remove();
+            }
+        });
+
+    }
+
+    @SGCleanup
+    public void cleanup() {
+        if (quality != null)
+            quality.setStaticQuality(null);
+        if (node != null) {
+            node.remove();
+            node = null;
+        }
+    }
+
+    public BoxSelectionMode(Point2D startingPoint, Point2D currentPoint, final int mouseId, final int mouseButton, final PickPolicy boxSelectMode) {
+        super(mouseId);
+        this.startingPoint = startingPoint;
+        this.currentPoint = currentPoint;
+        this.mouseButton = mouseButton;
+        this.boxSelectMode = boxSelectMode;
+        //setHint(RenderingQualityInteractor.KEY_QUALITY_INTERACTOR_ENABLED, Boolean.FALSE);
+    }
+
+    public synchronized Color getToolColor() {
+        Color c = getHint(DiagramHints.KEY_SELECTION_FRAME_COLOR);
+        if (c != null)
+            return c;
+        return Color.BLACK;
+    }
+
+    /**
+     * Allows user to cancel box selection operations by invoking the CANCEL
+     * command (pressing ESC).
+     */
+    @EventHandler(priority = 100)
+    public boolean handleCancel(CommandEvent e) {
+        if (e.command.equals( Commands.CANCEL ) ) {
+            setDirty();
+            remove();
+        }
+        return false;
+    }
+
 }
\ No newline at end of file