KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > filter > ColorFilterEditor


1 package net.suberic.pooka.gui.filter;
2 import javax.swing.*;
3 import java.awt.*;
4
5 /**
6  * This class allows you to choose colors for a ColorFilter.
7  */

8 public class ColorFilterEditor extends FilterEditor implements java.awt.event.ActionListener JavaDoc {
9   JButton colorButton;
10   Color currentColor;
11   int originalRgb = NO_VALUE;
12   
13   public static int NO_VALUE = -1;
14   
15   public static String JavaDoc FILTER_CLASS = "net.suberic.pooka.gui.filter.ColorDisplayFilter";
16   
17   /**
18    * Configures the given FilterEditor from the given VariableBundle and
19    * property.
20    */

21   public void configureEditor(net.suberic.util.gui.propedit.PropertyEditorManager newManager, String JavaDoc propertyName) {
22     property = propertyName;
23     manager = newManager;
24     
25     String JavaDoc 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   /**
48    * Shows a dialog for choosing a new color when this is selected.
49    */

50   public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
51     Color newColor = JColorChooser.showDialog(this, "title", currentColor);
52     if (newColor != null)
53       setCurrentColor(newColor);
54   }
55   
56   /**
57    * Gets the values that would be set by this FilterEditor.
58    */

59   public java.util.Properties JavaDoc getValue() {
60     java.util.Properties JavaDoc props = new java.util.Properties JavaDoc();
61     props.setProperty(property + ".rgb", Integer.toString(currentColor.getRGB()));
62     props.setProperty(property + ".class", FILTER_CLASS);
63     return props;
64   }
65   
66   /**
67    * Sets the values represented by this FilterEditor in the manager.
68    */

69   public void setValue() {
70     int newValue = currentColor.getRGB();
71     if (newValue != originalRgb)
72       manager.setProperty(property + ".rgb", Integer.toString(newValue));
73     
74     String JavaDoc oldClassName = manager.getProperty(property + ".class", "");
75     if (!oldClassName.equals(FILTER_CLASS))
76       manager.setProperty(property + ".class", FILTER_CLASS);
77   }
78
79   /**
80    * Returns the class that will be set for this FilterEditor.
81    */

82   public String JavaDoc getFilterClassValue() {
83     return FILTER_CLASS;
84   }
85   
86 }
87
88
89
90
91
92
93
94
95
96
Popular Tags