Generated on Fri Oct 6 16:26:43 2006 for Gecode/J by doxygen 1.4.7

PostscriptCursor.java

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00004  *
00005  *  Copyright:
00006  *     Marco Kuhlmann, 2005
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-02-09 16:32:56 +0100 (Thu, 09 Feb 2006) $ by $Author: tack $
00010  *     $Revision: 2943 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 package org.gecode.explorer.postscript;
00023 
00024 import org.gecode.explorer.*;
00025 import java.util.ArrayList;
00026 
00027 public class PostscriptCursor extends DefaultNodeCursor {
00028     protected static final int verticalOffset = 38;
00029 
00030     protected static final PSColor black = new PSColor(0.0,0.0,0.0);
00031     protected static final PSColor blue = new PSColor(0.0,0.36,0.63);
00032     protected static final PSColor white = new PSColor(1.0,1.0,1.0);
00033     protected static final PSColor red = new PSColor(0.85,0.14,0.11);
00034     protected static final PSColor green = new PSColor(0.04,0.46,0.27);
00035     protected static final PSColor lightgray = new PSColor(0.92,0.92,0.92);
00036     
00037     int x;
00038     int y;
00039 
00040     ArrayList<Path> ps;
00041     
00042     public PostscriptCursor(SpaceNode theNode, ArrayList<Path> ps0) {
00043         super(theNode);
00044         this.x = 0;
00045         this.y = 0;
00046         this.ps = ps0;
00047     }
00048     
00049     private SpaceNode getSpaceNode() {
00050         return ((SpaceNode) super.getCurrentNode());
00051     }
00052     
00053     public void moveUpwards() {
00054         SpaceNode currentNode = getSpaceNode();
00055         x = x - currentNode.getOffset();
00056         y = y - verticalOffset;
00057         super.moveUpwards();
00058     }
00059         
00060     public boolean mayMoveDownwards() {
00061         return (super.mayMoveDownwards() &&
00062                 ! getSpaceNode().isHidden() );
00063     }
00064     
00065     public void moveDownwards() {
00066         super.moveDownwards();
00067         SpaceNode currentNode = getSpaceNode();
00068         x = x + currentNode.getOffset();
00069         y = y + verticalOffset;
00070     }
00071     
00072     public void moveSidewards() {
00073         x = x - getSpaceNode().getOffset();
00074         super.moveSidewards();
00075         x = x + getSpaceNode().getOffset();
00076     }
00077     
00078 /*    private boolean isClipped() {
00079         return false;
00080     }*/
00081 
00082     private void drawHidden(ArrayList<Path> ps, int x, int y,
00083                             boolean solved, boolean open)
00084     {
00085         PSColor fill = solved ? green : red;
00086         ps.add(new Triangle(x,-y+10,x-16,-y-38,x+16,-y-38,black,fill));
00087     }
00088     private void drawFailed(ArrayList<Path> ps, int x, int y)
00089     {
00090         ps.add(new Rectangle(x-7,-y+7,x+7,-y-7,black,red));
00091     }
00092     private void drawSolved(ArrayList<Path> ps, int x, int y)
00093     {
00094         ps.add(new Diamond(x, -y-10, 10, black, green));
00095     }
00096     private void drawChoice(ArrayList<Path> ps, int x, int y)
00097     {
00098         ps.add(new Circle(x, -y, 10, black, blue));
00099     }
00100     private void drawUndetermined(ArrayList<Path> ps, int x, int y)
00101     {
00102         ps.add(new Circle(x, -y, 10, black, white));
00103     }
00104     
00105     public void processCurrentNode() {
00106         SpaceNode currentNode = getSpaceNode();
00107         int parentX = (x - currentNode.getOffset())/5;
00108         int myx = x / 5;
00109         int parentY = y - verticalOffset;
00110         if (! currentNode.isRoot()) {
00111             if (currentNode.isHidden()) {
00112                 ps.add(new Line(myx, -y+10, parentX, -y+28, black));
00113             } else {
00114                 switch(currentNode.getStatus()) {
00115                     case SOLVED:
00116                     case UNDETERMINED:
00117                     case BRANCH:
00118                         ps.add(new Line(myx, -y+10, parentX, -y+28, black));
00119                         break;
00120                     case FAILED:
00121                         ps.add(new Line(myx, -y+7, parentX, -y+28, black));
00122                         break;
00123                 }
00124             }
00125         }
00126         if (currentNode.isHidden()) {
00127             drawHidden(ps, myx, y,
00128                        currentNode.hasSolvedChildren(),
00129                        currentNode.isOpen());
00130         } else {
00131             switch(currentNode.getStatus()) {
00132                 case UNDETERMINED:
00133                     drawUndetermined(ps,myx,y);
00134                     break;
00135                 case FAILED:
00136                     drawFailed(ps,myx,y);
00137                     break;
00138                case SOLVED:
00139                    drawSolved(ps,myx,y);
00140                     break;
00141                case BRANCH:
00142                    drawChoice(ps,myx,y);
00143                     break;
00144             }
00145         }
00146     }
00147     
00148 }