1 /*******************************************************************************
2 * Copyright (c) 2007, 2017 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 * Semantum Oy - #7119 refactoring
12 *******************************************************************************/
13 package org.simantics.g2d.element.handler.impl;
15 import gnu.trove.map.hash.THashMap;
17 import java.awt.Shape;
18 import java.awt.geom.AffineTransform;
19 import java.util.ArrayList;
20 import java.util.Collection;
23 import org.simantics.g2d.diagram.handler.Topology.Terminal;
24 import org.simantics.g2d.element.IElement;
25 import org.simantics.g2d.element.handler.TerminalLayout;
26 import org.simantics.g2d.element.handler.TerminalTopology;
27 import org.simantics.g2d.utils.geom.DirectionSet;
30 * @author Tuukka Lehtonen
32 public class Terminals implements TerminalLayout, TerminalTopology {
34 private static final long serialVersionUID = -6532093690907028016L;
36 protected final Map<Terminal, ObjectTerminal> terminalMap = new THashMap<>();
37 protected final ArrayList<Terminal> terminals = new ArrayList<>();
39 public Terminals(Collection<ObjectTerminal> ts) {
40 for (ObjectTerminal ti : ts) {
42 terminalMap.put(ti, ti);
47 public AffineTransform getTerminalPosition(IElement node, Terminal t) {
48 ObjectTerminal ti = terminalMap.get(t);
51 return ti.getTransform();
55 public void getTerminals(IElement e, Collection<Terminal> result) {
56 result.addAll(terminals);
60 public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) {
61 ObjectTerminal ti = terminalMap.get(t);
64 directions.addAll(ti.getDirections());
69 public Shape getTerminalShape(IElement node, Terminal t) {
70 ObjectTerminal ti = terminalMap.get(t);
77 public int hashCode() {
78 return terminalMap.hashCode();
82 public boolean equals(Object obj) {
87 if (getClass() != obj.getClass())
89 Terminals other = (Terminals) obj;
90 return terminalMap.equals(other.terminalMap);