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