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 org.simantics.g2d.diagram.handler.Topology.Terminal;
15 import org.simantics.g2d.element.IElement;
16 import org.simantics.g2d.element.handler.TerminalData;
17 import org.simantics.utils.datastructures.hints.HintContext;
18 import org.simantics.utils.datastructures.hints.IHintContext;
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;
20 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
23 * A straight-forward implementation of the {@link TerminalData} element handler
24 * interface. It uses an element's hint context to store a separate HintContext
27 * @author Tuukka Lehtonen
29 public class TerminalDataImpl implements TerminalData {
31 private static final long serialVersionUID = -2131030904280472077L;
33 public static final TerminalDataImpl INSTANCE = new TerminalDataImpl();
35 static class TerminalKey extends KeyOf {
36 private final Terminal terminal;
37 public TerminalKey(Terminal terminal) {
38 super(IHintContext.class);
40 throw new NullPointerException("null terminal");
41 this.terminal = terminal;
44 public int hashCode() {
45 return terminal.hashCode();
48 public boolean equals(Object obj) {
51 if (!(obj instanceof TerminalKey))
53 TerminalKey other = (TerminalKey) obj;
54 return terminal.equals(other.terminal);
57 public String toString() {
58 return "TERMINAL_DATA(" + terminal + ")";
63 public <T> T getHint(IElement e, Terminal t, Key key) {
64 IHintContext context = e.getHint(new TerminalKey(t));
67 return context.getHint(key);
71 public void setHint(IElement e, Terminal t, Key key, Object value) {
72 Key terminalKey = new TerminalKey(t);
73 IHintContext context = e.getHint(terminalKey);
74 if (context == null) {
75 context = new HintContext();
76 e.setHint(terminalKey, context);
78 context.setHint(key, value);