KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SDefaultButtonModel


1 /* $Id: SDefaultButtonModel.java,v 1.3 2004/12/01 07:54:07 hengels Exp $ */
2 /*
3  * $Id: SDefaultButtonModel.java,v 1.3 2004/12/01 07:54:07 hengels Exp $
4  * Copyright 2000,2005 wingS development team.
5  *
6  * This file is part of wingS (http://www.j-wings.org).
7  *
8  * wingS is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1
11  * of the License, or (at your option) any later version.
12  *
13  * Please see COPYING for the complete licence.
14  */

15 package org.wings;
16
17 import javax.swing.event.ChangeEvent JavaDoc;
18 import javax.swing.event.ChangeListener JavaDoc;
19 import javax.swing.event.EventListenerList JavaDoc;
20
21 public class SDefaultButtonModel
22         implements SButtonModel {
23     public static final Object JavaDoc[] EMPTY_OBJECT_ARRAY = new Object JavaDoc[0];
24
25     private boolean selected;
26     private EventListenerList JavaDoc listeners = null;
27
28     protected transient ChangeEvent JavaDoc 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 JavaDoc[] getSelectedObjects() {
43         return new Object JavaDoc[0];
44     }
45
46     public void addChangeListener(ChangeListener JavaDoc listener) {
47         if (listeners == null)
48             listeners = new EventListenerList JavaDoc();
49         listeners.add(ChangeListener JavaDoc.class, listener);
50     }
51
52     public void removeChangeListener(ChangeListener JavaDoc listener) {
53         if (listeners == null)
54             return;
55         listeners.remove(ChangeListener JavaDoc.class, listener);
56     }
57
58     public ChangeListener JavaDoc[] getChangeListeners() {
59         return (ChangeListener JavaDoc[]) listeners.getListeners(ChangeListener JavaDoc.class);
60     }
61
62     protected final Object JavaDoc[] getListenerList() {
63         if (listeners == null) {
64             return EMPTY_OBJECT_ARRAY;
65         } else {
66             return listeners.getListenerList();
67         } // end of else
68
}
69
70     protected void fireStateChanged() {
71         Object JavaDoc[] listeners = getListenerList();
72
73         for (int i = listeners.length - 2; i >= 0; i -= 2) {
74             if (listeners[i] == ChangeListener JavaDoc.class) {
75                 // Lazily create the event:
76
if (changeEvent == null)
77                     changeEvent = new ChangeEvent JavaDoc(this);
78                 ((ChangeListener JavaDoc) listeners[i + 1]).stateChanged(changeEvent);
79             }
80         }
81     }
82 }
83
Popular Tags