Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/ButtonModel.java
38829 views
/*1* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package javax.swing;252627import java.awt.event.*;28import java.awt.*;29import javax.swing.event.*;3031/**32* State model for buttons.33* <p>34* This model is used for regular buttons, as well as check boxes35* and radio buttons, which are special kinds of buttons. In practice,36* a button's UI takes the responsibility of calling methods on its37* model to manage the state, as detailed below:38* <p>39* In simple terms, pressing and releasing the mouse over a regular40* button triggers the button and causes and <code>ActionEvent</code>41* to be fired. The same behavior can be produced via a keyboard key42* defined by the look and feel of the button (typically the SPACE BAR).43* Pressing and releasing this key while the button has44* focus will give the same results. For check boxes and radio buttons, the45* mouse or keyboard equivalent sequence just described causes the button46* to become selected.47* <p>48* In details, the state model for buttons works as follows49* when used with the mouse:50* <br>51* Pressing the mouse on top of a button makes the model both52* armed and pressed. As long as the mouse remains down,53* the model remains pressed, even if the mouse moves54* outside the button. On the contrary, the model is only55* armed while the mouse remains pressed within the bounds of56* the button (it can move in or out of the button, but the model57* is only armed during the portion of time spent within the button).58* A button is triggered, and an <code>ActionEvent</code> is fired,59* when the mouse is released while the model is armed60* - meaning when it is released over top of the button after the mouse61* has previously been pressed on that button (and not already released).62* Upon mouse release, the model becomes unarmed and unpressed.63* <p>64* In details, the state model for buttons works as follows65* when used with the keyboard:66* <br>67* Pressing the look and feel defined keyboard key while the button68* has focus makes the model both armed and pressed. As long as this key69* remains down, the model remains in this state. Releasing the key sets70* the model to unarmed and unpressed, triggers the button, and causes an71* <code>ActionEvent</code> to be fired.72*73* @author Jeff Dinkins74*/75public interface ButtonModel extends ItemSelectable {7677/**78* Indicates partial commitment towards triggering the79* button.80*81* @return <code>true</code> if the button is armed,82* and ready to be triggered83* @see #setArmed84*/85boolean isArmed();8687/**88* Indicates if the button has been selected. Only needed for89* certain types of buttons - such as radio buttons and check boxes.90*91* @return <code>true</code> if the button is selected92*/93boolean isSelected();9495/**96* Indicates if the button can be selected or triggered by97* an input device, such as a mouse pointer.98*99* @return <code>true</code> if the button is enabled100*/101boolean isEnabled();102103/**104* Indicates if the button is pressed.105*106* @return <code>true</code> if the button is pressed107*/108boolean isPressed();109110/**111* Indicates that the mouse is over the button.112*113* @return <code>true</code> if the mouse is over the button114*/115boolean isRollover();116117/**118* Marks the button as armed or unarmed.119*120* @param b whether or not the button should be armed121*/122public void setArmed(boolean b);123124/**125* Selects or deselects the button.126*127* @param b <code>true</code> selects the button,128* <code>false</code> deselects the button129*/130public void setSelected(boolean b);131132/**133* Enables or disables the button.134*135* @param b whether or not the button should be enabled136* @see #isEnabled137*/138public void setEnabled(boolean b);139140/**141* Sets the button to pressed or unpressed.142*143* @param b whether or not the button should be pressed144* @see #isPressed145*/146public void setPressed(boolean b);147148/**149* Sets or clears the button's rollover state150*151* @param b whether or not the button is in the rollover state152* @see #isRollover153*/154public void setRollover(boolean b);155156/**157* Sets the keyboard mnemonic (shortcut key or158* accelerator key) for the button.159*160* @param key an int specifying the accelerator key161*/162public void setMnemonic(int key);163164/**165* Gets the keyboard mnemonic for the button.166*167* @return an int specifying the accelerator key168* @see #setMnemonic169*/170public int getMnemonic();171172/**173* Sets the action command string that gets sent as part of the174* <code>ActionEvent</code> when the button is triggered.175*176* @param s the <code>String</code> that identifies the generated event177* @see #getActionCommand178* @see java.awt.event.ActionEvent#getActionCommand179*/180public void setActionCommand(String s);181182/**183* Returns the action command string for the button.184*185* @return the <code>String</code> that identifies the generated event186* @see #setActionCommand187*/188public String getActionCommand();189190/**191* Identifies the group the button belongs to --192* needed for radio buttons, which are mutually193* exclusive within their group.194*195* @param group the <code>ButtonGroup</code> the button belongs to196*/197public void setGroup(ButtonGroup group);198199/**200* Adds an <code>ActionListener</code> to the model.201*202* @param l the listener to add203*/204void addActionListener(ActionListener l);205206/**207* Removes an <code>ActionListener</code> from the model.208*209* @param l the listener to remove210*/211void removeActionListener(ActionListener l);212213/**214* Adds an <code>ItemListener</code> to the model.215*216* @param l the listener to add217*/218void addItemListener(ItemListener l);219220/**221* Removes an <code>ItemListener</code> from the model.222*223* @param l the listener to remove224*/225void removeItemListener(ItemListener l);226227/**228* Adds a <code>ChangeListener</code> to the model.229*230* @param l the listener to add231*/232void addChangeListener(ChangeListener l);233234/**235* Removes a <code>ChangeListener</code> from the model.236*237* @param l the listener to remove238*/239void removeChangeListener(ChangeListener l);240241}242243244