jdk/src/share/classes/sun/swing/UIAction.java
author alexp
Wed, 02 Sep 2009 17:47:19 +0400
changeset 3749 d0ecbd7075b1
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6797139: JButton title is truncating for some strings irrespective of preferred size. Reviewed-by: peterz
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 2003 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 sun.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * UIAction is the basis of all of basic's action classes that are used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * an ActionMap. Subclasses need to override <code>actionPerformed</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A typical subclass will look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *        Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *        public void actionPerformed(ActionEvent ae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *            if (getName() == "selectAll") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *                selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *            else if (getName() == "cancelEditing") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *                cancelEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Subclasses that wish to conditionalize the enabled state should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>isEnabled(Component)</code>, and be aware that the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>Component</code> may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see com.sun.java.swing.ExtendedAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see javax.swing.Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public abstract class UIAction implements Action {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public UIAction(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public Object getValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (key == NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // UIAction is not mutable, this does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void putValue(String key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // UIAction is not mutable, this does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Cover method for <code>isEnabled(null)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public final boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return isEnabled(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Subclasses that need to conditionalize the enabled state should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * override this. Be aware that <code>sender</code> may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param sender Widget enabled state is being asked for, may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public boolean isEnabled(Object sender) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // UIAction is not mutable, this does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // UIAction is not mutable, this does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}