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.*;
00025 import java.awt.geom.*;
00026 import org.gecode.explorer.*;
00027
00028 class HiddenNode extends GraphicsNode {
00029
00030 static int x1Points[] = {0, unit, -unit};
00031 static int y1Points[] = {0, 3*unit, 3*unit};
00032 static GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00033 x1Points.length);
00034 static {
00035 diamond.moveTo(x1Points[0], y1Points[0]);
00036 for ( int index = 1; index < x1Points.length; index++ ) {
00037 diamond.lineTo(x1Points[index], y1Points[index]);
00038 };
00039 diamond.closePath();
00040 }
00041
00042 public HiddenNode() {}
00043
00044 public void draw(Graphics2D g2, int x, int y,
00045 boolean hasShadow) {}
00046
00047 private void smallTria(Graphics2D g2,
00048 int x, int y,
00049 Color c) {
00050 int x1Points[] = {x+unit/2-10, x, x+unit-20};
00051 int y1Points[] = {y+2*unit, y+3*unit-10, y+3*unit-10};
00052 GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00053 x1Points.length);
00054 diamond.moveTo(x1Points[0], y1Points[0]);
00055 for ( int index = 1; index < x1Points.length; index++ ) {
00056 diamond.lineTo(x1Points[index], y1Points[index]);
00057 };
00058 diamond.closePath();
00059 g2.setPaint(c);
00060 g2.fill(diamond);
00061 g2.setPaint(fg);
00062 g2.setStroke(stroke);
00063 g2.draw(diamond);
00064 }
00065
00066 public void draw(Graphics2D g2, int x, int y,
00067 boolean hasShadow, boolean hasFailed,
00068 boolean hasSolved, boolean isOpen) {
00069
00070 if (hasShadow) {
00071 int sx = x+shadowOff; int sy = y+shadowOff;
00072 int x1Points[] = {sx, sx+unit, sx-unit};
00073 int y1Points[] = {sy, sy+3*unit, sy+3*unit};
00074 GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00075 x1Points.length);
00076 diamond.moveTo(x1Points[0], y1Points[0]);
00077 for ( int index = 1; index < x1Points.length; index++ ) {
00078 diamond.lineTo(x1Points[index], y1Points[index]);
00079 };
00080 diamond.closePath();
00081 g2.setPaint(shadow);
00082 g2.fill(diamond);
00083 g2.setPaint(shadow);
00084 g2.setStroke(stroke);
00085 g2.draw(diamond);
00086 }
00087
00088 int x1Points[] = {x, x+unit, x-unit};
00089 int y1Points[] = {y, y+3*unit, y+3*unit};
00090 GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00091 x1Points.length);
00092 diamond.moveTo(x1Points[0], y1Points[0]);
00093 for ( int index = 1; index < x1Points.length; index++ ) {
00094 diamond.lineTo(x1Points[index], y1Points[index]);
00095 };
00096 diamond.closePath();
00097
00098 if (!isOpen) {
00099 if (hasFailed) {
00100 g2.setPaint(red);
00101 } else {
00102 g2.setPaint(green);
00103 }
00104 } else {
00105 g2.setPaint(white);
00106 }
00107
00108 g2.fill(diamond);
00109 g2.setPaint(fg);
00110 g2.setStroke(stroke);
00111 g2.draw(diamond);
00112
00113 if (isOpen) {
00114 if (hasSolved) {
00115 smallTria(g2, x, y, green);
00116 }
00117 } else {
00118 if (hasSolved && hasFailed) {
00119 smallTria(g2, x, y, green);
00120 }
00121 }
00122
00123 }
00124 public void move(int xoff) {
00125
00126
00127
00128
00129
00130
00131 }
00132 public void connect(Graphics2D g2,
00133 int x, int y,
00134 int child_x, int child_y) {
00135 g2.setPaint(fg);
00136 g2.setStroke(stroke);
00137 g2.draw(new Line2D.Double(x, y, child_x, child_y));
00138 }
00139
00140 public boolean containsPoint(Coordinate x) {
00141 return diamond.contains(new Point(x.x(), x.y()));
00142 }
00143
00144 Point getConnector(int x, int y) {
00145 return new Point(x, y);
00146 }
00147
00148 }