1 /* DefaultButtonModel.java --
2    Copyright (C) 2002 Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20 
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25 
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37 
38 
39 package javax.swing;
40 
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.ItemEvent;
44 import java.awt.event.ItemListener;
45 import java.io.Serializable;
46 import java.util.EventListener;
47 import java.util.Vector;
48 import javax.swing.event.ChangeEvent;
49 import javax.swing.event.ChangeListener;
50 import javax.swing.event.EventListenerList;
51 
52 public class DefaultButtonModel
53   implements ButtonModel, Serializable
54 {
55   static final long serialVersionUID = -5342609566534980231L;
56 
57     Vector actions          = new Vector();
58 
59     Vector items    = new Vector();
60     Vector changes  = new Vector();
61     ButtonGroup group;
62     JComponent comp;
63 
64 
DefaultButtonModel(JComponent a)65     DefaultButtonModel(JComponent a)
66     {
67 	comp = a;
68     }
69 
70 
getSelectedObjects()71     public Object[] getSelectedObjects()
72     {
73 	return null;
74     }
75 
76 
fireItemStateChanged(ItemEvent event)77     public void fireItemStateChanged(ItemEvent event)
78     {
79 	for (int i=0;i<items.size();i++)
80 	    {
81 		ItemListener a = (ItemListener) items.get(i);
82 		a.itemStateChanged(event);
83 	    }
84     }
fireStateChanged(ChangeEvent event)85     public void fireStateChanged(ChangeEvent event)
86     {
87 	for (int i=0;i<changes.size();i++)
88 	    {
89 		ChangeListener a = (ChangeListener) changes.get(i);
90 		a.stateChanged(event);
91 	    }
92     }
fireActionPerformed(ActionEvent event)93     public void fireActionPerformed(ActionEvent event)
94     {
95 	for (int i=0;i<actions.size();i++)
96 	    {
97 		ActionListener a = (ActionListener) actions.get(i);
98 		a.actionPerformed(event);
99 	    }
100     }
101 
102     boolean arm;
isArmed()103     public boolean isArmed()          { return arm; }
setArmed(boolean b)104     public void setArmed(boolean b)   { arm = b; }
105 
106     boolean enabled = true;
isEnabled()107     public boolean isEnabled()         { return enabled; }
setEnabled(boolean b)108     public void setEnabled(boolean b)  { enabled = b; }
109 
110     boolean pressed;
setPressed(boolean b)111     public void setPressed(boolean b)
112     {
113 	pressed = b;
114     }
isPressed()115     public boolean isPressed()         { return pressed; }
116 
117 
removeActionListener(ActionListener l)118     public void removeActionListener(ActionListener l) { actions.removeElement(l); }
addActionListener(ActionListener l)119     public void addActionListener(ActionListener l)
120     {
121 	//	comp.enableEvents( AWTEvent.ACTION_EVENT_MASK );
122 	actions.addElement(l);
123     }
124 
addItemListener(ItemListener l)125     public void addItemListener(ItemListener l)        { items.addElement(l); }
removeItemListener(ItemListener l)126     public void removeItemListener(ItemListener l)     { items.removeElement(l); }
127 
addChangeListener(ChangeListener l)128     public void addChangeListener(ChangeListener l)    { changes.addElement(l); }
removeChangeListener(ChangeListener l)129     public void removeChangeListener(ChangeListener l) { changes.removeElement(l); }
130 
131     boolean roll;
setRollover(boolean b)132     public void setRollover(boolean b) { roll = b; }
isRollover()133     public boolean isRollover()        { return roll; }
134 
135     int mne;
getMnemonic()136     public int  getMnemonic()        { return mne; }
setMnemonic(int key)137     public void setMnemonic(int key) { mne = key; }
138 
139     String com;
setActionCommand(String s)140     public void setActionCommand(String s) { com = s; }
getActionCommand()141     public String getActionCommand()       { return com; }
142 
setGroup(ButtonGroup group)143     public void setGroup(ButtonGroup group)
144     {
145 	this.group = group;
146     }
147 
148     boolean sel;
setSelected(boolean b)149     public void setSelected(boolean b)
150     {
151 	if (group != null)
152 	    {
153 		if (b == true)
154 		    {
155 			System.out.println("selected button in group:"+this);
156 			group.setSelected(this, b);
157 			sel = true;
158 		    }
159 		else
160 		    {
161 			System.out.println("deselected button in group: " + this);
162 			sel = false;
163 		    }
164 	    }
165 	else
166 	    {
167 		sel = b;
168 	    }
169     }
isSelected()170     public boolean isSelected()        { return sel; }
171 }
172 
173 
174 
175 
176 
177 
178 
179