⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
package com.sshtools.ui.awt;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Abstract implementation of an {@link Action}.
 */
public abstract class AbstractAction
    implements Action {
  
  //  Private instance variables
  private Hashtable attributes = new Hashtable();
  private boolean enabled;
  private Vector listeners;

  /**
   * Construct a new action with a name.
   *
   * @param name
   */
  public AbstractAction(String name) {
    super();
    listeners = new Vector();
    putValue(NAME, name);
    enabled = true;
  }

  /* (non-Javadoc)
   * @see com.sshtools.ui.awt.Action#isEnabled()
   */
  public boolean isEnabled() {
    return enabled;
  }
  /* (non-Javadoc)
   * @see com.sshtools.ui.awt.Action#setEnabled(boolean)
   */
  public void setEnabled(boolean enabled) {
    if(this.enabled != enabled) {
      boolean oldVal = this.enabled;
      this.enabled = enabled;
      firePropertyChanged(this, "enabled", oldVal ? Boolean.TRUE : Boolean.FALSE, enabled ? Boolean.TRUE : Boolean.FALSE);
    }
  }

  /* (non-Javadoc)
   * @see com.sshtools.ui.awt.Action#getName()
   */
  public String getName() {
    return (String) getValue(NAME);
  }

  /* (non-Javadoc)
       * @see com.sshtools.ui.awt.Action#putValue(java.lang.String, java.lang.Object)
   */
  public void putValue(String key, Object value) {
    Object oldVal = attributes.put(key, value);
    firePropertyChanged(this, key, oldVal, value);
  }


  /**
   * Get the value for an attribute. <code>null</code> will be returned
   * if no such attribute can be found.
   *
   * @param key attribute key
   * @return attribute value
   */
  public Object getValue(String key) {
    return attributes.get(key);
  }

  /* (non-Javadoc)
   * @see com.sshtools.ui.awt.Action#addPropertyChangeListener(java.beans.PropertyChangeListener)
   */
  public void addPropertyChangeListener(PropertyChangeListener l) {
    listeners.addElement(l);
  }
  
  /* (non-Javadoc)
   * @see com.sshtools.ui.awt.Action#removePropertyChangeListener(java.beans.PropertyChangeListener)
   */
  public void removePropertyChangeListener(PropertyChangeListener l) {
    listeners.removeElement(l);
  }
  
  /**
   * @param event
   */
  private void firePropertyChanged(Object source, String key, Object oldVal, Object newVal) {
    PropertyChangeEvent evt = null;
    synchronized(listeners) {
      for(int i = listeners.size() - 1; i >= 0 ; i-- ) {
        if(evt == null) {
          evt = new PropertyChangeEvent(source, key, oldVal, newVal);          
        }
        ((PropertyChangeListener)listeners.elementAt(i)).propertyChange(evt);
      }
    }    
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -