UINode.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 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
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 }