jdk/src/share/classes/javax/swing/ButtonModel.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * State model for buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This model is used for regular buttons, as well as check boxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * and radio buttons, which are special kinds of buttons. In practice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * a button's UI takes the responsibility of calling methods on its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * model to manage the state, as detailed below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * In simple terms, pressing and releasing the mouse over a regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * button triggers the button and causes and <code>ActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to be fired. The same behavior can be produced via a keyboard key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * defined by the look and feel of the button (typically the SPACE BAR).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Pressing and releasing this key while the button has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * focus will give the same results. For check boxes and radio buttons, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * mouse or keyboard equivalent sequence just described causes the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to become selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * In details, the state model for buttons works as follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * when used with the mouse:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Pressing the mouse on top of a button makes the model both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * armed and pressed. As long as the mouse remains down,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * the model remains pressed, even if the mouse moves
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * outside the button. On the contrary, the model is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * armed while the mouse remains pressed within the bounds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the button (it can move in or out of the button, but the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * is only armed during the portion of time spent within the button).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * A button is triggered, and an <code>ActionEvent</code> is fired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * when the mouse is released while the model is armed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * - meaning when it is released over top of the button after the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * has previously been pressed on that button (and not already released).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Upon mouse release, the model becomes unarmed and unpressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * In details, the state model for buttons works as follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * when used with the keyboard:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Pressing the look and feel defined keyboard key while the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * has focus makes the model both armed and pressed. As long as this key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * remains down, the model remains in this state. Releasing the key sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the model to unarmed and unpressed, triggers the button, and causes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>ActionEvent</code> to be fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public interface ButtonModel extends ItemSelectable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Indicates partial commitment towards triggering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return <code>true</code> if the button is armed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *         and ready to be triggered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #setArmed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    boolean isArmed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Indicates if the button has been selected. Only needed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * certain types of buttons - such as radio buttons and check boxes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @return <code>true</code> if the button is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    boolean isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Indicates if the button can be selected or triggered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * an input device, such as a mouse pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return <code>true</code> if the button is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    boolean isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Indicates if the button is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return <code>true</code> if the button is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    boolean isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Indicates that the mouse is over the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return <code>true</code> if the mouse is over the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    boolean isRollover();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Marks the button as armed or unarmed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param b whether or not the button should be armed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void setArmed(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Selects or deselects the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param b <code>true</code> selects the button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *          <code>false</code> deselects the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setSelected(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Enables or disables the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param b whether or not the button should be enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void setEnabled(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Sets the button to pressed or unpressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param b whether or not the button should be pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #isPressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void setPressed(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Sets or clears the button's rollover state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param b whether or not the button is in the rollover state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #isRollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void setRollover(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Sets the keyboard mnemonic (shortcut key or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * accelerator key) for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param key an int specifying the accelerator key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void setMnemonic(int key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Gets the keyboard mnemonic for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return an int specifying the accelerator key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #setMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public int  getMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Sets the action command string that gets sent as part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <code>ActionEvent</code> when the button is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param s the <code>String</code> that identifies the generated event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see #getActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see java.awt.event.ActionEvent#getActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void setActionCommand(String s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Returns the action command string for the button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return the <code>String</code> that identifies the generated event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #setActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public String getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Identifies the group the button belongs to --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * needed for radio buttons, which are mutually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * exclusive within their group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param group the <code>ButtonGroup</code> the button belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void setGroup(ButtonGroup group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Adds an <code>ActionListener</code> to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param l the listener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    void addActionListener(ActionListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Removes an <code>ActionListener</code> from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param l the listener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    void removeActionListener(ActionListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Adds an <code>ItemListener</code> to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param l the listener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    void addItemListener(ItemListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Removes an <code>ItemListener</code> from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param l the listener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    void removeItemListener(ItemListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Adds a <code>ChangeListener</code> to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param l the listener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    void addChangeListener(ChangeListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Removes a <code>ChangeListener</code> from the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param l the listener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    void removeChangeListener(ChangeListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
}