]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DiagramSelection.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / handler / DiagramSelection.java
index d304dc279e132f53f824ad00a3e095636be0228f..ed4b75944fc72855e33f67024651e9f0e81aee8a 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.diagram.handler;\r
-\r
-import java.awt.geom.Point2D;\r
-import java.lang.ref.WeakReference;\r
-import java.util.Collections;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.utils.strings.EString;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class DiagramSelection {\r
-\r
-    public static final DiagramSelection EMPTY = new DiagramSelection((Resource) null);\r
-\r
-    // Reference may be null\r
-    private final WeakReference<ICanvasContext> sourceCanvas;\r
-    private final Resource source;\r
-\r
-    /**\r
-     * May be empty or at least invalid after the source canvas no longer\r
-     * exists. Should not be used for anything besides visualisation.\r
-     */\r
-    private transient final Set<IElement> elements;\r
-\r
-    private final ElementObjectAssortment assortment;\r
-    private final boolean cut;\r
-    private final Point2D copyPos;\r
-\r
-    private DiagramSelection(Resource source) {\r
-        this.sourceCanvas = null;\r
-        this.source = source;\r
-        this.elements = Collections.emptySet();\r
-        this.assortment = ElementObjectAssortment.fromElements(elements);\r
-        this.cut = false;\r
-        this.copyPos = new Point2D.Double();\r
-    }\r
-\r
-    public DiagramSelection(ICanvasContext sourceCanvas, Resource source, Set<IElement> elements, boolean cut, Point2D copyPos) {\r
-        assert source != null;\r
-        assert elements != null;\r
-\r
-        this.sourceCanvas = new WeakReference<ICanvasContext>(sourceCanvas);\r
-        this.source = source;\r
-        this.elements = Collections.unmodifiableSet(elements);\r
-        this.assortment = ElementObjectAssortment.fromElements(elements);\r
-        this.cut = cut;\r
-        this.copyPos = copyPos;\r
-    }\r
-\r
-    /**\r
-     * @return <code>null</code> if the source canvas has already been disposed.\r
-     */\r
-    public ICanvasContext getSourceCanvas() {\r
-        ICanvasContext ctx = sourceCanvas == null ? null : sourceCanvas.get();\r
-        return ctx == null ? null : ctx.isDisposed() ? null : ctx;\r
-    }\r
-\r
-    public boolean isFromCanvasContext(ICanvasContext ctx) {\r
-        ICanvasContext srcCtx = getSourceCanvas();\r
-        return ctx != null && ctx == srcCtx;\r
-    }\r
-\r
-    public Resource getSourceDiagram() {\r
-        return source;\r
-    }\r
-\r
-    public boolean isCut() {\r
-        return cut;\r
-    }\r
-\r
-    public Point2D getCopyPos() {\r
-        return copyPos;\r
-    }\r
-\r
-    public Set<IElement> getOriginalElements() {\r
-        return elements;\r
-    }\r
-\r
-    public ElementObjectAssortment getAssortment() {\r
-        return assortment;\r
-    }\r
-\r
-    public boolean isEmpty() {\r
-        return getAssortment().isEmpty();\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        StringBuilder sb = new StringBuilder();\r
-        sb.append("Diagram selection of ");\r
-        sb.append(elements.size());\r
-        sb.append(" element(s) ");\r
-        if (cut)\r
-            sb.append("cut");\r
-        else\r
-            sb.append("copied");\r
-        sb.append(" from ");\r
-        sb.append(source);\r
-        sb.append(" with reference position ");\r
-        sb.append(copyPos);\r
-        if (elements != null && !elements.isEmpty()) {\r
-            sb.append(":\n");\r
-            String elems = EString.implode(elements, "\n");\r
-            if (elems != null)\r
-                sb.append(EString.addPrefix(elems, "\t"));\r
-        }\r
-        if (assortment != null && !assortment.isEmpty()) {\r
-            sb.append(assortment.toString());\r
-        }\r
-        return sb.toString();\r
-    }\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.diagram.handler;
+
+import java.awt.geom.Point2D;
+import java.lang.ref.WeakReference;
+import java.util.Collections;
+import java.util.Set;
+
+import org.simantics.db.Resource;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.element.IElement;
+import org.simantics.utils.strings.EString;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class DiagramSelection {
+
+    public static final DiagramSelection EMPTY = new DiagramSelection((Resource) null);
+
+    // Reference may be null
+    private final WeakReference<ICanvasContext> sourceCanvas;
+    private final Resource source;
+
+    /**
+     * May be empty or at least invalid after the source canvas no longer
+     * exists. Should not be used for anything besides visualisation.
+     */
+    private transient final Set<IElement> elements;
+
+    private final ElementObjectAssortment assortment;
+    private final boolean cut;
+    private final Point2D copyPos;
+
+    private DiagramSelection(Resource source) {
+        this.sourceCanvas = null;
+        this.source = source;
+        this.elements = Collections.emptySet();
+        this.assortment = ElementObjectAssortment.fromElements(elements);
+        this.cut = false;
+        this.copyPos = new Point2D.Double();
+    }
+
+    public DiagramSelection(ICanvasContext sourceCanvas, Resource source, Set<IElement> elements, boolean cut, Point2D copyPos) {
+        assert source != null;
+        assert elements != null;
+
+        this.sourceCanvas = new WeakReference<ICanvasContext>(sourceCanvas);
+        this.source = source;
+        this.elements = Collections.unmodifiableSet(elements);
+        this.assortment = ElementObjectAssortment.fromElements(elements);
+        this.cut = cut;
+        this.copyPos = copyPos;
+    }
+
+    /**
+     * @return <code>null</code> if the source canvas has already been disposed.
+     */
+    public ICanvasContext getSourceCanvas() {
+        ICanvasContext ctx = sourceCanvas == null ? null : sourceCanvas.get();
+        return ctx == null ? null : ctx.isDisposed() ? null : ctx;
+    }
+
+    public boolean isFromCanvasContext(ICanvasContext ctx) {
+        ICanvasContext srcCtx = getSourceCanvas();
+        return ctx != null && ctx == srcCtx;
+    }
+
+    public Resource getSourceDiagram() {
+        return source;
+    }
+
+    public boolean isCut() {
+        return cut;
+    }
+
+    public Point2D getCopyPos() {
+        return copyPos;
+    }
+
+    public Set<IElement> getOriginalElements() {
+        return elements;
+    }
+
+    public ElementObjectAssortment getAssortment() {
+        return assortment;
+    }
+
+    public boolean isEmpty() {
+        return getAssortment().isEmpty();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("Diagram selection of ");
+        sb.append(elements.size());
+        sb.append(" element(s) ");
+        if (cut)
+            sb.append("cut");
+        else
+            sb.append("copied");
+        sb.append(" from ");
+        sb.append(source);
+        sb.append(" with reference position ");
+        sb.append(copyPos);
+        if (elements != null && !elements.isEmpty()) {
+            sb.append(":\n");
+            String elems = EString.implode(elements, "\n");
+            if (elems != null)
+                sb.append(EString.addPrefix(elems, "\t"));
+        }
+        if (assortment != null && !assortment.isEmpty()) {
+            sb.append(assortment.toString());
+        }
+        return sb.toString();
+    }
+}
+