001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package visualdebugger.draw2d;
011:
012: import org.eclipse.draw2d.AbstractConnectionAnchor;
013: import org.eclipse.draw2d.IFigure;
014: import org.eclipse.draw2d.ScalableFigure;
015: import org.eclipse.draw2d.geometry.Point;
016: import org.eclipse.draw2d.geometry.PrecisionPoint;
017: import org.eclipse.draw2d.geometry.Rectangle;
018:
019: public class FixedConnectionAnchor extends AbstractConnectionAnchor {
020:
021: public boolean leftToRight = true;
022: public int offsetH;
023: public int offsetV;
024: public boolean topDown = true;
025:
026: public FixedConnectionAnchor(IFigure owner) {
027: super (owner);
028: }
029:
030: /**
031: * @see org.eclipse.draw2d.AbstractConnectionAnchor#ancestorMoved(IFigure)
032: */
033: public void ancestorMoved(IFigure figure) {
034: if (figure instanceof ScalableFigure)
035: return;
036: super .ancestorMoved(figure);
037: }
038:
039: public Point getLocation(Point reference) {
040: Rectangle r = getOwner().getBounds();
041: int x, y;
042: if (topDown)
043: y = r.y + offsetV;
044: else
045: y = r.bottom() - 1 - offsetV;
046:
047: if (leftToRight)
048: x = r.x + offsetH;
049: else
050: x = r.right() - 1 - offsetH;
051:
052: Point p = new PrecisionPoint(x, y);
053: getOwner().translateToAbsolute(p);
054: return p;
055: }
056:
057: public Point getReferencePoint() {
058: return getLocation(null);
059: }
060:
061: /**
062: * @param offsetH
063: * The offsetH to set.
064: */
065: public void setOffsetH(int offsetH) {
066: this .offsetH = offsetH;
067: fireAnchorMoved();
068: }
069:
070: /**
071: * @param offsetV
072: * The offsetV to set.
073: */
074: public void setOffsetV(int offsetV) {
075: this .offsetV = offsetV;
076: fireAnchorMoved();
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see java.lang.Object#equals(java.lang.Object)
083: */
084: public boolean equals(Object o) {
085: if (o instanceof FixedConnectionAnchor) {
086: FixedConnectionAnchor fa = (FixedConnectionAnchor) o;
087:
088: if (fa.leftToRight == this .leftToRight
089: && fa.topDown == this .topDown
090: && fa.offsetH == this .offsetH
091: && fa.offsetV == this .offsetV
092: && fa.getOwner() == this .getOwner()) {
093: return true;
094: }
095: }
096:
097: return false;
098: }
099:
100: /*
101: * (non-Javadoc)
102: *
103: * @see java.lang.Object#hashCode()
104: */
105: public int hashCode() {
106: return ((this .leftToRight ? 31 : 0) + (this .topDown ? 37 : 0)
107: + this .offsetH * 43 + this .offsetV * 47)
108: ^ this.getOwner().hashCode();
109: }
110:
111: }
|