3101 lines · 109.2 KB · Java
RawDownload
     * @return the value of the <code>rolloverEnabled</code> property     * @see #setRolloverEnabled     */    public boolean isRolloverEnabled() {        return rolloverEnabled;    }     /**     * Sets the <code>rolloverEnabled</code> property, which     * must be <code>true</code> for rollover effects to occur.     * The default value for the <code>rolloverEnabled</code>     * property is <code>false</code>.     * Some look and feels might not implement rollover effects;     * they will ignore this property.     *     * @param b if <code>true</code>, rollover effects should be painted     * @see #isRolloverEnabled     * @beaninfo     *        bound: true     *    attribute: visualUpdate true     *  description: Whether rollover effects should be enabled.     */    public void setRolloverEnabled(boolean b) {        boolean oldValue = rolloverEnabled;        rolloverEnabled = b;        rolloverEnabledSet = true;        firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);        if (b != oldValue) {            repaint();        }    }     /**     * Returns the keyboard mnemonic from the the current model.     * @return the keyboard mnemonic from the model     */    public int getMnemonic() {        return mnemonic;    }     /**     * Sets the keyboard mnemonic on the current model.     * The mnemonic is the key which when combined with the look and feel's     * mouseless modifier (usually Alt) will activate this button     * if focus is contained somewhere within this button's ancestor     * window.     * <p>     * A mnemonic must correspond to a single key on the keyboard     * and should be specified using one of the <code>VK_XXX</code>     * keycodes defined in <code>java.awt.event.KeyEvent</code>.     * These codes and the wider array of codes for international     * keyboards may be obtained through     * <code>java.awt.event.KeyEvent.getExtendedKeyCodeForChar</code>.     * Mnemonics are case-insensitive, therefore a key event     * with the corresponding keycode would cause the button to be     * activated whether or not the Shift modifier was pressed.     * <p>     * If the character defined by the mnemonic is found within     * the button's label string, the first occurrence of it     * will be underlined to indicate the mnemonic to the user.     *     * @param mnemonic the key code which represents the mnemonic     * @see     java.awt.event.KeyEvent     * @see     #setDisplayedMnemonicIndex     *     * @beaninfo     *        bound: true     *    attribute: visualUpdate true     *  description: the keyboard character mnemonic     */    public void setMnemonic(int mnemonic) {        int oldValue = getMnemonic();        model.setMnemonic(mnemonic);        updateMnemonicProperties();    }     /**     * This method is now obsolete, please use <code>setMnemonic(int)</code>     * to set the mnemonic for a button.  This method is only designed     * to handle character values which fall between 'a' and 'z' or     * 'A' and 'Z'.     *     * @param mnemonic  a char specifying the mnemonic value     * @see #setMnemonic(int)     * @beaninfo     *        bound: true     *    attribute: visualUpdate true     *  description: the keyboard character mnemonic     */    public void setMnemonic(char mnemonic) {        int vk = (int) mnemonic;        if(vk >= 'a' && vk <='z')            vk -= ('a' - 'A');        setMnemonic(vk);    }     /**     * Provides a hint to the look and feel as to which character in the     * text should be decorated to represent the mnemonic. Not all look and     * feels may support this. A value of -1 indicates either there is no     * mnemonic, the mnemonic character is not contained in the string, or     * the developer does not wish the mnemonic to be displayed.     * <p>     * The value of this is updated as the properties relating to the     * mnemonic change (such as the mnemonic itself, the text...).     * You should only ever have to call this if     * you do not wish the default character to be underlined. For example, if     * the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A'     * to be decorated, as 'Save <u>A</u>s', you would have to invoke     * <code>setDisplayedMnemonicIndex(5)</code> after invoking     * <code>setMnemonic(KeyEvent.VK_A)</code>.     *     * @since 1.4     * @param index Index into the String to underline     * @exception IllegalArgumentException will be thrown if <code>index</code>     *            is &gt;= length of the text, or &lt; -1     * @see #getDisplayedMnemonicIndex     *     * @beaninfo     *        bound: true     *    attribute: visualUpdate true     *  description: the index into the String to draw the keyboard character     *               mnemonic at     */    public void setDisplayedMnemonicIndex(int index)                                          throws IllegalArgumentException {        int oldValue = mnemonicIndex;        if (index == -1) {            mnemonicIndex = -1;        } else {            String text = getText();            int textLength = (text == null) ? 0 : text.length();            if (index < -1 || index >= textLength) {  // index out of range                throw new IllegalArgumentException("index == " + index);            }        }        mnemonicIndex = index;        firePropertyChange("displayedMnemonicIndex", oldValue, index);        if (index != oldValue) {            revalidate();            repaint();        }    }     /**     * Returns the character, as an index, that the look and feel should     * provide decoration for as representing the mnemonic character.     *     * @since 1.4     * @return index representing mnemonic character     * @see #setDisplayedMnemonicIndex     */    public int getDisplayedMnemonicIndex() {        return mnemonicIndex;    }     /**     * Update the displayedMnemonicIndex property. This method     * is called when either text or mnemonic changes. The new     * value of the displayedMnemonicIndex property is the index     * of the first occurrence of mnemonic in text.     */    private void updateDisplayedMnemonicIndex(String text, int mnemonic) {        setDisplayedMnemonicIndex(            SwingUtilities.findDisplayedMnemonicIndex(text, mnemonic));    }     /**     * Brings the mnemonic property in accordance with model's mnemonic.     * This is called when model's mnemonic changes. Also updates the     * displayedMnemonicIndex property.     */    private void updateMnemonicProperties() {        int newMnemonic = model.getMnemonic();        if (mnemonic != newMnemonic) {            int oldValue = mnemonic;            mnemonic = newMnemonic;            firePropertyChange(MNEMONIC_CHANGED_PROPERTY,                               oldValue, mnemonic);            updateDisplayedMnemonicIndex(getText(), mnemonic);            revalidate();            repaint();        }    }     /**     * Sets the amount of time (in milliseconds) required between     * mouse press events for the button to generate the corresponding     * action events.  After the initial mouse press occurs (and action     * event generated) any subsequent mouse press events which occur     * on intervals less than the threshhold will be ignored and no     * corresponding action event generated.  By default the threshhold is 0,     * which means that for each mouse press, an action event will be     * fired, no matter how quickly the mouse clicks occur.  In buttons     * where this behavior is not desirable (for example, the "OK" button     * in a dialog), this threshhold should be set to an appropriate     * positive value.     *     * @see #getMultiClickThreshhold     * @param threshhold the amount of time required between mouse     *        press events to generate corresponding action events     * @exception   IllegalArgumentException if threshhold < 0     * @since 1.4     */    public void setMultiClickThreshhold(long threshhold) {        if (threshhold < 0) {            throw new IllegalArgumentException("threshhold must be >= 0");        }        this.multiClickThreshhold = threshhold;    }     /**     * Gets the amount of time (in milliseconds) required between     * mouse press events for the button to generate the corresponding     * action events.     *     * @see #setMultiClickThreshhold     * @return the amount of time required between mouse press events     *         to generate corresponding action events     * @since 1.4     */    public long getMultiClickThreshhold() {        return multiClickThreshhold;    }     /**     * Returns the model that this button represents.     * @return the <code>model</code> property     * @see #setModel     */    public ButtonModel getModel() {        return model;    }     /**     * Sets the model that this button represents.     * @param newModel the new <code>ButtonModel</code>     * @see #getModel     * @beaninfo     *        bound: true     *  description: Model that the Button uses.     */    public void setModel(ButtonModel newModel) {         ButtonModel oldModel = getModel();         if (oldModel != null) {            oldModel.removeChangeListener(changeListener);            oldModel.removeActionListener(actionListener);            oldModel.removeItemListener(itemListener);            changeListener = null;            actionListener = null;            itemListener = null;        }         model = newModel;         if (newModel != null) {            changeListener = createChangeListener();            actionListener = createActionListener();            itemListener = createItemListener();            newModel.addChangeListener(changeListener);            newModel.addActionListener(actionListener);            newModel.addItemListener(itemListener);             updateMnemonicProperties();            //We invoke setEnabled() from JComponent            //because setModel() can be called from a constructor            //when the button is not fully initialized            super.setEnabled(newModel.isEnabled());         } else {            mnemonic = '\0';        }         updateDisplayedMnemonicIndex(getText(), mnemonic);         firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, newModel);        if (newModel != oldModel) {            revalidate();            repaint();        }    }      /**     * Returns the L&F object that renders this component.     * @return the ButtonUI object     * @see #setUI     */    public ButtonUI getUI() {        return (ButtonUI) ui;    }      /**     * Sets the L&F object that renders this component.     * @param ui the <code>ButtonUI</code> L&F object     * @see #getUI     * @beaninfo     *        bound: true     *       hidden: true     *    attribute: visualUpdate true     *  description: The UI object that implements the LookAndFeel.     */    public void setUI(ButtonUI ui) {        super.setUI(ui);        // disabled icons are generated by the LF so they should be unset here        if (disabledIcon instanceof UIResource) {            setDisabledIcon(null);        }        if (disabledSelectedIcon instanceof UIResource) {            setDisabledSelectedIcon(null);        }    }      /**     * Resets the UI property to a value from the current look     * and feel.  Subtypes of <code>AbstractButton</code>     * should override this to update the UI. For     * example, <code>JButton</code> might do the following:     * <pre>     *      setUI((ButtonUI)UIManager.getUI(     *          "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));     * </pre>     */    public void updateUI() {    }     /**     * Adds the specified component to this container at the specified     * index, refer to     * {@link java.awt.Container#addImpl(Component, Object, int)}     * for a complete description of this method.     *     * @param     comp the component to be added     * @param     constraints an object expressing layout constraints     *                 for this component     * @param     index the position in the container's list at which to     *                 insert the component, where <code>-1</code>     *                 means append to the end     * @exception IllegalArgumentException if <code>index</code> is invalid     * @exception IllegalArgumentException if adding the container's parent     *                  to itself     * @exception IllegalArgumentException if adding a window to a container     * @since 1.5     */    protected void addImpl(Component comp, Object constraints, int index) {        if (!setLayout) {            setLayout(new OverlayLayout(this));        }        super.addImpl(comp, constraints, index);    }     /**     * Sets the layout manager for this container, refer to     * {@link java.awt.Container#setLayout(LayoutManager)}     * for a complete description of this method.     *     * @param mgr the specified layout manager     * @since 1.5     */    public void setLayout(LayoutManager mgr) {        setLayout = true;        super.setLayout(mgr);    }     /**     * Adds a <code>ChangeListener</code> to the button.     * @param l the listener to be added     */    public void addChangeListener(ChangeListener l) {        listenerList.add(ChangeListener.class, l);    }     /**     * Removes a ChangeListener from the button.     * @param l the listener to be removed     */    public void removeChangeListener(ChangeListener l) {        listenerList.remove(ChangeListener.class, l);    }     /**     * Returns an array of all the <code>ChangeListener</code>s added     * to this AbstractButton with addChangeListener().     *     * @return all of the <code>ChangeListener</code>s added or an empty     *         array if no listeners have been added     * @since 1.4     */    public ChangeListener[] getChangeListeners() {        return listenerList.getListeners(ChangeListener.class);    }     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created.     * @see EventListenerList     */    protected void fireStateChanged() {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==ChangeListener.class) {                // Lazily create the event:                if (changeEvent == null)                    changeEvent = new ChangeEvent(this);                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);            }        }    }     /**     * Adds an <code>ActionListener</code> to the button.     * @param l the <code>ActionListener</code> to be added     */    public void addActionListener(ActionListener l) {        listenerList.add(ActionListener.class, l);    }     /**     * Removes an <code>ActionListener</code> from the button.     * If the listener is the currently set <code>Action</code>     * for the button, then the <code>Action</code>     * is set to <code>null</code>.     *     * @param l the listener to be removed     */    public void removeActionListener(ActionListener l) {        if ((l != null) && (getAction() == l)) {            setAction(null);        } else {            listenerList.remove(ActionListener.class, l);        }    }     /**     * Returns an array of all the <code>ActionListener</code>s added     * to this AbstractButton with addActionListener().     *     * @return all of the <code>ActionListener</code>s added or an empty     *         array if no listeners have been added     * @since 1.4     */    public ActionListener[] getActionListeners() {        return listenerList.getListeners(ActionListener.class);    }     /**     * Subclasses that want to handle <code>ChangeEvents</code> differently     * can override this to return another <code>ChangeListener</code>     * implementation.     *     * @return the new <code>ChangeListener</code>     */    protected ChangeListener createChangeListener() {        return getHandler();    }     /**     * Extends <code>ChangeListener</code> to be serializable.     * <p>     * <strong>Warning:</strong>     * Serialized objects of this class will not be compatible with     * future Swing releases. The current serialization support is     * appropriate for short term storage or RMI between applications running     * the same version of Swing.  As of 1.4, support for long term storage     * of all JavaBeans<sup><font size="-2">TM</font></sup>     * has been added to the <code>java.beans</code> package.     * Please see {@link java.beans.XMLEncoder}.     */    protected class ButtonChangeListener implements ChangeListener, Serializable {        // NOTE: This class is NOT used, instead the functionality has        // been moved to Handler.        ButtonChangeListener() {        }         public void stateChanged(ChangeEvent e) {            getHandler().stateChanged(e);        }    }      /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the <code>event</code>     * parameter.     *     * @param event  the <code>ActionEvent</code> object     * @see EventListenerList     */    protected void fireActionPerformed(ActionEvent event) {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();

Lines 1501–2000 of 3101. Previous lines