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.connection;
\r
14 import org.simantics.g2d.diagram.handler.Topology.Terminal;
\r
15 import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;
\r
16 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
19 * This hint key is used for representing a terminal within an element that is
\r
20 * connected to an edge. The key is identified by two things: the connected
\r
21 * terminal and a secondary data object that can be used to make the key unique
\r
22 * for an edge in cases where several connections to the same terminal are
\r
23 * possible. A good option is to use the back-end object of the edge element
\r
24 * itself, which naturally makes the key unique for that particular edge.
\r
27 * This key has a counterpart, {@link EndKeyOf} that is used in edge elements to
\r
28 * connect both the {@link EdgeEnd#Begin} and {@link EdgeEnd#End} ends of the
\r
29 * edge to element terminals. To actually represent the connection, you should
\r
30 * give the same value object for this hint pair.
\r
33 * @author Tuukka Lehtonen
\r
35 public class TerminalKeyOf extends KeyOf {
\r
37 private final Terminal terminal;
\r
38 private final Object data;
\r
42 * @param t the terminal this connector hint represents
\r
43 * @param data a secondary data object for making the key unique for a
\r
44 * single edge connected to the specified terminal. Use a
\r
45 * <code>null</code> value only if you consider the terminal to allow
\r
46 * only one connected edge.
\r
47 * @param clazz the allowed class of the value object.
\r
49 public TerminalKeyOf(Terminal t, Object data, Class<?> clazz) {
\r
53 this.hash = t.hashCode() ^ clazz.hashCode();
\r
55 this.hash = this.hash * 31 + data.hashCode();
\r
58 public Terminal getTerminal() {
\r
62 public Object getData() {
\r
67 public int hashCode() {
\r
72 public boolean equals(Object obj) {
\r
75 if (!(obj instanceof TerminalKeyOf))
\r
77 TerminalKeyOf other = (TerminalKeyOf) obj;
\r
78 if (!terminal.equals(other.terminal))
\r
80 return (data == null) ? other.data == null : data.equals(other.data);
\r
84 public String toString() {
\r
85 return getClass().getSimpleName() + "[terminal=" + terminal + ", data=" + data + "]";
\r