Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / plaf / basic / BasicButtonListener.java
blob48451c2373abbf843bd44953ed9cf127617102f2
1 /* BasicButtonListener.java --
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package javax.swing.plaf.basic;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.FocusEvent;
43 import java.awt.event.FocusListener;
44 import java.awt.event.InputEvent;
45 import java.awt.event.MouseEvent;
46 import java.awt.event.MouseListener;
47 import java.awt.event.MouseMotionListener;
48 import java.beans.PropertyChangeEvent;
49 import java.beans.PropertyChangeListener;
51 import javax.swing.AbstractAction;
52 import javax.swing.AbstractButton;
53 import javax.swing.ButtonModel;
54 import javax.swing.JComponent;
55 import javax.swing.event.ChangeEvent;
56 import javax.swing.event.ChangeListener;
58 public class BasicButtonListener
59 implements MouseListener, MouseMotionListener, FocusListener,
60 ChangeListener, PropertyChangeListener
62 public BasicButtonListener(AbstractButton b)
64 // Do nothing here.
67 public void propertyChange(PropertyChangeEvent e)
71 protected void checkOpacity(AbstractButton b)
75 public void focusGained(FocusEvent e)
77 if (e.getSource() instanceof AbstractButton)
79 AbstractButton button = (AbstractButton) e.getSource();
80 if (button.isFocusPainted())
81 button.repaint();
85 public void focusLost(FocusEvent e)
87 if (e.getSource() instanceof AbstractButton)
89 AbstractButton button = (AbstractButton) e.getSource();
90 ButtonModel model = button.getModel();
91 model.setArmed(false);
93 if (button.isFocusPainted())
94 button.repaint();
98 public void installKeyboardActions(JComponent c)
100 c.getActionMap().put("pressed",
101 new AbstractAction()
103 public void actionPerformed(ActionEvent e)
105 AbstractButton button = (AbstractButton) e.getSource();
106 ButtonModel model = button.getModel();
107 // It is important that these transitions happen in this order.
108 model.setArmed(true);
109 model.setPressed(true);
113 c.getActionMap().put("released",
114 new AbstractAction()
116 public void actionPerformed(ActionEvent e)
118 AbstractButton button = (AbstractButton) e.getSource();
119 ButtonModel model = button.getModel();
120 // It is important that these transitions happen in this order.
121 model.setPressed(false);
122 model.setArmed(false);
124 });
127 public void uninstallKeyboardActions(JComponent c)
129 c.getActionMap().put("pressed", null);
130 c.getActionMap().put("released", null);
133 public void stateChanged(ChangeEvent e)
137 public void mouseMoved(MouseEvent e)
141 public void mouseDragged(MouseEvent e)
145 public void mouseClicked(MouseEvent e)
150 * Accept a mouse press event and arm the button.
152 * @param e The mouse press event to accept
154 public void mousePressed(MouseEvent e)
156 if (e.getSource() instanceof AbstractButton)
158 AbstractButton button = (AbstractButton) e.getSource();
159 ButtonModel model = button.getModel();
160 if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
162 // It is important that these transitions happen in this order.
163 model.setArmed(true);
164 model.setPressed(true);
170 * Accept a mouse release event and set the button's
171 * "pressed" property to <code>true</code>, if the model
172 * is armed. If the model is not armed, ignore the event.
174 * @param e The mouse release event to accept
176 public void mouseReleased(MouseEvent e)
178 if (e.getSource() instanceof AbstractButton)
180 AbstractButton button = (AbstractButton) e.getSource();
181 ButtonModel model = button.getModel();
182 if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
184 // It is important that these transitions happen in this order.
185 model.setPressed(false);
186 model.setArmed(false);
192 * Accept a mouse enter event and set the button's "rollover" property to
193 * <code>true</code>, if the button's "rolloverEnabled" property is
194 * <code>true</code>. If the button is currently armed and the mouse
195 * button is not held down, this enter event will also disarm the model.
197 * @param e The mouse enter event to accept
199 public void mouseEntered(MouseEvent e)
201 if (e.getSource() instanceof AbstractButton)
203 AbstractButton button = (AbstractButton) e.getSource();
204 ButtonModel model = button.getModel();
205 if (button.isRolloverEnabled())
206 model.setRollover(true);
208 if (model.isPressed()
209 && (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
210 model.setArmed(true);
211 else
212 model.setArmed(false);
217 * Accept a mouse exit event and set the button's model's "rollover"
218 * property to <code>false</code>, if it's "rolloverEnabled" property is
219 * <code>true</code>. Also disarm the button.
221 * @param e The mouse exit event to accept
223 public void mouseExited(MouseEvent e)
225 if (e.getSource() instanceof AbstractButton)
227 AbstractButton button = (AbstractButton) e.getSource();
228 ButtonModel model = button.getModel();
229 if (button.isRolloverEnabled())
230 model.setRollover(false);
231 model.setArmed(false);