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

GraphicsNode.java

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-02-09 16:32:56 +0100 (Thu, 09 Feb 2006) $ by $Author: tack $
00013  *     $Revision: 2943 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
00022  *
00023  */
00024 
00025 package org.gecode.explorer.swing;
00026 
00027 import org.gecode.explorer.Coordinate;
00028 import java.awt.*;
00029 import java.awt.image.BufferedImage;
00030 import javax.swing.Icon;
00031 import javax.swing.ImageIcon;
00032 
00033 abstract class GraphicsNode {
00034   final protected static int unit = 100;
00035   final protected static int halfUnit = unit / 2;
00036   final protected static int shadowOff = 10;
00037   final static Color bg = Color.white;
00038   final static Color fg = Color.black;
00039   final static Color red = new Color(218, 37, 29);
00040   final static Color white = Color.white;
00041   final static Color green = new Color(11, 118, 70);
00042   final static Color blue = new Color(0, 92, 161);
00043   final static Color yellow = new Color(235, 137, 27);
00044   final static Color marker = yellow;
00045   final static Color shadow = Color.gray;
00046   final static BasicStroke stroke =
00047   new BasicStroke(5, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
00048   
00049   abstract void draw(Graphics2D g, int momx, int momy, boolean hasShadow);
00050   abstract Point getConnector(int x, int y);
00051   abstract boolean containsPoint(Coordinate x);
00052   
00053   Icon getIcon() {
00054     int size = 16;
00055     double scale = 0.145;
00056     BufferedImage bf = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
00057     Graphics2D g2 = (Graphics2D)bf.getGraphics();
00058     g2.scale(scale, scale);
00059     g2.translate(size/scale/2, 0);
00060     draw(g2, (int)(size*scale), (int)(size*scale), false);
00061     return new javax.swing.ImageIcon(bf);
00062   }
00063 }