To load this file without formatting, visit http://whoyouknow.co.uk/ants/AntGraph/java/4/src/antgraph/GraphComponent.java. This is a spam-protection measure; sorry for the inconvenience.

· GraphComponent.java ·

   1/*
   2 * GraphComponent.java
   3 *
   4 * Created on 07 March 2007, 00:20
   5 *
   6 * To change this template, choose Tools | Template Manager
   7 * and open the template in the editor.
   8 */
   9
  10package antgraph;
  11
  12import java.awt.Color;
  13import java.awt.Graphics;
  14import java.awt.Graphics2D;
  15import java.awt.Polygon;
  16import java.awt.RenderingHints;
  17
  18/**
  19 *
  20 * @author James
  21 */
  22public abstract class GraphComponent extends Polygon {
  23
  24    public static final Color NORMAL = Color.BLACK;
  25    public static final Color SELECTED = Color.GREEN;
  26    
  27    private Color color = NORMAL;
  28    
  29    private boolean selected = false;    
  30    private boolean highlighted = false;
  31    
  32    /** Creates a new instance of GraphComponent */
  33    public GraphComponent() {
  34        
  35    }
  36
  37    public boolean isSelected() {
  38        return selected;
  39    }
  40
  41    public void setSelected(boolean selected) {
  42        this.selected = selected;
  43        color = selected ? SELECTED : NORMAL;
  44    }
  45
  46    public void draw(Graphics g) {
  47        update();
  48        Graphics2D g2d = (Graphics2D)g;
  49        g2d.setRenderingHint
  50          (RenderingHints.KEY_ANTIALIASING, 
  51            RenderingHints.VALUE_ANTIALIAS_ON);
  52        
  53        Color old = g2d.getColor();
  54        
  55        g2d.setColor( getColor());
  56
  57        g2d.fill(this);
  58
  59        g2d.setColor(old);
  60    }       
  61    
  62    public void highlight(boolean value) {
  63        highlighted = value;
  64    }
  65    
  66    public boolean isHighlighted() {
  67        return highlighted;
  68    }
  69    
  70    public Color getColor() {
  71        if(!isSelected() && isHighlighted()) 
  72            return Color.BLUE;
  73        else
  74            return color;
  75    }
  76    
  77    public abstract void update();
  78
  79}
  80

· GraphComponent.java ends ·

Generated by CHIP: Code Highlighting in PHP, version 2.7.0.