]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticTerminals.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / StaticTerminals.java
index e158fad6d5b23ed607f0621a260dffffbffae2f4..0950e6e8679e4ebc74ad225ea05f9d4404d278a8 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.element.handler.impl;\r
-\r
-import java.awt.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.g2d.diagram.handler.Topology.Terminal;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.TerminalLayout;\r
-import org.simantics.g2d.element.handler.TerminalTopology;\r
-import org.simantics.g2d.utils.geom.DirectionSet;\r
-import org.simantics.utils.datastructures.ValueUtils;\r
-\r
-/**\r
- * \r
- * \r
- * Example:\r
- * \r
- *   TerminalHandler th = \r
- *     StaticTerminals.compile(\r
- *             topTerminal,    0.0, -10.0, DirectionSet.N,\r
- *             bottomTerminal, 0.0,  10.0, DirectionSet.S,\r
- *             leftTerminal,  -10.0,  0.0, DirectionSet.W,\r
- *          rightTerminal,  20.0,  0.0, DirectionSet.E);\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class StaticTerminals implements TerminalLayout, TerminalTopology {\r
-\r
-    private static final long serialVersionUID = -7324592260579191478L;\r
-\r
-    /**\r
-        * Compile terminal handler with static terminals.\r
-        * The xytArray is an varargs array which consists of sequences of\r
-        *  (terminal, x-position, y-position, DirectionSet).\r
-        * \r
-        * @param xytArray an array of (x, y, terminal) triples\r
-        * @return terminal reference\r
-        */\r
-       public static TerminalLayout compile(Object ... xytArray)\r
-       {\r
-               return new StaticTerminals(xytArray);\r
-       }\r
-       \r
-       private class TerminalImpl implements Terminal {\r
-               double x, y;\r
-               DirectionSet ds;\r
-               Terminal t;\r
-       }\r
-       \r
-       Map<Terminal, TerminalImpl> terminalMap = new HashMap<Terminal, TerminalImpl>();\r
-       ArrayList<Terminal> terminals = new ArrayList<Terminal>();\r
-       \r
-       StaticTerminals(Object ... xytArray)\r
-       {\r
-               assert(xytArray.length % 4 == 0);\r
-               for (int i=0; i<xytArray.length/4; i++)\r
-               {\r
-                       TerminalImpl ti = new TerminalImpl();\r
-                       ti.t = (Terminal) xytArray[i*4+0];\r
-                       ti.x = ValueUtils.toDoubleScalar( xytArray[i*4+1] );\r
-                       ti.y = ValueUtils.toDoubleScalar( xytArray[i*4+2] );\r
-                       DirectionSet ds = (DirectionSet) xytArray[i*4+3];\r
-                       ti.ds = ds;\r
-                       terminals.add(ti.t);\r
-                       terminalMap.put(ti.t, ti);\r
-               }\r
-       }       \r
-\r
-       @Override\r
-       public AffineTransform getTerminalPosition(IElement node, Terminal t) {\r
-               TerminalImpl ti = terminalMap.get(t);\r
-               if (ti==null) return null;\r
-               AffineTransform result = new AffineTransform();\r
-               result.setToTranslation(ti.x, ti.y);\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public void getTerminals(IElement e, Collection<Terminal> result) {\r
-               result.addAll(terminals);\r
-       }\r
-\r
-       @Override\r
-       public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) {\r
-               TerminalImpl ti = terminalMap.get(t);\r
-               if (ti==null) return false;\r
-               directions.addAll(ti.ds);\r
-               return true;\r
-       }\r
-\r
-       @Override\r
-       public Shape getTerminalShape(IElement node, Terminal t) {\r
-               return null;\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.g2d.element.handler.impl;
+
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.g2d.diagram.handler.Topology.Terminal;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.TerminalLayout;
+import org.simantics.g2d.element.handler.TerminalTopology;
+import org.simantics.g2d.utils.geom.DirectionSet;
+import org.simantics.utils.datastructures.ValueUtils;
+
+/**
+ * 
+ * 
+ * Example:
+ * 
+ *   TerminalHandler th = 
+ *     StaticTerminals.compile(
+ *             topTerminal,    0.0, -10.0, DirectionSet.N,
+ *             bottomTerminal, 0.0,  10.0, DirectionSet.S,
+ *             leftTerminal,  -10.0,  0.0, DirectionSet.W,
+ *          rightTerminal,  20.0,  0.0, DirectionSet.E);
+ * 
+ * @author Toni Kalajainen
+ */
+public class StaticTerminals implements TerminalLayout, TerminalTopology {
+
+    private static final long serialVersionUID = -7324592260579191478L;
+
+    /**
+        * Compile terminal handler with static terminals.
+        * The xytArray is an varargs array which consists of sequences of
+        *  (terminal, x-position, y-position, DirectionSet).
+        * 
+        * @param xytArray an array of (x, y, terminal) triples
+        * @return terminal reference
+        */
+       public static TerminalLayout compile(Object ... xytArray)
+       {
+               return new StaticTerminals(xytArray);
+       }
+       
+       private class TerminalImpl implements Terminal {
+               double x, y;
+               DirectionSet ds;
+               Terminal t;
+       }
+       
+       Map<Terminal, TerminalImpl> terminalMap = new HashMap<Terminal, TerminalImpl>();
+       ArrayList<Terminal> terminals = new ArrayList<Terminal>();
+       
+       StaticTerminals(Object ... xytArray)
+       {
+               assert(xytArray.length % 4 == 0);
+               for (int i=0; i<xytArray.length/4; i++)
+               {
+                       TerminalImpl ti = new TerminalImpl();
+                       ti.t = (Terminal) xytArray[i*4+0];
+                       ti.x = ValueUtils.toDoubleScalar( xytArray[i*4+1] );
+                       ti.y = ValueUtils.toDoubleScalar( xytArray[i*4+2] );
+                       DirectionSet ds = (DirectionSet) xytArray[i*4+3];
+                       ti.ds = ds;
+                       terminals.add(ti.t);
+                       terminalMap.put(ti.t, ti);
+               }
+       }       
+
+       @Override
+       public AffineTransform getTerminalPosition(IElement node, Terminal t) {
+               TerminalImpl ti = terminalMap.get(t);
+               if (ti==null) return null;
+               AffineTransform result = new AffineTransform();
+               result.setToTranslation(ti.x, ti.y);
+               return result;
+       }
+
+       @Override
+       public void getTerminals(IElement e, Collection<Terminal> result) {
+               result.addAll(terminals);
+       }
+
+       @Override
+       public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) {
+               TerminalImpl ti = terminalMap.get(t);
+               if (ti==null) return false;
+               directions.addAll(ti.ds);
+               return true;
+       }
+
+       @Override
+       public Shape getTerminalShape(IElement node, Terminal t) {
+               return null;
+       }
+       
+}