// Copyright MageLang Institute; Version $Id: //depot/main/src/edu/modules/Swing/magercises/JTable/ColorizedCell.java#2 $ import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; class ColorizedCell /* subclass table cell renderer */ { static Hashtable cache; static { cache = new Hashtable(); cache.put ("white",Color.white); cache.put ("lightGray",Color.lightGray); cache.put ("gray",Color.gray); cache.put ("darkGray",Color.darkGray); cache.put ("black",Color.black); cache.put ("red",Color.red); cache.put ("pink",Color.pink); cache.put ("orange",Color.orange); cache.put ("yellow",Color.yellow); cache.put ("green",Color.green); cache.put ("magenta",Color.magenta); cache.put ("cyan",Color.cyan); cache.put ("blue",Color.blue); } protected void setValue(Object value) { if (value != null) { Color c; c = (Color)cache.get (value); if (c == null) c = Color.black; // Create icon // Associate to label } } static class ColorizedIcon implements Icon { Color color; public ColorizedIcon (Color c) { color = c; } public void paintIcon (Component c, Graphics g, int x, int y) { int width = getIconWidth(); int height = getIconHeight(); g.setColor (color); g.fillOval (x, y, width, height); } public int getIconWidth() { return 10; } public int getIconHeight() { return 10; } } }