1 package org.columba.core.gui.base; 17 18 import java.awt.Color ; 19 import java.awt.Graphics2D ; 20 import java.awt.image.BufferedImage ; 21 22 import javax.swing.Icon ; 23 import javax.swing.ImageIcon ; 24 25 26 31 public class ColorItem { 32 private Color itemColor; 33 private String itemName; 34 private Icon itemIcon; 35 36 41 public ColorItem(Color color, String name) { 42 setColor(color); 43 itemName = name; 44 } 45 46 49 public Color getColor() { 50 return itemColor; 51 } 52 53 58 public final void setColor(Color color) { 59 itemColor = color; 60 itemIcon = createIcon(color); 61 } 62 63 66 public String getName() { 67 return itemName; 68 } 69 70 73 public Icon getIcon() { 74 return itemIcon; 75 } 76 77 82 private Icon createIcon(Color color) { 83 int width = 45; 84 int height = 14; 85 BufferedImage image = new BufferedImage (width, height, 86 BufferedImage.TYPE_INT_ARGB); 87 88 Graphics2D graphics = (Graphics2D ) image.getGraphics(); 89 graphics.setColor(Color.black); 90 graphics.drawRect(1, 1, width - 3, height - 3); 91 graphics.setColor(color); 92 graphics.fillRect(2, 2, width - 4, height - 4); 93 graphics.dispose(); 94 95 return new ImageIcon (image); 96 } 97 } 98 | Popular Tags |