1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.element.handler.impl;
\r
14 import gnu.trove.map.hash.THashMap;
\r
16 import java.awt.Shape;
\r
17 import java.awt.geom.AffineTransform;
\r
18 import java.util.ArrayList;
\r
19 import java.util.Collection;
\r
20 import java.util.Map;
\r
22 import org.simantics.g2d.diagram.handler.Topology.Terminal;
\r
23 import org.simantics.g2d.element.IElement;
\r
24 import org.simantics.g2d.element.handler.TerminalLayout;
\r
25 import org.simantics.g2d.element.handler.TerminalTopology;
\r
26 import org.simantics.g2d.utils.geom.DirectionSet;
\r
29 * @author Tuukka Lehtonen
\r
31 public class Terminals implements TerminalLayout, TerminalTopology {
\r
33 private static final long serialVersionUID = -6532093690907028016L;
\r
35 private final Map<Terminal, ObjectTerminal> terminalMap = new THashMap<Terminal, ObjectTerminal>();
\r
36 private final ArrayList<Terminal> terminals = new ArrayList<Terminal>();
\r
38 public Terminals(Collection<ObjectTerminal> ts) {
\r
39 for (ObjectTerminal ti : ts) {
\r
41 terminalMap.put(ti, ti);
\r
46 public AffineTransform getTerminalPosition(IElement node, Terminal t) {
\r
47 ObjectTerminal ti = terminalMap.get(t);
\r
50 return new AffineTransform(ti.getTransform());
\r
54 public void getTerminals(IElement e, Collection<Terminal> result) {
\r
55 result.addAll(terminals);
\r
59 public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) {
\r
60 ObjectTerminal ti = terminalMap.get(t);
\r
63 directions.addAll(ti.getDirections());
\r
68 public Shape getTerminalShape(IElement node, Terminal t) {
\r
69 ObjectTerminal ti = terminalMap.get(t);
\r
72 return ti.getShape();
\r
76 public int hashCode() {
\r
77 return terminalMap.hashCode();
\r
81 public boolean equals(Object obj) {
\r
86 if (getClass() != obj.getClass())
\r
88 Terminals other = (Terminals) obj;
\r
89 return terminalMap.equals(other.terminalMap);
\r