1 /* 2 Copyright 2002-2006 Martin van den Bemt 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package org.xulux.guilayer.swing.listeners; 17 18 import javax.swing.JButton; 19 import javax.swing.event.ChangeEvent; 20 import javax.swing.event.ChangeListener; 21 22 /** 23 * This listeners detects when the defaultbutton is used. 24 * 25 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a> 26 * @version $Id: DefaultButtonChangeListener.java,v 1.1 2005/12/18 12:58:21 mvdb Exp $ 27 */ 28 public class DefaultButtonChangeListener implements ChangeListener { 29 30 /** 31 * 32 */ 33 public DefaultButtonChangeListener() { 34 super(); 35 } 36 37 /** 38 * Mainly used to release any pending events when the defaultbutton is used by 39 * eg hitting the enter key. 40 * 41 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) 42 */ 43 public void stateChanged(ChangeEvent e) { 44 if (e.getSource() instanceof JButton) { 45 JButton button = (JButton) e.getSource(); 46 if (button.getModel().isArmed() && button.getModel().isPressed()) { 47 button.requestFocus(); 48 } 49 } 50 } 51 52 }