Node.java
Go to the documentation of this file.00001 package org.gecode.explorer.cocoa; 00002 00003 import java.util.*; 00004 00005 import com.apple.cocoa.foundation.*; 00006 import com.apple.cocoa.application.*; 00007 00008 import org.gecode.explorer.*; 00009 00010 00011 abstract public class Node { 00012 00013 final protected static int unit = 100; 00014 final protected static int halfUnit = unit / 2; 00015 00016 final static Shape unknownShape = new Shape(new Extent(unit)); 00017 00018 final static Shape hiddenSubtreeShape = 00019 new Shape(new Extent(unit), new Shape(new Extent(unit + halfUnit))); 00020 00021 protected abstract NSBezierPath getBezierPath(); 00022 00023 protected abstract NSColor getInsideColor(); 00024 protected abstract NSColor getBorderColor(); 00025 00026 protected abstract NSPoint getTopConnector(); 00027 protected abstract NSPoint getBotConnector(); 00028 00029 public Node() {} 00030 00031 protected static NSColor getDefaultColor(String key) { 00032 NSUserDefaults defaults = NSUserDefaults.standardUserDefaults(); 00033 String colorName = defaults.stringForKey("NodeColor" + key); 00034 NSColorList colorList = NSColorList.colorListNamed("Crayons"); 00035 return colorList.colorWithKey(colorName); 00036 } 00037 00038 public void draw(Object gc, int x, int y) { 00039 NSAffineTransform transform = new NSAffineTransform(); 00040 transform.translateXYBy(x, y); 00041 transform.concat(); 00042 getInsideColor().set(); 00043 NSBezierPath bezierPath = getBezierPath(); 00044 bezierPath.fill(); 00045 bezierPath.setLineWidth(5); 00046 getBorderColor().set(); 00047 bezierPath.stroke(); 00048 transform.invert(); 00049 transform.concat(); 00050 } 00051 00052 protected Shape getHiddenShape() { 00053 return hiddenSubtreeShape; 00054 } 00055 00056 protected Shape getUnknownShape() { 00057 return unknownShape; 00058 } 00059 00060 public boolean containsPoint(Coordinate thePoint) { 00061 NSPoint point = new NSPoint((float) thePoint.x(), (float) thePoint.y()); 00062 return getBezierPath().containsPoint(point); 00063 } 00064 00065 00066 }
