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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
public final static String PROPERTY_ON="on";
public final static String PROPERTY_COLOR="color";
private Color color=Color.RED;
private Color internalColor=color.darker();
private boolean on=false;
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public void off() {
if (on) {
on = false;
updateInternalColor();
this.pcs.firePropertyChange(PROPERTY_ON, true, false);
}
}
public void on() {
if (!on) {
on = true;
updateInternalColor();
this.pcs.firePropertyChange(PROPERTY_ON, false, true);
}
}
public boolean isOn() {
return on;
}
public void setColor(Color c) {
if( c!=null && !c.equals(color) ) {
Color oldValue = color;
color = c;
updateInternalColor();
this.pcs.firePropertyChange(PROPERTY_COLOR, oldValue, color);
}
}
public Color getColor() {
return color;
}
private void updateInternalColor() {
if ( on ) {
internalColor=color;
}
else {
internalColor=color.darker();
}
invalidate();
}
public void inverse() {
if (on) {
off();
} else {
on();
}
}
public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
pcs.addPropertyChangeListener(property, listener)
}
public void removePropertyChangeListener(String property, PropertyChangeListener listener) {
pcs.removePropertyChangeListener(property, listener)
}
} |
Partager