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

UINode.java

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2006
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.swing;
00023 
00024 import java.awt.Graphics2D;
00025 
00026 import java.awt.Point;
00027 import java.awt.geom.Line2D;
00028 
00029 //import java.awt.geom.*;
00030 import org.gecode.explorer.*;
00031 import org.gecode.Gecode;
00032 import org.gecode.Space;
00033 
00034 class UINode extends SpaceNode {
00035     final static Shape unitShape =
00036         new Shape(new Extent(unit), new Shape(new Extent(unit+halfUnit)));
00037 
00038     GraphicsNode gNode;
00039 
00040     static HiddenNode hiddenNode = new HiddenNode();
00041 
00042     boolean marked = false;
00043     boolean hasShadow = false;
00044 
00045     public UINode(Space root, boolean bab, Statistics stats) {
00046         super(root,stats);
00047         if (bab) {
00048                 initCurBest(new BestSpace());
00049         }
00050         gNode = new UnknownNode();
00051     }
00052     public UINode(int alternative, BestSpace best, Statistics stats) {
00053         super(alternative, best, stats);
00054         gNode = new UnknownNode();
00055     }
00056 
00057     public void mark() {
00058         marked = true;
00059     }
00060     public void unmark() {
00061         marked = true;
00062     }
00063     public void togglemark() {
00064         marked = !marked;
00065     }
00066 
00067     public int getWidth() { return unit; }
00068     protected Shape getUnknownShape() { return unitShape; }
00069     protected Shape getHiddenShape() { return unitShape; }
00070 
00071     public void drawNode(Object graphicsContext, int x, int y) {
00072         Graphics2D g2 = (Graphics2D) graphicsContext;
00073         if (isHidden()) {
00074             hiddenNode.draw(g2, x, y, hasShadow, hasFailedChildren(),
00075                             hasSolvedChildren(), isOpen());
00076         } else {
00077             gNode.draw(g2, x, y, hasShadow);
00078         }
00079     }
00080 
00081 
00082     public void move(int xoff) {}
00083     public void connect(Object graphicsContext,
00084                         int x, int y,
00085                         int momX, int momY) {
00086         
00087         Graphics2D g2 = (Graphics2D) graphicsContext;
00088         g2.setPaint(GraphicsNode.fg);
00089         g2.setStroke(GraphicsNode.stroke);
00090         
00091         Point realCoords = ((UINode)getParent()).gNode.getConnector(momX, momY);
00092         
00093         g2.draw(new Line2D.Double(x, y, realCoords.x, realCoords.y));
00094     }
00095     public SpaceNode createChild(int i) {
00096         return new UINode(i, curBest, stats);
00097     }
00098 
00099     public VisualNode findNodeForPoint(int x, int y) {
00100         Coordinate foundPoint = new Coordinate();
00101         UINode found = (UINode) super.findNode(x, y, foundPoint);
00102         if (found != null) {
00103             if (found.isHidden()) {
00104                 if (hiddenNode.containsPoint(foundPoint))
00105                     return found;
00106             } else {
00107                 if (found.gNode.containsPoint(foundPoint))
00108                     return found;
00109             }
00110         }
00111         return null;
00112     }
00113 
00114     public int getNumberOfChildNodes() {
00115         if (getStatus() == Undetermined) {
00116             int kids = super.getNumberOfChildNodes();
00117             switch(getStatus()) {
00118             case FAILED:
00119                 gNode = new FailureNode();
00120                 break;
00121             case SOLVED:
00122                 gNode = new SuccessNode();
00123                 break;
00124             case BRANCH:
00125                 gNode = new ChoiceNode();
00126                 break;
00127             }
00128             return kids;
00129         } else {
00130             return super.getNumberOfChildNodes();
00131         }
00132     }
00133 }