KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.pooka.gui.filter;
2
3 import javax.swing.*;
4 import java.util.Properties JavaDoc;
5
6 /**
7  * This is a class that lets you choose your filter actions.
8  */

9 public class BounceFilterEditor extends FilterEditor {
10   JTextField addressField;
11   JCheckBox deleteField;
12
13   public static String JavaDoc FILTER_CLASS = "net.suberic.pooka.filter.BounceFilterAction";
14
15   /**
16    * Configures the given FilterEditor from the given VariableBundle and
17    * property.
18    */

19   public void configureEditor(net.suberic.util.gui.propedit.PropertyEditorManager newManager, String JavaDoc propertyName) {
20     property = propertyName;
21     manager = newManager;
22
23     String JavaDoc originalAddressString = manager.getProperty(propertyName + ".targetAddresses", "");
24
25     addressField = new JTextField(originalAddressString);
26
27     boolean originalDeleteValue = manager.getProperty(propertyName + ".removeBounced", "false").equalsIgnoreCase("true");
28
29     deleteField = new JCheckBox();
30     deleteField.setSelected(originalDeleteValue);
31
32     SpringLayout layout = new SpringLayout();
33     this.setLayout(layout);
34
35     this.add(addressField);
36     this.add(deleteField);
37
38     layout.putConstraint(SpringLayout.NORTH, addressField, 0, SpringLayout.NORTH, this);
39     layout.putConstraint(SpringLayout.WEST, addressField, 0, SpringLayout.WEST, this);
40     layout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, addressField);
41     layout.putConstraint(SpringLayout.WEST, deleteField, 5, SpringLayout.EAST, addressField);
42     layout.putConstraint(SpringLayout.EAST, this, 5, SpringLayout.EAST, deleteField);
43
44     this.setPreferredSize(new java.awt.Dimension JavaDoc(150, addressField.getMinimumSize().height));
45     this.setMaximumSize(new java.awt.Dimension JavaDoc(Integer.MAX_VALUE, addressField.getMinimumSize().height));
46   }
47
48   /**
49    * Gets the values that would be set by this FilterEditor.
50    */

51   public java.util.Properties JavaDoc getValue() {
52     Properties JavaDoc props = new Properties JavaDoc();
53
54     String JavaDoc oldClassName = manager.getProperty(property + ".class", "");
55     if (!oldClassName.equals(FILTER_CLASS))
56       props.setProperty(property + ".class", FILTER_CLASS);
57
58     String JavaDoc originalAddressString = manager.getProperty(property + ".targetAddresses", "");
59     if (addressField.getText() != originalAddressString) {
60       props.setProperty(property + ".targetAddresses", addressField.getText());
61     }
62
63     boolean originalDeleteValue = manager.getProperty(property + ".removeBounced", "false").equalsIgnoreCase("true");
64     if (originalDeleteValue != deleteField.isSelected()) {
65       if (deleteField.isSelected())
66   props.setProperty(property + ".removeBounced", "true");
67       else
68   props.setProperty(property + ".removeBounced", "false");
69     }
70
71     return props;
72   }
73
74   /**
75    * Sets the values represented by this FilterEditor in the manager.
76    */

77   public void setValue() {
78
79     String JavaDoc oldClassName = manager.getProperty(property + ".class", "");
80     if (!oldClassName.equals(FILTER_CLASS))
81       manager.setProperty(property + ".class", FILTER_CLASS);
82
83     String JavaDoc originalAddressString = manager.getProperty(property + ".targetAddresses", "");
84     if (addressField.getText() != originalAddressString) {
85       manager.setProperty(property + ".targetAddresses", addressField.getText());
86     }
87
88     boolean originalDeleteValue = manager.getProperty(property + ".removeBounced", "false").equalsIgnoreCase("true");
89     if (originalDeleteValue != deleteField.isSelected()) {
90       if (deleteField.isSelected())
91   manager.setProperty(property + ".removeBounced", "true");
92       else
93   manager.setProperty(property + ".removeBounced", "false");
94     }
95
96   }
97
98   /**
99    * Returns the class that will be set for this FilterEditor.
100    */

101   public String JavaDoc getFilterClassValue() {
102     return FILTER_CLASS;
103   }
104
105 }
106
Popular Tags