Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

DrawingCursor.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Marco Kuhlmann, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2006-10-26 11:31:58 +0200 (Thu, 26 Oct 2006) $ by $Author: tack $
00011  *     $Revision: 3796 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  See the file "LICENSE" for information on usage and
00018  *  redistribution of this file, and for a
00019  *     DISCLAIMER OF ALL WARRANTIES.
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 }