001 /* 002 * NodeNetIcon.java 003 * 004 * Developed for the "Rethinking CS101" project. See http://www.cs101.org, the 005 * CS101 homepage or email las@olin.edu. 006 * 007 * Created on January 6, 2004, 3:04 PM 008 * Please do not redistribute without obtaining permission. 009 */ 010 011 package nodenet; 012 013 import java.awt.Color; 014 import java.awt.Graphics; 015 import java.awt.Component; 016 017 import javax.swing.Icon; 018 019 /** 020 * An icon to draw nodes reflecting their selection status. This was formerly 021 * an inner class of ControlPanel. 022 * 023 * @author Todd C. Parnell, tparnell@ai.mit.edu 024 * @author Patrick G. Heck, gus.heck@olin.edu 025 * @version $Id: NodeNetIcon.java,v 1.3 2004/01/14 21:43:17 gus Exp $ 026 */ 027 public class NodeNetIcon implements Icon { 028 029 private Color color; 030 private boolean state; 031 032 /** Creates a new instance of NodeNetIcon */ 033 public NodeNetIcon() { 034 } 035 036 /** 037 * Creates a new instance of NodeNetIcon with the specified 038 * color and state. 039 */ 040 public NodeNetIcon(Color c, boolean s) { 041 this.color = c; 042 this.state = s; 043 } 044 045 // implementing Icon 046 public void paintIcon(Component c, Graphics g, int x, int y) { 047 int width = getIconWidth(); 048 int height = getIconHeight(); 049 g.setColor(color); 050 g.fillOval(x, y, width, height); 051 if (this.state) { 052 g.setColor(Color.black); 053 g.drawRect(x, y, width, height); 054 } 055 } 056 057 // implementing Icon 058 public int getIconWidth() { 059 return Node.GUISIZE; 060 } 061 062 // implementing Icon 063 public int getIconHeight() { 064 return Node.GUISIZE; 065 } 066 067 /** 068 * Getter for property color. 069 * 070 * @return Value of property color. 071 * 072 */ 073 public java.awt.Color getColor() { 074 return color; 075 } 076 077 /** 078 * Setter for property color. 079 * 080 * @param color New value of property color. 081 * 082 */ 083 public void setColor(java.awt.Color color) { 084 this.color = color; 085 } 086 087 }