001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo;
021:
022: import com.nwoods.jgo.JGoPort;
023: import com.nwoods.jgo.JGoView;
024: import org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo.AbstractCanvasLink.NodeYChangeListener;
025:
026: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasTreeToTreeLink;
027: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasView;
028: import org.netbeans.modules.soa.mapper.common.basicmapper.tree.IMapperTreeNode;
029: import org.netbeans.modules.soa.mapper.common.IMapperLink;
030:
031: /**
032: * <p>
033: *
034: * Title: </p> <p>
035: *
036: * Description: </p> BasicCanvasTreeToTreeLink provides basic implementation of
037: * ICanvasTreeToTreeLink <p>
038: *
039: * Copyright: Copyright (c) 2002 </p> <p>
040: *
041: * Company: </p>
042: *
043: * @author unascribed
044: * @created January 2, 2003
045: * @version 1.0
046: */
047: public class BasicCanvasTreeToTreeLink extends AbstractCanvasLink
048: implements ICanvasTreeToTreeLink {
049:
050: /**
051: * the start node y change listener
052: */
053: private NodeYChangeListener endYListener;
054:
055: /**
056: * the end node y change listener
057: */
058: private NodeYChangeListener startYListener;
059:
060: /**
061: * Creates a new BasicCanvasTreeToTreeLink object.
062: *
063: * @param link the mapper link
064: */
065: public BasicCanvasTreeToTreeLink(IMapperLink link) {
066: super (link);
067: this .setRelinkable(false);
068: this .setOrthogonal(true);
069:
070: startPort = new BasicCanvasPort();
071: startPort.setDraggable(false);
072: startPort.setSelectable(false);
073: startPort.setStyle(JGoPort.StyleHidden);
074: this .setFromPort(startPort);
075:
076: endPort = new BasicCanvasPort();
077: endPort.setDraggable(false);
078: endPort.setSelectable(false);
079: endPort.setStyle(JGoPort.StyleHidden);
080: this .setToPort(endPort);
081: }
082:
083: /**
084: * Return the tree node repersetns the end point of this link.
085: *
086: * @return the tree node repersetns the end point of this link.
087: */
088: public IMapperTreeNode getDestTreeAddress() {
089: return (IMapperTreeNode) getMapperLink().getEndNode();
090: }
091:
092: /**
093: * Return the tree node repersetns the start point of this link.
094: *
095: * @return the tree node repersetns the start point of this link.
096: */
097: public IMapperTreeNode getSourceTreeAddress() {
098: return (IMapperTreeNode) getMapperLink().getStartNode();
099: }
100:
101: /**
102: * Set the canvas contains this canvas node.
103: *
104: * @param canvas the canvas contains this canvas node.
105: */
106: public void setMapperCanvas(ICanvasView canvas) {
107: super .setMapperCanvas(canvas);
108:
109: if (canvas instanceof BasicCanvasView) {
110: startPort.setLeft(((BasicCanvasView) canvas)
111: .getTreeLinkFromPortX());
112: endPort.setLeft(((BasicCanvasView) canvas)
113: .getTreeLinkToPortX());
114:
115: IMapperLink link = getMapperLink();
116: startPort.setTop(link.getStartNode().getY()
117: + NodeYChangeListener.Y_AXIS_DIFF
118: + ((JGoView) canvas).getViewPosition().y);
119: link.getStartNode()
120: .addPropertyChangeListener(
121: new NodeYChangeListener((JGoView) canvas,
122: startPort));
123: endPort.setTop(link.getEndNode().getY()
124: + NodeYChangeListener.Y_AXIS_DIFF
125: + ((JGoView) canvas).getViewPosition().y);
126: link.getEndNode().addPropertyChangeListener(
127: new NodeYChangeListener((JGoView) canvas, endPort));
128: }
129: }
130:
131: protected int getMidOrthoPosition(int from, int to, boolean vertical) {
132: int result;
133: if (mPosition > 0) {
134: int newPos = from + (mPosition * 6);
135: result = newPos;
136: } else {
137: result = super.getMidOrthoPosition(from, to, vertical);
138: }
139: return result;
140: }
141: }
|