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