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