]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/valve/ValveClass.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / valve / ValveClass.java
index 9fcfb371ac6d1b12f623cd68f8c2ee7af8378b30..dff7069bec8213d284d2588f079e57218fbafe42 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
-/*******************************************************************************\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.elementclass.valve;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.Stroke;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.SceneGraphNodeKey;\r
-import org.simantics.g2d.element.handler.LifeCycle;\r
-import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.element.handler.Stateful;\r
-import org.simantics.g2d.element.handler.Clickable.PressStatus;\r
-import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
-import org.simantics.g2d.element.handler.impl.ElementShapeImpl;\r
-import org.simantics.g2d.element.handler.impl.FillColorImpl;\r
-import org.simantics.g2d.element.handler.impl.FixedSize;\r
-import org.simantics.g2d.elementclass.slider.SliderColorProfile;\r
-import org.simantics.g2d.elementclass.slider.SliderHandle;\r
-import org.simantics.g2d.utils.PathUtils;\r
-import org.simantics.scenegraph.Node;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-\r
-/**\r
- * @author Toni Kalajainen\r
- */\r
-public class ValveClass {\r
-\r
-    static final double M = 3;\r
-    public static final Stroke STROKE = new BasicStroke(1.5f);\r
-    public static final Stroke STROKE2 = new BasicStroke(1.f);\r
-    public static final Path2D SHAPE = PathUtils.closedPath(-30*M,20*M, -30*M,-20*M, 0,-7*M, 30*M,-20*M, 30*M,20*M, 0,7*M);\r
-    public static final Path2D WHITE_LINE = PathUtils.path(-30*M,20*M, -30*M,-20*M, 0,-7*M, 30*M,-20*M);\r
-    public static final Path2D BLACK_LINE = PathUtils.path(30*M,-20*M, 30*M,20*M, 0,7*M, -30*M,20*M);\r
-    public final static Rectangle2D TRACK_RECT = new Rectangle2D.Double(-27*M, -5*M, 54*M, 10*M);\r
-    public static final Path2D TRACK_WHITE = PathUtils.path(-27*M,5*M, -27*M,-5*M, 27*M,-5*M);\r
-    public static final Path2D TRACK_BLACK = PathUtils.path(27*M,-5*M, 27*M,5*M, -27*M,5*M);\r
-\r
-    public static ElementClass INSTANCE =\r
-        ElementClass.compile(\r
-                new ValvePainter(),\r
-                new ValveHandle(),\r
-                FillColorImpl.handlerOf(new Color(150, 150, 180)),\r
-                //Clickable.INSTANCE,\r
-                Stateful.ENABLED_BY_DEFAULT,\r
-                DefaultTransform.INSTANCE,\r
-                ElementShapeImpl.shapeOf(SHAPE),\r
-                FixedSize.of(SHAPE.getBounds2D())\r
-        );\r
-\r
-    public static class ValveHandle extends SliderHandle implements LifeCycle {\r
-        private static final long serialVersionUID = 5605597689550675532L;\r
-        @Override\r
-        protected Rectangle2D getBounds(IElement e) {\r
-            return TRACK_RECT;\r
-        }\r
-\r
-        @Override\r
-        protected double getHandleWidth(IElement e) {\r
-            return super.getHandleWidth(e);\r
-        }\r
-\r
-        @Override\r
-        public void onElementActivated(IDiagram d, IElement e) {\r
-        }\r
-        @Override\r
-        public void onElementCreated(IElement e) {\r
-            e.setHint(SliderHandle.KEY_SLIDER_COLOR_PROFILE, SliderColorProfile.DEFAULT);\r
-            e.setHint(SliderHandle.KEY_SLIDER_POSITION, 50.0);\r
-            e.setHint(SliderHandle.KEY_SLIDER_MIN_VALUE, 0.0);\r
-            e.setHint(SliderHandle.KEY_SLIDER_MAX_VALUE, 100.0);\r
-        }\r
-        @Override\r
-        public void onElementDeactivated(IDiagram d, IElement e) {\r
-        }\r
-        @Override\r
-        public void onElementDestroyed(IElement e) {\r
-        }\r
-\r
-    }\r
-\r
-\r
-    private static class ValvePainter implements SceneGraph {\r
-        /**\r
-         * \r
-         */\r
-        private static final long serialVersionUID = -434582053817033874L;\r
-        public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");\r
-\r
-        @Override\r
-        public void cleanup(IElement e) {\r
-            Node node = e.removeHint(SG_NODE);\r
-            if (node != null)\r
-                node.remove();\r
-        }\r
-\r
-        @Override\r
-        public void init(IElement e, G2DParentNode parent) {\r
-            G2DParentNode node = (G2DParentNode) e.getHint(SG_NODE);\r
-            if (node == null) {\r
-                node = parent.addNode(G2DParentNode.class);\r
-                e.setHint(SG_NODE, node);\r
-            }\r
-            Color                      fc              = ElementUtils.getFillColor(e);\r
-            PressStatus        press   = null;//ElementUtils.getPressStatus(e, ctx); // FIXME: scenegraph does not support context\r
-                       AffineTransform at      = ElementUtils.getTransform(e);\r
-                       if(at != null) node.setTransform(at);\r
-\r
-            ShapeNode shape1 = node.getOrCreateNode("shape1", ShapeNode.class);\r
-            shape1.setStroke(STROKE);\r
-            shape1.setColor(fc);\r
-            shape1.setFill(true);\r
-            shape1.setShape(SHAPE);\r
-\r
-            ShapeNode shape_press1 = node.getOrCreateNode("shape_press1", ShapeNode.class);\r
-            ShapeNode shape_press2 = node.getOrCreateNode("shape_press2", ShapeNode.class);\r
-\r
-            if (press==null || press==PressStatus.NORMAL || press == PressStatus.HOVER) {\r
-                shape_press1.setColor(Color.WHITE);\r
-                shape_press1.setShape(WHITE_LINE);\r
-                shape_press2.setColor(Color.BLACK);\r
-                shape_press2.setShape(BLACK_LINE);\r
-            } else if (press==PressStatus.PRESSED) {\r
-                shape_press1.setColor(Color.BLACK);\r
-                shape_press1.setShape(WHITE_LINE);\r
-                shape_press2.setColor(Color.WHITE);\r
-                shape_press2.setShape(BLACK_LINE);\r
-            } else if (press==PressStatus.HELD) {\r
-                shape_press1.setColor(new Color(50, 50, 50));\r
-                shape_press1.setShape(WHITE_LINE);\r
-                shape_press2.setColor(new Color(240, 240, 240));\r
-                shape_press2.setShape(BLACK_LINE);\r
-            }\r
-\r
-            ShapeNode shape2 = node.getOrCreateNode("shape2", ShapeNode.class);\r
-            shape2.setStroke(STROKE2);\r
-            shape2.setColor(Color.BLACK);\r
-            shape2.setShape(TRACK_BLACK);\r
-\r
-            ShapeNode shape3 = node.getOrCreateNode("shape3", ShapeNode.class);\r
-            shape3.setStroke(STROKE2);\r
-            shape3.setColor(Color.WHITE);\r
-            shape3.setShape(TRACK_WHITE);\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
+ *******************************************************************************/
+/*******************************************************************************
+ * 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.elementclass.valve;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Stroke;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.SceneGraphNodeKey;
+import org.simantics.g2d.element.handler.LifeCycle;
+import org.simantics.g2d.element.handler.SceneGraph;
+import org.simantics.g2d.element.handler.Stateful;
+import org.simantics.g2d.element.handler.Clickable.PressStatus;
+import org.simantics.g2d.element.handler.impl.DefaultTransform;
+import org.simantics.g2d.element.handler.impl.ElementShapeImpl;
+import org.simantics.g2d.element.handler.impl.FillColorImpl;
+import org.simantics.g2d.element.handler.impl.FixedSize;
+import org.simantics.g2d.elementclass.slider.SliderColorProfile;
+import org.simantics.g2d.elementclass.slider.SliderHandle;
+import org.simantics.g2d.utils.PathUtils;
+import org.simantics.scenegraph.Node;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+
+/**
+ * @author Toni Kalajainen
+ */
+public class ValveClass {
+
+    static final double M = 3;
+    public static final Stroke STROKE = new BasicStroke(1.5f);
+    public static final Stroke STROKE2 = new BasicStroke(1.f);
+    public static final Path2D SHAPE = PathUtils.closedPath(-30*M,20*M, -30*M,-20*M, 0,-7*M, 30*M,-20*M, 30*M,20*M, 0,7*M);
+    public static final Path2D WHITE_LINE = PathUtils.path(-30*M,20*M, -30*M,-20*M, 0,-7*M, 30*M,-20*M);
+    public static final Path2D BLACK_LINE = PathUtils.path(30*M,-20*M, 30*M,20*M, 0,7*M, -30*M,20*M);
+    public final static Rectangle2D TRACK_RECT = new Rectangle2D.Double(-27*M, -5*M, 54*M, 10*M);
+    public static final Path2D TRACK_WHITE = PathUtils.path(-27*M,5*M, -27*M,-5*M, 27*M,-5*M);
+    public static final Path2D TRACK_BLACK = PathUtils.path(27*M,-5*M, 27*M,5*M, -27*M,5*M);
+
+    public static ElementClass INSTANCE =
+        ElementClass.compile(
+                new ValvePainter(),
+                new ValveHandle(),
+                FillColorImpl.handlerOf(new Color(150, 150, 180)),
+                //Clickable.INSTANCE,
+                Stateful.ENABLED_BY_DEFAULT,
+                DefaultTransform.INSTANCE,
+                ElementShapeImpl.shapeOf(SHAPE),
+                FixedSize.of(SHAPE.getBounds2D())
+        );
+
+    public static class ValveHandle extends SliderHandle implements LifeCycle {
+        private static final long serialVersionUID = 5605597689550675532L;
+        @Override
+        protected Rectangle2D getBounds(IElement e) {
+            return TRACK_RECT;
+        }
+
+        @Override
+        protected double getHandleWidth(IElement e) {
+            return super.getHandleWidth(e);
+        }
+
+        @Override
+        public void onElementActivated(IDiagram d, IElement e) {
+        }
+        @Override
+        public void onElementCreated(IElement e) {
+            e.setHint(SliderHandle.KEY_SLIDER_COLOR_PROFILE, SliderColorProfile.DEFAULT);
+            e.setHint(SliderHandle.KEY_SLIDER_POSITION, 50.0);
+            e.setHint(SliderHandle.KEY_SLIDER_MIN_VALUE, 0.0);
+            e.setHint(SliderHandle.KEY_SLIDER_MAX_VALUE, 100.0);
+        }
+        @Override
+        public void onElementDeactivated(IDiagram d, IElement e) {
+        }
+        @Override
+        public void onElementDestroyed(IElement e) {
+        }
+
+    }
+
+
+    private static class ValvePainter implements SceneGraph {
+        /**
+         * 
+         */
+        private static final long serialVersionUID = -434582053817033874L;
+        public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
+
+        @Override
+        public void cleanup(IElement e) {
+            Node node = e.removeHint(SG_NODE);
+            if (node != null)
+                node.remove();
+        }
+
+        @Override
+        public void init(IElement e, G2DParentNode parent) {
+            G2DParentNode node = (G2DParentNode) e.getHint(SG_NODE);
+            if (node == null) {
+                node = parent.addNode(G2DParentNode.class);
+                e.setHint(SG_NODE, node);
+            }
+            Color                      fc              = ElementUtils.getFillColor(e);
+            PressStatus        press   = null;//ElementUtils.getPressStatus(e, ctx); // FIXME: scenegraph does not support context
+                       AffineTransform at      = ElementUtils.getTransform(e);
+                       if(at != null) node.setTransform(at);
+
+            ShapeNode shape1 = node.getOrCreateNode("shape1", ShapeNode.class);
+            shape1.setStroke(STROKE);
+            shape1.setColor(fc);
+            shape1.setFill(true);
+            shape1.setShape(SHAPE);
+
+            ShapeNode shape_press1 = node.getOrCreateNode("shape_press1", ShapeNode.class);
+            ShapeNode shape_press2 = node.getOrCreateNode("shape_press2", ShapeNode.class);
+
+            if (press==null || press==PressStatus.NORMAL || press == PressStatus.HOVER) {
+                shape_press1.setColor(Color.WHITE);
+                shape_press1.setShape(WHITE_LINE);
+                shape_press2.setColor(Color.BLACK);
+                shape_press2.setShape(BLACK_LINE);
+            } else if (press==PressStatus.PRESSED) {
+                shape_press1.setColor(Color.BLACK);
+                shape_press1.setShape(WHITE_LINE);
+                shape_press2.setColor(Color.WHITE);
+                shape_press2.setShape(BLACK_LINE);
+            } else if (press==PressStatus.HELD) {
+                shape_press1.setColor(new Color(50, 50, 50));
+                shape_press1.setShape(WHITE_LINE);
+                shape_press2.setColor(new Color(240, 240, 240));
+                shape_press2.setShape(BLACK_LINE);
+            }
+
+            ShapeNode shape2 = node.getOrCreateNode("shape2", ShapeNode.class);
+            shape2.setStroke(STROKE2);
+            shape2.setColor(Color.BLACK);
+            shape2.setShape(TRACK_BLACK);
+
+            ShapeNode shape3 = node.getOrCreateNode("shape3", ShapeNode.class);
+            shape3.setStroke(STROKE2);
+            shape3.setColor(Color.WHITE);
+            shape3.setShape(TRACK_WHITE);
+        }
+    }
+}