-/*\r
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.\r
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
- *\r
- * This code is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU General Public License version 2 only, as\r
- * published by the Free Software Foundation. Oracle designates this\r
- * particular file as subject to the "Classpath" exception as provided\r
- * by Oracle in the LICENSE file that accompanied this code.\r
- *\r
- * This code is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
- * version 2 for more details (a copy is included in the LICENSE file that\r
- * accompanied this code).\r
- *\r
- * You should have received a copy of the GNU General Public License version\r
- * 2 along with this work; if not, write to the Free Software Foundation,\r
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
- * or visit www.oracle.com if you need additional information or have any\r
- * questions.\r
- */\r
-\r
-package swingjs.plaf;\r
-\r
-import jsjava.awt.event.ActionEvent;\r
-import jsjava.awt.event.FocusEvent;\r
-import jsjava.awt.event.FocusListener;\r
-import jsjava.awt.event.InputEvent;\r
-import jsjava.awt.event.MouseEvent;\r
-import jsjava.awt.event.MouseListener;\r
-import jsjava.awt.event.MouseMotionListener;\r
-import jsjava.beans.PropertyChangeEvent;\r
-import jsjava.beans.PropertyChangeListener;\r
-import jsjavax.swing.AbstractButton;\r
-import jsjavax.swing.ButtonModel;\r
-import jsjavax.swing.InputMap;\r
-import jsjavax.swing.JComponent;\r
-import jsjavax.swing.KeyStroke;\r
-import jsjavax.swing.SwingUtilities;\r
-import jsjavax.swing.event.ChangeEvent;\r
-import jsjavax.swing.event.ChangeListener;\r
-import jsjavax.swing.plaf.ComponentInputMapUIResource;\r
-import jsjavax.swing.plaf.ComponentUI;\r
-import jssun.swing.UIAction;\r
-\r
-/**\r
- * Button Listener\r
- *\r
- * @author Jeff Dinkins\r
- * @author Arnaud Weber (keyboard UI support)\r
- */\r
-\r
-public class JSButtonListener implements MouseListener, MouseMotionListener,\r
- FocusListener, ChangeListener, PropertyChangeListener\r
-{\r
- private long lastPressedTimestamp = -1;\r
- private boolean shouldDiscardRelease = false;\r
- private AbstractButton btn;\r
-\r
- /**\r
- * Populates Buttons actions.\r
- */\r
- static void loadActionMap(LazyActionMap map) {\r
- map.put(new Actions(Actions.PRESS));\r
- map.put(new Actions(Actions.RELEASE));\r
- }\r
-\r
-\r
- public JSButtonListener(AbstractButton b) {\r
- btn = b;\r
- }\r
-\r
- public void propertyChange(PropertyChangeEvent e) {\r
- String prop = e.getPropertyName();\r
- //System.out.println("JSButtonListener property change: " + prop + " " + e.getSource());\r
- if (prop == AbstractButton.MNEMONIC_CHANGED_PROPERTY) {\r
- updateMnemonicBinding((AbstractButton) e.getSource());\r
- } else if (prop == AbstractButton.CONTENT_AREA_FILLED_CHANGED_PROPERTY) {\r
- checkOpacity((AbstractButton) e.getSource());\r
- } else if (prop == AbstractButton.TEXT_CHANGED_PROPERTY || "font" == prop\r
- || "foreground" == prop) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- ((JSComponentUI) (Object) b.getUI()).notifyPropertyChanged(prop);\r
- }\r
- }\r
-\r
- protected void checkOpacity(AbstractButton b) {\r
- b.setOpaque( b.isContentAreaFilled() );\r
- }\r
-\r
- /**\r
- * Register default key actions: pressing space to "click" a\r
- * button and registring the keyboard mnemonic (if any).\r
- */\r
- public void installKeyboardActions(JComponent c) {\r
- AbstractButton b = (AbstractButton)c;\r
- // Update the mnemonic binding.\r
- updateMnemonicBinding(b);\r
-\r
- LazyActionMap.installLazyActionMap(c, JSButtonListener.class,\r
- "Button.actionMap");\r
-\r
- InputMap km = getInputMap(JComponent.WHEN_FOCUSED, c);\r
-\r
- SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, km);\r
- }\r
-\r
- /**\r
- * Unregister's default key actions\r
- */\r
- public void uninstallKeyboardActions(JComponent c) {\r
- SwingUtilities.replaceUIInputMap(c, JComponent.\r
- WHEN_IN_FOCUSED_WINDOW, null);\r
- SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null);\r
- SwingUtilities.replaceUIActionMap(c, null);\r
- }\r
-\r
- /**\r
- * Returns the InputMap for condition <code>condition</code>. Called as\r
- * part of <code>installKeyboardActions</code>.\r
- */\r
- InputMap getInputMap(int condition, JComponent c) {\r
-// if (condition == JComponent.WHEN_FOCUSED) {\r
-// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(\r
-// ((AbstractButton)c).getUI(), BasicButtonUI.class);\r
-// if (ui != null) {\r
-// return (InputMap)DefaultLookup.get(\r
-// c, ui, ui.getPropertyPrefix() + "focusInputMap");\r
-// }\r
-// }\r
- return null;\r
- }\r
-\r
- /**\r
- * Resets the binding for the mnemonic in the WHEN_IN_FOCUSED_WINDOW\r
- * UI InputMap.\r
- */\r
- void updateMnemonicBinding(AbstractButton b) {\r
- int m = b.getMnemonic();\r
- if(m != 0) {\r
- InputMap map = SwingUtilities.getUIInputMap(\r
- b, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
-\r
- if (map == null) {\r
- map = new ComponentInputMapUIResource(b);\r
- SwingUtilities.replaceUIInputMap(b,\r
- JComponent.WHEN_IN_FOCUSED_WINDOW, map);\r
- }\r
- map.clear();\r
- map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, false),\r
- "pressed");\r
- map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, true),\r
- "released");\r
- map.put(KeyStroke.getKeyStroke(m, 0, true), "released");\r
- }\r
- else {\r
- InputMap map = SwingUtilities.getUIInputMap(b, JComponent.\r
- WHEN_IN_FOCUSED_WINDOW);\r
- if (map != null) {\r
- map.clear();\r
- }\r
- }\r
- }\r
-\r
- public void stateChanged(ChangeEvent e) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- b.repaint();\r
- }\r
-\r
- public void focusGained(FocusEvent e) {\r
-// AbstractButton b = (AbstractButton) e.getSource();\r
-// if (b instanceof JButton && ((JButton)b).isDefaultCapable()) {\r
-// JRootPane root = b.getRootPane();\r
-// if (root != null) {\r
-// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(\r
-// ((AbstractButton)b).getUI(), BasicButtonUI.class);\r
-// if (ui != null && DefaultLookup.getBoolean(b, ui,\r
-// ui.getPropertyPrefix() +\r
-// "defaultButtonFollowsFocus", true)) {\r
-// root.putClientProperty("temporaryDefaultButton", b);\r
-// root.setDefaultButton((JButton)b);\r
-// root.putClientProperty("temporaryDefaultButton", null);\r
-// }\r
-// }\r
-// }\r
-// b.repaint();\r
- }\r
-\r
- public void focusLost(FocusEvent e) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
-// JRootPane root = b.getRootPane();\r
-// if (root != null) {\r
-// JButton initialDefault = (JButton)root.getClientProperty("initialDefaultButton");\r
-// if (b != initialDefault) {\r
-// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(\r
-// ((AbstractButton)b).getUI(), BasicButtonUI.class);\r
-// if (ui != null && DefaultLookup.getBoolean(b, ui,\r
-// ui.getPropertyPrefix() +\r
-// "defaultButtonFollowsFocus", true)) {\r
-// root.setDefaultButton(initialDefault);\r
-// }\r
-// }\r
-// }\r
-//\r
- ButtonModel model = b.getModel();\r
- model.setArmed(false);\r
- model.setPressed(false);\r
-//\r
-// b.repaint();\r
- }\r
-\r
- public void mouseMoved(MouseEvent e) {\r
- }\r
-\r
-\r
- public void mouseDragged(MouseEvent e) {\r
- }\r
-\r
- public void mouseClicked(MouseEvent e) {\r
- }\r
-\r
- public void mousePressed(MouseEvent e) {\r
- if (SwingUtilities.isLeftMouseButton(e)) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- if (!b.contains(e.getX(), e.getY()))\r
- return;\r
- // We need to check the state before and after the button click \r
- // for radio and checkboxes to make sure the DOM button actually got hit.\r
- // mousePress is an "arm"; mouseRelease is a "click"\r
- \r
- ((JSButtonUI) (ComponentUI) b.getUI()).verifyButtonClick(false);\r
- long multiClickThreshhold = b.getMultiClickThreshhold();\r
- long lastTime = lastPressedTimestamp;\r
- long currentTime = lastPressedTimestamp = e.getWhen();\r
- if (lastTime != -1 && currentTime - lastTime < multiClickThreshhold) {\r
- shouldDiscardRelease = true;\r
- return;\r
- }\r
-\r
- //System.out.println("JSButtonListener press " + b.getName() + " " + e);\r
-\r
- ButtonModel model = b.getModel();\r
- if (!model.isEnabled()) {\r
- // Disabled buttons ignore all input...\r
- return;\r
- }\r
- if (!model.isArmed()) {\r
- // button not armed, should be\r
- model.setArmed(true);\r
- }\r
- model.setPressed(true);\r
- if (!b.hasFocus() && b.isRequestFocusEnabled()) {\r
- b.requestFocus();\r
- }\r
- }\r
- };\r
-\r
- public void mouseReleased(MouseEvent e) {\r
- if (SwingUtilities.isLeftMouseButton(e)) {\r
- // Support for multiClickThreshhold\r
- if (shouldDiscardRelease) {\r
- shouldDiscardRelease = false;\r
- return;\r
- }\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- if (!((JSButtonUI) (ComponentUI) b.getUI()).verifyButtonClick(true))\r
- return;\r
- \r
- //System.out.println("JSButtonListener released " + b.getName() + " " + e);\r
-\r
- ButtonModel model = b.getModel();\r
- model.setPressed(false);\r
- model.setArmed(false);\r
- }\r
- };\r
-\r
- public void mouseEntered(MouseEvent e) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- ButtonModel model = b.getModel();\r
- if (b.isRolloverEnabled() && !SwingUtilities.isLeftMouseButton(e)) {\r
- model.setRollover(true);\r
- }\r
- if (model.isPressed())\r
- model.setArmed(true);\r
- };\r
-\r
- public void mouseExited(MouseEvent e) {\r
- AbstractButton b = (AbstractButton) e.getSource();\r
- ButtonModel model = b.getModel();\r
- if(b.isRolloverEnabled()) {\r
- model.setRollover(false);\r
- }\r
- model.setArmed(false);\r
- };\r
-\r
-\r
- /**\r
- * Actions for Buttons. Two types of action are supported:\r
- * pressed: Moves the button to a pressed state\r
- * released: Disarms the button.\r
- */\r
- private static class Actions extends UIAction {\r
- private static final String PRESS = "pressed";\r
- private static final String RELEASE = "released";\r
-\r
- Actions(String name) {\r
- super(name);\r
- }\r
-\r
- public void actionPerformed(ActionEvent e) {\r
- AbstractButton b = (AbstractButton)e.getSource();\r
- String key = getName();\r
- if (key == PRESS) {\r
- ButtonModel model = b.getModel();\r
- model.setArmed(true);\r
- model.setPressed(true);\r
- if(!b.hasFocus()) {\r
- b.requestFocus();\r
- }\r
- }\r
- else if (key == RELEASE) {\r
- ButtonModel model = b.getModel();\r
- model.setPressed(false);\r
- model.setArmed(false);\r
- }\r
- }\r
-\r
- public boolean isEnabled(Object sender) {\r
- if(sender != null && (sender instanceof AbstractButton) &&\r
- !((AbstractButton)sender).getModel().isEnabled()) {\r
- return false;\r
- } else {\r
- return true;\r
- }\r
- }\r
- }\r
-}\r
+/*
+ * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package swingjs.plaf;
+
+import jsjava.awt.event.ActionEvent;
+import jsjava.awt.event.FocusEvent;
+import jsjava.awt.event.FocusListener;
+import jsjava.awt.event.InputEvent;
+import jsjava.awt.event.MouseEvent;
+import jsjava.awt.event.MouseListener;
+import jsjava.awt.event.MouseMotionListener;
+import jsjava.beans.PropertyChangeEvent;
+import jsjava.beans.PropertyChangeListener;
+import jsjavax.swing.AbstractButton;
+import jsjavax.swing.ButtonModel;
+import jsjavax.swing.InputMap;
+import jsjavax.swing.JComponent;
+import jsjavax.swing.KeyStroke;
+import jsjavax.swing.SwingUtilities;
+import jsjavax.swing.event.ChangeEvent;
+import jsjavax.swing.event.ChangeListener;
+import jsjavax.swing.plaf.ComponentInputMapUIResource;
+import jsjavax.swing.plaf.ComponentUI;
+import jssun.swing.UIAction;
+
+/**
+ * Button Listener
+ *
+ * @author Jeff Dinkins
+ * @author Arnaud Weber (keyboard UI support)
+ */
+
+public class JSButtonListener implements MouseListener, MouseMotionListener,
+ FocusListener, ChangeListener, PropertyChangeListener
+{
+ private long lastPressedTimestamp = -1;
+ private boolean shouldDiscardRelease = false;
+ private AbstractButton btn;
+
+ /**
+ * Populates Buttons actions.
+ */
+ static void loadActionMap(LazyActionMap map) {
+ map.put(new Actions(Actions.PRESS));
+ map.put(new Actions(Actions.RELEASE));
+ }
+
+
+ public JSButtonListener(AbstractButton b) {
+ btn = b;
+ }
+
+ public void propertyChange(PropertyChangeEvent e) {
+ String prop = e.getPropertyName();
+ //System.out.println("JSButtonListener property change: " + prop + " " + e.getSource());
+ if (prop == AbstractButton.MNEMONIC_CHANGED_PROPERTY) {
+ updateMnemonicBinding((AbstractButton) e.getSource());
+ } else if (prop == AbstractButton.CONTENT_AREA_FILLED_CHANGED_PROPERTY) {
+ checkOpacity((AbstractButton) e.getSource());
+ } else if (prop == AbstractButton.TEXT_CHANGED_PROPERTY || "font" == prop
+ || "foreground" == prop) {
+ AbstractButton b = (AbstractButton) e.getSource();
+ ((JSComponentUI) (Object) b.getUI()).notifyPropertyChanged(prop);
+ }
+ }
+
+ protected void checkOpacity(AbstractButton b) {
+ b.setOpaque( b.isContentAreaFilled() );
+ }
+
+ /**
+ * Register default key actions: pressing space to "click" a
+ * button and registring the keyboard mnemonic (if any).
+ */
+ public void installKeyboardActions(JComponent c) {
+ AbstractButton b = (AbstractButton)c;
+ // Update the mnemonic binding.
+ updateMnemonicBinding(b);
+
+ LazyActionMap.installLazyActionMap(c, JSButtonListener.class,
+ "Button.actionMap");
+
+ InputMap km = getInputMap(JComponent.WHEN_FOCUSED, c);
+
+ SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, km);
+ }
+
+ /**
+ * Unregister's default key actions
+ */
+ public void uninstallKeyboardActions(JComponent c) {
+ SwingUtilities.replaceUIInputMap(c, JComponent.
+ WHEN_IN_FOCUSED_WINDOW, null);
+ SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null);
+ SwingUtilities.replaceUIActionMap(c, null);
+ }
+
+ /**
+ * Returns the InputMap for condition <code>condition</code>. Called as
+ * part of <code>installKeyboardActions</code>.
+ */
+ InputMap getInputMap(int condition, JComponent c) {
+// if (condition == JComponent.WHEN_FOCUSED) {
+// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(
+// ((AbstractButton)c).getUI(), BasicButtonUI.class);
+// if (ui != null) {
+// return (InputMap)DefaultLookup.get(
+// c, ui, ui.getPropertyPrefix() + "focusInputMap");
+// }
+// }
+ return null;
+ }
+
+ /**
+ * Resets the binding for the mnemonic in the WHEN_IN_FOCUSED_WINDOW
+ * UI InputMap.
+ */
+ void updateMnemonicBinding(AbstractButton b) {
+ int m = b.getMnemonic();
+ if(m != 0) {
+ InputMap map = SwingUtilities.getUIInputMap(
+ b, JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+ if (map == null) {
+ map = new ComponentInputMapUIResource(b);
+ SwingUtilities.replaceUIInputMap(b,
+ JComponent.WHEN_IN_FOCUSED_WINDOW, map);
+ }
+ map.clear();
+ map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, false),
+ "pressed");
+ map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, true),
+ "released");
+ map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
+ }
+ else {
+ InputMap map = SwingUtilities.getUIInputMap(b, JComponent.
+ WHEN_IN_FOCUSED_WINDOW);
+ if (map != null) {
+ map.clear();
+ }
+ }
+ }
+
+ public void stateChanged(ChangeEvent e) {
+ AbstractButton b = (AbstractButton) e.getSource();
+ b.repaint();
+ }
+
+ public void focusGained(FocusEvent e) {
+// AbstractButton b = (AbstractButton) e.getSource();
+// if (b instanceof JButton && ((JButton)b).isDefaultCapable()) {
+// JRootPane root = b.getRootPane();
+// if (root != null) {
+// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(
+// ((AbstractButton)b).getUI(), BasicButtonUI.class);
+// if (ui != null && DefaultLookup.getBoolean(b, ui,
+// ui.getPropertyPrefix() +
+// "defaultButtonFollowsFocus", true)) {
+// root.putClientProperty("temporaryDefaultButton", b);
+// root.setDefaultButton((JButton)b);
+// root.putClientProperty("temporaryDefaultButton", null);
+// }
+// }
+// }
+// b.repaint();
+ }
+
+ public void focusLost(FocusEvent e) {
+ AbstractButton b = (AbstractButton) e.getSource();
+// JRootPane root = b.getRootPane();
+// if (root != null) {
+// JButton initialDefault = (JButton)root.getClientProperty("initialDefaultButton");
+// if (b != initialDefault) {
+// BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(
+// ((AbstractButton)b).getUI(), BasicButtonUI.class);
+// if (ui != null && DefaultLookup.getBoolean(b, ui,
+// ui.getPropertyPrefix() +
+// "defaultButtonFollowsFocus", true)) {
+// root.setDefaultButton(initialDefault);
+// }
+// }
+// }
+//
+ ButtonModel model = b.getModel();
+ model.setArmed(false);
+ model.setPressed(false);
+//
+// b.repaint();
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ }
+
+
+ public void mouseDragged(MouseEvent e) {
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ AbstractButton b = (AbstractButton) e.getSource();
+ if (!b.contains(e.getX(), e.getY()))
+ return;
+ // We need to check the state before and after the button click
+ // for radio and checkboxes to make sure the DOM button actually got hit.
+ // mousePress is an "arm"; mouseRelease is a "click"
+
+ ((JSButtonUI) (ComponentUI) b.getUI()).verifyButtonClick(false);
+ long multiClickThreshhold = b.getMultiClickThreshhold();
+ long lastTime = lastPressedTimestamp;
+ long currentTime = lastPressedTimestamp = e.getWhen();
+ if (lastTime != -1 && currentTime - lastTime < multiClickThreshhold) {
+ shouldDiscardRelease = true;
+ return;
+ }
+
+ //System.out.println("JSButtonListener press " + b.getName() + " " + e);
+
+ ButtonModel model = b.getModel();
+ if (!model.isEnabled()) {
+ // Disabled buttons ignore all input...
+ return;
+ }
+ if (!model.isArmed()) {
+ // button not armed, should be
+ model.setArmed(true);
+ }
+ model.setPressed(true);
+ if (!b.hasFocus() && b.isRequestFocusEnabled()) {
+ b.requestFocus();
+ }
+ }
+ };
+
+ public void mouseReleased(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ // Support for multiClickThreshhold
+ if (shouldDiscardRelease) {
+ shouldDiscardRelease = false;
+ return;
+ }
+ AbstractButton b = (AbstractButton) e.getSource();
+ if (!((JSButtonUI) (ComponentUI) b.getUI()).verifyButtonClick(true))
+ return;
+
+ //System.out.println("JSButtonListener released " + b.getName() + " " + e);
+
+ ButtonModel model = b.getModel();
+ model.setPressed(false);
+ model.setArmed(false);
+ }
+ };
+
+ public void mouseEntered(MouseEvent e) {
+ AbstractButton b = (AbstractButton) e.getSource();
+ ButtonModel model = b.getModel();
+ if (b.isRolloverEnabled() && !SwingUtilities.isLeftMouseButton(e)) {
+ model.setRollover(true);
+ }
+ if (model.isPressed())
+ model.setArmed(true);
+ };
+
+ public void mouseExited(MouseEvent e) {
+ AbstractButton b = (AbstractButton) e.getSource();
+ ButtonModel model = b.getModel();
+ if(b.isRolloverEnabled()) {
+ model.setRollover(false);
+ }
+ model.setArmed(false);
+ };
+
+
+ /**
+ * Actions for Buttons. Two types of action are supported:
+ * pressed: Moves the button to a pressed state
+ * released: Disarms the button.
+ */
+ private static class Actions extends UIAction {
+ private static final String PRESS = "pressed";
+ private static final String RELEASE = "released";
+
+ Actions(String name) {
+ super(name);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ AbstractButton b = (AbstractButton)e.getSource();
+ String key = getName();
+ if (key == PRESS) {
+ ButtonModel model = b.getModel();
+ model.setArmed(true);
+ model.setPressed(true);
+ if(!b.hasFocus()) {
+ b.requestFocus();
+ }
+ }
+ else if (key == RELEASE) {
+ ButtonModel model = b.getModel();
+ model.setPressed(false);
+ model.setArmed(false);
+ }
+ }
+
+ public boolean isEnabled(Object sender) {
+ if(sender != null && (sender instanceof AbstractButton) &&
+ !((AbstractButton)sender).getModel().isEnabled()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+}
\ No newline at end of file