UIAction.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: UIAction.java,v 1.2 2005/10/10 18:01:51 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. /*
  22.  * @(#)UIAction.java    1.2 03/04/24
  23.  *
  24.  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  25.  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  26.  */
  27. package org.jdesktop.swingx;
  28. import java.beans.PropertyChangeListener;
  29. import javax.swing.Action;
  30. /**
  31.  * UIAction is the basis of all of basic's action classes that are used in
  32.  * an ActionMap. Subclasses need to override <code>actionPerformed</code>.
  33.  * <p>
  34.  * A typical subclass will look like:
  35.  * <pre>
  36.  *    private static class Actions extends UIAction {
  37.  *        Actions(String name) {
  38.  *            super(name);
  39.  *        }
  40.  *
  41.  *        public void actionPerformed(ActionEvent ae) {
  42.  *            if (getName() == "selectAll") {
  43.  *                selectAll();
  44.  *            }
  45.  *            else if (getName() == "cancelEditing") {
  46.  *                cancelEditing();
  47.  *            }
  48.  *        }
  49.  *    }
  50.  * </pre>
  51.  * <p>
  52.  * Subclasses that wish to conditionalize the enabled state should override
  53.  * <code>isEnabled(Component)</code>, and be aware that the passed in
  54.  * <code>Component</code> may be null.
  55.  * <p>
  56.  * This is based on sun.swing.UIAction in J2SE 1.5
  57.  *
  58.  * @see javax.swing.Action
  59.  * @author Scott Violet
  60.  */
  61. public abstract class UIAction implements Action {
  62.     private String name;
  63.     public UIAction(String name) {
  64.         this.name = name;
  65.     }
  66.     public final String getName() {
  67.         return name;
  68.     }
  69.     public Object getValue(String key) {
  70.         if (key == NAME) {
  71.             return name;
  72.         }
  73.         return null;
  74.     }
  75.     // UIAction is not mutable, this does nothing.
  76.     public void putValue(String key, Object value) {
  77.     }
  78.     // UIAction is not mutable, this does nothing.
  79.     public void setEnabled(boolean b) {
  80.     }
  81.     /**
  82.      * Cover method for <code>isEnabled(null)</code>.
  83.      */
  84.     public final boolean isEnabled() {
  85.         return isEnabled(null);
  86.     }
  87.     /**
  88.      * Subclasses that need to conditionalize the enabled state should
  89.      * override this. Be aware that <code>sender</code> may be null.
  90.      *
  91.      * @param sender Widget enabled state is being asked for, may be null.
  92.      */
  93.     public boolean isEnabled(Object sender) {
  94.         return true;
  95.     }
  96.     // UIAction is not mutable, this does nothing.
  97.     public void addPropertyChangeListener(PropertyChangeListener listener) {
  98.     }
  99.     // UIAction is not mutable, this does nothing.
  100.     public void removePropertyChangeListener(PropertyChangeListener listener) {
  101.     }
  102. }