📄 command.java
字号:
/*====================================================================*\Command.javaCommand class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage util;//----------------------------------------------------------------------// IMPORTSimport java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeListener;import java.util.Hashtable;import javax.swing.Action;import javax.swing.event.SwingPropertyChangeSupport;//----------------------------------------------------------------------// COMMAND CLASSpublic class Command implements Action{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// public static final String COMMAND_METHOD_PREFIX = "do"; public static final String ENABLED_KEY = "enabled"; private static final int PROPERTIES_INITIAL_CAPACITY = 8;////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// public Command( ActionListener listener ) { this.listener = listener; enabled = true; properties = new Hashtable<String,Object>( PROPERTIES_INITIAL_CAPACITY ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : Action interface//////////////////////////////////////////////////////////////////////// public void addPropertyChangeListener( PropertyChangeListener listener ) { if ( changeSupport == null ) changeSupport = new SwingPropertyChangeSupport( this ); changeSupport.addPropertyChangeListener( listener ); } //------------------------------------------------------------------ public Object getValue( String key ) { return ( key.equals( ENABLED_KEY ) ? new Boolean( enabled ) : properties.get( key ) ); } //------------------------------------------------------------------ public boolean isEnabled( ) { return enabled; } //------------------------------------------------------------------ public void putValue( String key, Object value ) { Object oldValue = getValue( key ); if ( key.equals( ENABLED_KEY ) ) { if ( !(value instanceof Boolean) ) value = Boolean.FALSE; enabled = ((Boolean)value).booleanValue( ); } else { if ( value == null ) properties.remove( key ); else properties.put( key, value ); } if ( (changeSupport != null) && (((oldValue == null) && (value != null)) || ((oldValue != null) && !oldValue.equals( value ))) ) changeSupport.firePropertyChange( key, oldValue, value ); } //------------------------------------------------------------------ public void removePropertyChangeListener( PropertyChangeListener listener ) { if ( changeSupport != null ) changeSupport.removePropertyChangeListener( listener ); } //------------------------------------------------------------------ public void setEnabled( boolean enabled ) { boolean oldValue = this.enabled; if ( this.enabled != enabled ) { this.enabled = enabled; if ( changeSupport != null ) changeSupport.firePropertyChange( ENABLED_KEY, new Boolean( oldValue ), new Boolean( enabled ) ); } } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : ActionListener interface//////////////////////////////////////////////////////////////////////// public void actionPerformed( ActionEvent event ) { listener.actionPerformed( event ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods//////////////////////////////////////////////////////////////////////// public String getMethodName( ) { String key = (String)getValue( Action.ACTION_COMMAND_KEY ); return ( COMMAND_METHOD_PREFIX + key.substring( 0, 1 ).toUpperCase( ) + key.substring( 1 ) ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance variables//////////////////////////////////////////////////////////////////////// private ActionListener listener; private boolean enabled; private Hashtable<String,Object> properties; private SwingPropertyChangeSupport changeSupport;}//----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -