summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/LightBulbLightOnEditor2.java
blob: 196f10f8d24e8b6b55d6a655c0dd28737f8d02e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* LightBulbLightOnEditor2.java */

import java.awt.*;
import java.beans.*;

public class LightBulbLightOnEditor2
extends PropertyEditorSupport
{
  boolean currentvalue;

  public void setValue(Object value)
  {
    currentvalue = ((Boolean)value).booleanValue();
  }

  public Object getValue()
  {
    return new Boolean(currentvalue);
  }

  public String getAsText()
  {
    return "" + (currentvalue ? "an" : "aus");
  }

  public void setAsText(String text)
  throws java.lang.IllegalArgumentException
  {
    System.out.println("setAsText(" + text + ")");
    if (text.equalsIgnoreCase("an")) {
      currentvalue = true;
    } else if (text.equalsIgnoreCase("aus")) {
      currentvalue = false;
    } else {
      throw new IllegalArgumentException(text);
    }
    firePropertyChange();
  }

  public String[] getTags()
  {
    return new String[]{"aus", "an"};
  }
}