DrawingCursor.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package org.gecode.gist;
00024
00025
00026 public class DrawingCursor extends DefaultNodeCursor {
00027
00028 private Object graphicsContext;
00029 private Rect clippingRect;
00030
00031 int x;
00032 int y;
00033
00034 public DrawingCursor(VisualNode theNode, Object theGraphicsContext, Rect theClippingRect) {
00035 super(theNode);
00036 this.graphicsContext = theGraphicsContext;
00037 this.clippingRect = theClippingRect;
00038 this.x = 0;
00039 this.y = 0;
00040 }
00041
00042 private VisualNode getVisualNode() {
00043 return ((VisualNode) super.getCurrentNode());
00044 }
00045
00046 public void moveUpwards() {
00047 VisualNode currentNode = getVisualNode();
00048 x = x - currentNode.getOffset();
00049 y = y - currentNode.getVerticalOffset();
00050 super.moveUpwards();
00051 }
00052
00053 public boolean mayMoveDownwards() {
00054 return (super.mayMoveDownwards() &&
00055 ! getVisualNode().isHidden() &&
00056 ! isClipped());
00057 }
00058
00059 public void moveDownwards() {
00060 super.moveDownwards();
00061 VisualNode currentNode = getVisualNode();
00062 x = x + currentNode.getOffset();
00063 y = y + currentNode.getVerticalOffset();
00064 }
00065
00066 public void moveSidewards() {
00067 x = x - getVisualNode().getOffset();
00068 super.moveSidewards();
00069 x = x + getVisualNode().getOffset();
00070 }
00071
00072 private boolean isClipped() {
00073 BoundingBox b = getVisualNode().getBoundingBox();
00074 int verticalOffset = getVisualNode().getVerticalOffset();
00075 return (x + b.left > clippingRect.x + clippingRect.width ||
00076 x + b.right < clippingRect.x ||
00077 y > clippingRect.y + clippingRect.height ||
00078 y + b.depth * verticalOffset < clippingRect.y);
00079 }
00080
00081 public void processCurrentNode() {
00082 VisualNode currentNode = getVisualNode();
00083 int parentX = x - currentNode.getOffset();
00084 int parentY = y - currentNode.getVerticalOffset();
00085 if (! currentNode.isRoot()) {
00086 currentNode.connect(graphicsContext, x, y, parentX, parentY);
00087 }
00088 if (! isClipped()) {
00089 currentNode.drawNode(graphicsContext, x, y);
00090 }
00091 }
00092
00093 }