1 package net.suberic.pooka.gui.filter; 2 import javax.swing.*; 3 import java.awt.*; 4 5 8 public class ColorFilterEditor extends FilterEditor implements java.awt.event.ActionListener { 9 JButton colorButton; 10 Color currentColor; 11 int originalRgb = NO_VALUE; 12 13 public static int NO_VALUE = -1; 14 15 public static String FILTER_CLASS = "net.suberic.pooka.gui.filter.ColorDisplayFilter"; 16 17 21 public void configureEditor(net.suberic.util.gui.propedit.PropertyEditorManager newManager, String propertyName) { 22 property = propertyName; 23 manager = newManager; 24 25 String origRgbString = manager.getProperty(propertyName + ".rgb", Integer.toString(NO_VALUE)); 26 originalRgb = Integer.parseInt(origRgbString); 27 28 colorButton = new JButton(); 29 if (originalRgb != NO_VALUE) { 30 setCurrentColor(new Color(originalRgb)); 31 } else { 32 setCurrentColor(Color.blue); 33 } 34 colorButton.addActionListener(this); 35 this.add(colorButton); 36 } 37 38 public void setCurrentColor(Color newColor) { 39 currentColor = newColor; 40 colorButton.setBackground(currentColor); 41 } 42 43 public Color getCurrentColor() { 44 return currentColor; 45 } 46 47 50 public void actionPerformed(java.awt.event.ActionEvent e) { 51 Color newColor = JColorChooser.showDialog(this, "title", currentColor); 52 if (newColor != null) 53 setCurrentColor(newColor); 54 } 55 56 59 public java.util.Properties getValue() { 60 java.util.Properties props = new java.util.Properties (); 61 props.setProperty(property + ".rgb", Integer.toString(currentColor.getRGB())); 62 props.setProperty(property + ".class", FILTER_CLASS); 63 return props; 64 } 65 66 69 public void setValue() { 70 int newValue = currentColor.getRGB(); 71 if (newValue != originalRgb) 72 manager.setProperty(property + ".rgb", Integer.toString(newValue)); 73 74 String oldClassName = manager.getProperty(property + ".class", ""); 75 if (!oldClassName.equals(FILTER_CLASS)) 76 manager.setProperty(property + ".class", FILTER_CLASS); 77 } 78 79 82 public String getFilterClassValue() { 83 return FILTER_CLASS; 84 } 85 86 } 87 88 89 90 91 92 93 94 95 96 | Popular Tags |