Author: DartPeng
Date: 2009-08-19 05:52:48 -0400 (Wed, 19 Aug 2009)
New Revision: 17153
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/LeftOrRightAnchor.java
Log:
JBIDE-4648
change the ConnectionAnchor
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java 2009-08-19
09:47:48 UTC (rev 17152)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java 2009-08-19
09:52:48 UTC (rev 17153)
@@ -4,22 +4,20 @@
package org.jboss.tools.smooks.gef.tree.editparts;
import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.ConnectionLocator;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ManhattanConnectionRouter;
-import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
import org.jboss.tools.smooks.gef.tree.editpolicy.TreeNodeConnectionEditPolicy;
import org.jboss.tools.smooks.gef.tree.editpolicy.TreeNodeEndpointEditPolicy;
-import org.jboss.tools.smooks.gef.tree.model.TreeContainerModel;
-import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
+import org.jboss.tools.smooks.gef.tree.figures.LeftOrRightAnchor;
/**
* @author DartPeng
@@ -39,21 +37,22 @@
}
public IFigure createFigure() {
- TreeNodeConnection model = (TreeNodeConnection) getModel();
- AbstractSmooksGraphicalModel sourceModel = model.getSourceNode();
- AbstractSmooksGraphicalModel targetModel = model.getTargetNode();
- PolylineConnection connection1 = new PolylineConnection() {
- @Override
- public void paintFigure(Graphics graphics) {
- graphics.setAlpha(alpha);
- super.paintFigure(graphics);
- }
- };
- if (sourceModel instanceof TreeContainerModel || targetModel instanceof
TreeContainerModel) {
- // connection1.setConnectionRouter(new ManhattanConnectionRouter());
- connection1.setTargetDecoration(new PolygonDecoration());
- return connection1;
- }
+// TreeNodeConnection model = (TreeNodeConnection) getModel();
+// AbstractSmooksGraphicalModel sourceModel = model.getSourceNode();
+// AbstractSmooksGraphicalModel targetModel = model.getTargetNode();
+// PolylineConnection connection1 = new PolylineConnection() {
+// @Override
+// public void paintFigure(Graphics graphics) {
+// graphics.setAlpha(alpha);
+// super.paintFigure(graphics);
+// }
+// };
+ // if (sourceModel instanceof TreeContainerModel || targetModel
+ // instanceof TreeContainerModel) {
+ // // connection1.setConnectionRouter(new ManhattanConnectionRouter());
+ // connection1.setTargetDecoration(new PolygonDecoration());
+ // return connection1;
+ // }
PolylineConnection connection = new PolylineConnection() {
@Override
@@ -63,12 +62,36 @@
}
public PointList getPoints() {
+ ConnectionAnchor sourceAnchor = getSourceConnectionAnchor();
+ ConnectionAnchor targetAnchor = getTargetConnectionAnchor();
+ boolean startLeft = false;
+ if (sourceAnchor instanceof LeftOrRightAnchor) {
+ ((LeftOrRightAnchor) sourceAnchor).getLocation(targetAnchor.getReferencePoint());
+ startLeft = ((LeftOrRightAnchor) sourceAnchor).isLeft();
+ }
+
+ boolean targetLeft = false;
+ if (targetAnchor instanceof LeftOrRightAnchor) {
+ ((LeftOrRightAnchor) targetAnchor).getLocation(sourceAnchor.getReferencePoint());
+ targetLeft = ((LeftOrRightAnchor) targetAnchor).isLeft();
+ }
+
PointList list = super.getPoints();
- if(list.size() == 0) return list;
+ if (list.size() == 0)
+ return list;
Point start = getStart();
- Point start2 = new Point(start.x + 20, start.y);
+ int slength = 20;
+ int tlength = 20;
+ if (startLeft) {
+ slength = (-slength);
+ }
+ if (targetLeft) {
+ tlength = (-tlength);
+ }
+
+ Point start2 = new Point(start.x + slength, start.y);
Point end = getEnd();
- Point end2 = new Point(end.x - 20, end.y);
+ Point end2 = new Point(end.x + tlength, end.y);
list.removeAllPoints();
list.addPoint(start);
list.addPoint(start2);
@@ -86,18 +109,45 @@
*/
@Override
public void paint(Graphics graphics) {
+
+ ConnectionAnchor sourceAnchor = getSourceConnectionAnchor();
+ ConnectionAnchor targetAnchor = getTargetConnectionAnchor();
+ // boolean startLeft = false;
+ // if(sourceAnchor instanceof LeftOrRightAnchor){
+ // ((LeftOrRightAnchor)sourceAnchor).getLocation(targetAnchor.getReferencePoint());
+ // startLeft = ((LeftOrRightAnchor)sourceAnchor).isLeft();
+ // }
+ boolean targetLeft = false;
+ if (targetAnchor instanceof LeftOrRightAnchor) {
+ ((LeftOrRightAnchor) targetAnchor).getLocation(sourceAnchor.getReferencePoint());
+ targetLeft = ((LeftOrRightAnchor) targetAnchor).isLeft();
+ }
+
graphics.pushState();
graphics.setBackgroundColor(ColorConstants.button);
- Point p = this.getBounds().getTopLeft();
- Point p2 = this.getBounds().getBottomLeft();
- Point p3 = this.getBounds().getTopRight();
- p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
- PointList pointList = new PointList();
- pointList.addPoint(p);
- pointList.addPoint(p2.x, p2.y - 1);
- pointList.addPoint(p3);
- graphics.fillPolygon(pointList);
- graphics.drawPolygon(pointList);
+ if (targetLeft) {
+ Point p = this.getBounds().getTopLeft();
+ Point p2 = this.getBounds().getBottomLeft();
+ Point p3 = this.getBounds().getTopRight();
+ p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
+ PointList pointList = new PointList();
+ pointList.addPoint(p);
+ pointList.addPoint(p2.x, p2.y - 1);
+ pointList.addPoint(p3);
+ graphics.fillPolygon(pointList);
+ graphics.drawPolygon(pointList);
+ } else {
+ Point p = this.getBounds().getTopRight();
+ Point p2 = this.getBounds().getBottomRight();
+ Point p3 = this.getBounds().getTopLeft();
+ p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
+ PointList pointList = new PointList();
+ pointList.addPoint(p.x - 1, p.y);
+ pointList.addPoint(p2.x - 1, p2.y - 1);
+ pointList.addPoint(p3);
+ graphics.fillPolygon(pointList);
+ graphics.drawPolygon(pointList);
+ }
graphics.popState();
}
@@ -113,25 +163,45 @@
@Override
public void paint(Graphics graphics) {
graphics.pushState();
+ ConnectionAnchor sourceAnchor = getSourceConnectionAnchor();
+ ConnectionAnchor targetAnchor = getTargetConnectionAnchor();
+ boolean startLeft = false;
+ if (sourceAnchor instanceof LeftOrRightAnchor) {
+ ((LeftOrRightAnchor) sourceAnchor).getLocation(targetAnchor.getReferencePoint());
+ startLeft = ((LeftOrRightAnchor) sourceAnchor).isLeft();
+ }
graphics.setForegroundColor(ColorConstants.black);
graphics.setBackgroundColor(ColorConstants.listBackground);
- Point p = this.getBounds().getTopLeft();
- Point p2 = this.getBounds().getBottomLeft();
- Point p3 = this.getBounds().getTopRight();
- p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
- PointList pointList = new PointList();
- pointList.addPoint(p);
- pointList.addPoint(p2.x, p2.y - 1);
- pointList.addPoint(p3);
- graphics.fillPolygon(pointList);
- graphics.drawPolygon(pointList);
+ if (!startLeft) {
+ Point p = this.getBounds().getTopLeft();
+ Point p2 = this.getBounds().getBottomLeft();
+ Point p3 = this.getBounds().getTopRight();
+ p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
+ PointList pointList = new PointList();
+ pointList.addPoint(p);
+ pointList.addPoint(p2.x, p2.y - 1);
+ pointList.addPoint(p3);
+ graphics.fillPolygon(pointList);
+ graphics.drawPolygon(pointList);
+ }else{
+ Point p = this.getBounds().getTopRight();
+ Point p2 = this.getBounds().getBottomRight();
+ Point p3 = this.getBounds().getTopLeft();
+ p3 = new Point(p3.x, p3.y + this.getSize().height / 2);
+ PointList pointList = new PointList();
+ pointList.addPoint(p.x - 1, p.y);
+ pointList.addPoint(p2.x - 1, p2.y - 1);
+ pointList.addPoint(p3);
+ graphics.fillPolygon(pointList);
+ graphics.drawPolygon(pointList);
+ }
graphics.popState();
super.paint(graphics);
}
};
- targetFlagFigure.setSize(10, 10);
- sourceFlagFigure.setSize(10, 10);
+ targetFlagFigure.setSize(5, 5);
+ sourceFlagFigure.setSize(5, 5);
ConnectionLocator targetLocator = new ConnectionLocator(connection,
ConnectionLocator.TARGET);
connection.add(targetFlagFigure, targetLocator);
ConnectionLocator sourceLocator = new ConnectionLocator(connection,
ConnectionLocator.SOURCE);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/LeftOrRightAnchor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/LeftOrRightAnchor.java 2009-08-19
09:47:48 UTC (rev 17152)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/LeftOrRightAnchor.java 2009-08-19
09:52:48 UTC (rev 17153)
@@ -7,6 +7,8 @@
public class LeftOrRightAnchor extends ChopboxAnchor {
+ private boolean isLeft;
+
public LeftOrRightAnchor(IFigure owner) {
super(owner);
}
@@ -28,8 +30,8 @@
p = getOwner().getBounds().getCenter();
getOwner().translateToAbsolute(p);
Point referencePoint = reference;
- boolean isLeft = false;
- if(referencePoint.x > p.x){
+ isLeft = false;
+ if(referencePoint.x > (p.x + getOwner().getBounds().width / 2)){
isLeft = false;
}else{
isLeft = true;
@@ -45,5 +47,11 @@
getOwner().translateToAbsolute(p);
return p;
}
+
+ public boolean isLeft() {
+ return isLeft;
+ }
+
+
}