1 2 15 package org.wings; 16 17 import javax.swing.event.ChangeEvent ; 18 import javax.swing.event.ChangeListener ; 19 import javax.swing.event.EventListenerList ; 20 21 public class SDefaultButtonModel 22 implements SButtonModel { 23 public static final Object [] EMPTY_OBJECT_ARRAY = new Object [0]; 24 25 private boolean selected; 26 private EventListenerList listeners = null; 27 28 protected transient ChangeEvent changeEvent = null; 29 30 public boolean isSelected() { 31 return selected; 32 } 33 34 public void setSelected(boolean selected) { 35 if (this.selected == selected) { 36 return; 37 } 38 this.selected = selected; 39 fireStateChanged(); 40 } 41 42 public Object [] getSelectedObjects() { 43 return new Object [0]; 44 } 45 46 public void addChangeListener(ChangeListener listener) { 47 if (listeners == null) 48 listeners = new EventListenerList (); 49 listeners.add(ChangeListener .class, listener); 50 } 51 52 public void removeChangeListener(ChangeListener listener) { 53 if (listeners == null) 54 return; 55 listeners.remove(ChangeListener .class, listener); 56 } 57 58 public ChangeListener [] getChangeListeners() { 59 return (ChangeListener []) listeners.getListeners(ChangeListener .class); 60 } 61 62 protected final Object [] getListenerList() { 63 if (listeners == null) { 64 return EMPTY_OBJECT_ARRAY; 65 } else { 66 return listeners.getListenerList(); 67 } } 69 70 protected void fireStateChanged() { 71 Object [] listeners = getListenerList(); 72 73 for (int i = listeners.length - 2; i >= 0; i -= 2) { 74 if (listeners[i] == ChangeListener .class) { 75 if (changeEvent == null) 77 changeEvent = new ChangeEvent (this); 78 ((ChangeListener ) listeners[i + 1]).stateChanged(changeEvent); 79 } 80 } 81 } 82 } 83 | Popular Tags |