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

ExplorerNode.java

Go to the documentation of this file.
00001 package org.gecode.explorer.cocoa;
00002 
00003 import com.apple.cocoa.foundation.*;
00004 import com.apple.cocoa.application.*;
00005 
00006 import org.gecode.*;
00007 import org.gecode.explorer.*;
00008 
00009 
00010 public class ExplorerNode extends SpaceNode {
00011     
00012     Node graphicalNode;
00013     
00014     private static HiddenSubtreeNode hiddenSubtree = new HiddenSubtreeNode();
00015     
00016     public ExplorerNode(Space theSpace) {
00017         super(theSpace);
00018 //        this.graphicalNode = new UnknownNode();
00019         this.graphicalNode = new UnknownNode();
00020     }
00021     
00022     public ExplorerNode(int alternative) {
00023         super(alternative);
00024 //        this.graphicalNode = new UnknownNode();
00025         this.graphicalNode = new UnknownNode();
00026     }
00027     
00028 //    public void mark() {
00029 //        marked = true;
00030 //    }
00031     
00032 //    public void unmark() {
00033 //        marked = false;
00034 //    }
00035     
00036 //    public void toggleMarked() {
00037 //        marked = ! marked;
00038 //    }
00039     
00040     public int getWidth() {
00041         return unit;
00042     }
00043     
00044     public Shape getUnknownShape() {
00045         return graphicalNode.getUnknownShape();
00046     }
00047     
00048     public Shape getHiddenShape() {
00049         return graphicalNode.getHiddenShape();
00050     }
00051     
00052     public void drawNode(Object gc, int x, int y) {
00053         if (isHidden()) {
00054             hiddenSubtree.draw(gc, x, y);
00055         } else {
00056             graphicalNode.draw(gc, x, y);
00057         }
00058     }
00059     
00060     public void move(int offset) {}
00061     
00062     public SpaceNode createChild(int i) {
00063         return new ExplorerNode(i);
00064     }
00065     
00066     public VisualNode findNodeForPoint(int x, int y) {
00067         Coordinate foundPoint = new Coordinate();
00068         ExplorerNode foundNode = (ExplorerNode) super.findNode(x, y, foundPoint);
00069         if (foundNode != null) {
00070             if (foundNode.isHidden()) {
00071                 if (hiddenSubtree.containsPoint(foundPoint)) {
00072                     return foundNode;
00073                 }
00074             } else {
00075                 if (foundNode.graphicalNode.containsPoint(foundPoint)) {
00076                     return foundNode;
00077                 }
00078             }
00079         }
00080         return null;
00081     }
00082 
00083     public int getNumberOfChildNodes() {
00084         if (getStatus() == Undetermined) {
00085             int numberOfChildren = super.getNumberOfChildNodes();
00086             switch(getStatus()) {
00087                 case SS_FAILED:
00088                     graphicalNode = new FailureNode();
00089                     break;
00090                 case SS_SOLVED:
00091                     graphicalNode = new SolutionNode();
00092                     break;
00093                 case SS_BRANCH:
00094                     graphicalNode = new ChoiceNode();
00095                     break;
00096             }
00097             return numberOfChildren;
00098         } else {
00099             return super.getNumberOfChildNodes();
00100         }
00101     }
00102 
00103     public void connect(Object gc, int x, int y, int parentX, int parentY) {
00104         if (! isRoot()) {
00105             NSAffineTransform parentTransform = new NSAffineTransform();
00106             parentTransform.translateXYBy(parentX, parentY);
00107             ExplorerNode parent = (ExplorerNode) getParent();
00108             NSPoint p1 = parentTransform.transformPoint(parent.graphicalNode.getBotConnector());
00109             
00110             NSAffineTransform transform = new NSAffineTransform();
00111             transform.translateXYBy(x, y);
00112             NSPoint p2 = transform.transformPoint(graphicalNode.getTopConnector());
00113             
00114             NSBezierPath connection = new NSBezierPath();
00115             connection.moveToPoint(p1);
00116             connection.lineToPoint(p2);
00117             connection.setLineWidth(5);
00118             connection.stroke();
00119         }
00120     }    
00121     
00122 }