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

SuccessNode.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.*;
00025 import java.awt.geom.*;
00026 import org.gecode.explorer.*;
00027 
00028 class SuccessNode extends GraphicsNode {
00029 
00030     static int x1Points[] = {0, halfUnit, 0, -halfUnit};
00031     static int y1Points[] = {0, halfUnit, unit, halfUnit};
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 SuccessNode() {}
00043 
00044     public void draw(Graphics2D g2, int x, int y, boolean hasShadow) {
00045         if (hasShadow) {
00046             int sx = x+shadowOff; int sy = y+shadowOff;
00047             // draw GeneralPath (polygon)
00048             int x1Points[] = {sx, sx+halfUnit, sx, sx-halfUnit};
00049             int y1Points[] = {sy, sy+halfUnit, sy+unit, sy+halfUnit};
00050             GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00051                                                   x1Points.length);
00052             diamond.moveTo(x1Points[0], y1Points[0]);
00053             for ( int index = 1; index < x1Points.length; index++ ) {
00054                 diamond.lineTo(x1Points[index], y1Points[index]);
00055             };
00056             diamond.closePath();
00057             g2.setPaint(shadow);
00058             g2.fill(diamond);
00059             
00060             g2.setPaint(shadow);
00061             g2.setStroke(stroke);
00062             g2.draw(diamond);
00063         }
00064 
00065         // draw GeneralPath (polygon)
00066         int x1Points[] = {x, x+halfUnit, x, x-halfUnit};
00067         int y1Points[] = {y, y+halfUnit, y+unit, y+halfUnit};
00068         GeneralPath diamond = new GeneralPath(GeneralPath.WIND_NON_ZERO,
00069                                               x1Points.length);
00070         diamond.moveTo(x1Points[0], y1Points[0]);
00071         for ( int index = 1; index < x1Points.length; index++ ) {
00072             diamond.lineTo(x1Points[index], y1Points[index]);
00073         };
00074         diamond.closePath();
00075         g2.setPaint(green);
00076         g2.fill(diamond);
00077         
00078         g2.setPaint(fg);
00079         g2.setStroke(stroke);
00080         g2.draw(diamond);
00081     }
00082     public void move(int xoff) {
00083 //         x_coord += xoff;
00084 //         Iterator childrenIterator = children.iterator();
00085 //         while (childrenIterator.hasNext()) {
00086 //             UINode child = (UINode) childrenIterator.next();
00087 //             child.move(xoff);
00088 //         }
00089     }
00090     public void connect(Graphics2D g2,
00091                         int x, int y,
00092                         int child_x, int child_y) {
00093         g2.setPaint(fg);
00094         g2.setStroke(stroke);
00095         g2.draw(new Line2D.Double(x, y, child_x, child_y));
00096     }
00097 
00098     Point getConnector(int x, int y) {
00099         return new Point(x, y);
00100     }
00101     
00102     public boolean containsPoint(Coordinate x) {
00103         return diamond.contains(new Point(x.x(), x.y()));
00104     }
00105 }