X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felement%2Fhandler%2Fimpl%2FStaticTerminals.java;h=0950e6e8679e4ebc74ad225ea05f9d4404d278a8;hb=refs%2Fchanges%2F38%2F238%2F2;hp=e158fad6d5b23ed607f0621a260dffffbffae2f4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticTerminals.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticTerminals.java index e158fad6d..0950e6e86 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticTerminals.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticTerminals.java @@ -1,111 +1,111 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.element.handler.impl; - -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.simantics.g2d.diagram.handler.Topology.Terminal; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.TerminalLayout; -import org.simantics.g2d.element.handler.TerminalTopology; -import org.simantics.g2d.utils.geom.DirectionSet; -import org.simantics.utils.datastructures.ValueUtils; - -/** - * - * - * Example: - * - * TerminalHandler th = - * StaticTerminals.compile( - * topTerminal, 0.0, -10.0, DirectionSet.N, - * bottomTerminal, 0.0, 10.0, DirectionSet.S, - * leftTerminal, -10.0, 0.0, DirectionSet.W, - * rightTerminal, 20.0, 0.0, DirectionSet.E); - * - * @author Toni Kalajainen - */ -public class StaticTerminals implements TerminalLayout, TerminalTopology { - - private static final long serialVersionUID = -7324592260579191478L; - - /** - * Compile terminal handler with static terminals. - * The xytArray is an varargs array which consists of sequences of - * (terminal, x-position, y-position, DirectionSet). - * - * @param xytArray an array of (x, y, terminal) triples - * @return terminal reference - */ - public static TerminalLayout compile(Object ... xytArray) - { - return new StaticTerminals(xytArray); - } - - private class TerminalImpl implements Terminal { - double x, y; - DirectionSet ds; - Terminal t; - } - - Map terminalMap = new HashMap(); - ArrayList terminals = new ArrayList(); - - StaticTerminals(Object ... xytArray) - { - assert(xytArray.length % 4 == 0); - for (int i=0; i result) { - result.addAll(terminals); - } - - @Override - public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) { - TerminalImpl ti = terminalMap.get(t); - if (ti==null) return false; - directions.addAll(ti.ds); - return true; - } - - @Override - public Shape getTerminalShape(IElement node, Terminal t) { - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.element.handler.impl; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.g2d.diagram.handler.Topology.Terminal; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.TerminalLayout; +import org.simantics.g2d.element.handler.TerminalTopology; +import org.simantics.g2d.utils.geom.DirectionSet; +import org.simantics.utils.datastructures.ValueUtils; + +/** + * + * + * Example: + * + * TerminalHandler th = + * StaticTerminals.compile( + * topTerminal, 0.0, -10.0, DirectionSet.N, + * bottomTerminal, 0.0, 10.0, DirectionSet.S, + * leftTerminal, -10.0, 0.0, DirectionSet.W, + * rightTerminal, 20.0, 0.0, DirectionSet.E); + * + * @author Toni Kalajainen + */ +public class StaticTerminals implements TerminalLayout, TerminalTopology { + + private static final long serialVersionUID = -7324592260579191478L; + + /** + * Compile terminal handler with static terminals. + * The xytArray is an varargs array which consists of sequences of + * (terminal, x-position, y-position, DirectionSet). + * + * @param xytArray an array of (x, y, terminal) triples + * @return terminal reference + */ + public static TerminalLayout compile(Object ... xytArray) + { + return new StaticTerminals(xytArray); + } + + private class TerminalImpl implements Terminal { + double x, y; + DirectionSet ds; + Terminal t; + } + + Map terminalMap = new HashMap(); + ArrayList terminals = new ArrayList(); + + StaticTerminals(Object ... xytArray) + { + assert(xytArray.length % 4 == 0); + for (int i=0; i result) { + result.addAll(terminals); + } + + @Override + public boolean getTerminalDirection(IElement node, Terminal t, DirectionSet directions) { + TerminalImpl ti = terminalMap.get(t); + if (ti==null) return false; + directions.addAll(ti.ds); + return true; + } + + @Override + public Shape getTerminalShape(IElement node, Terminal t) { + return null; + } + +}