-/*******************************************************************************\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 gnu.trove.map.hash.THashMap;\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.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
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class Terminals implements TerminalLayout, TerminalTopology {\r
-\r
- private static final long serialVersionUID = -6532093690907028016L;\r
-\r
- private final Map<Terminal, ObjectTerminal> terminalMap = new THashMap<Terminal, ObjectTerminal>();\r
- private final ArrayList<Terminal> terminals = new ArrayList<Terminal>();\r
-\r
- public Terminals(Collection<ObjectTerminal> ts) {\r
- for (ObjectTerminal ti : ts) {\r
- terminals.add(ti);\r
- terminalMap.put(ti, ti);\r
- }\r
- }\r
-\r
- @Override\r
- public AffineTransform getTerminalPosition(IElement node, Terminal t) {\r
- ObjectTerminal ti = terminalMap.get(t);\r
- if (ti == null)\r
- return null;\r
- return new AffineTransform(ti.getTransform());\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
- ObjectTerminal ti = terminalMap.get(t);\r
- if (ti == null)\r
- return false;\r
- directions.addAll(ti.getDirections());\r
- return true;\r
- }\r
-\r
- @Override\r
- public Shape getTerminalShape(IElement node, Terminal t) {\r
- ObjectTerminal ti = terminalMap.get(t);\r
- if (ti == null)\r
- return null;\r
- return ti.getShape();\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return terminalMap.hashCode();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Terminals other = (Terminals) obj;\r
- return terminalMap.equals(other.terminalMap);\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2017 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
+ * Semantum Oy - #7119 refactoring
+ *******************************************************************************/
+package org.simantics.g2d.element.handler.impl;
+
+import gnu.trove.map.hash.THashMap;
+
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+import java.util.Collection;
+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;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class Terminals implements TerminalLayout, TerminalTopology {
+
+ private static final long serialVersionUID = -6532093690907028016L;
+
+ protected final Map<Terminal, ObjectTerminal> terminalMap = new THashMap<>();
+ protected final ArrayList<Terminal> terminals = new ArrayList<>();
+
+ public Terminals(Collection<ObjectTerminal> ts) {
+ for (ObjectTerminal ti : ts) {
+ terminals.add(ti);
+ terminalMap.put(ti, ti);
+ }
+ }
+
+ @Override
+ public AffineTransform getTerminalPosition(IElement node, Terminal t) {
+ ObjectTerminal ti = terminalMap.get(t);
+ if (ti == null)
+ return null;
+ return ti.getTransform();
+ }
+
+ @Override
+ public void getTerminals(IElement e, Collection<Terminal> result) {
+ result.addAll(terminals);
+ }
+
+ @Override
+ public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) {
+ ObjectTerminal ti = terminalMap.get(t);
+ if (ti == null)
+ return false;
+ directions.addAll(ti.getDirections());
+ return true;
+ }
+
+ @Override
+ public Shape getTerminalShape(IElement node, Terminal t) {
+ ObjectTerminal ti = terminalMap.get(t);
+ if (ti == null)
+ return null;
+ return ti.getShape();
+ }
+
+ @Override
+ public int hashCode() {
+ return terminalMap.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Terminals other = (Terminals) obj;
+ return terminalMap.equals(other.terminalMap);
+ }
+
}
\ No newline at end of file