001 /*
002 * LAPIS lightweight structured text processing system
003 *
004 * Copyright (C) 1998-2002 Carnegie Mellon University,
005 * Copyright (C) 2003 Massachusetts Institute of Technology.
006 * All rights reserved.
007 *
008 * This library is free software; you can redistribute it
009 * and/or modify it under the terms of the GNU General
010 * Public License as published by the Free Software
011 * Foundation, version 2.
012 *
013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/
014 */
015
016 package lapisx.swing;
017
018 import java.awt.event.*;
019 import java.beans.*;
020 import javax.swing.*;
021
022 public class MaskedAction implements Action, PropertyChangeListener {
023 String masked;
024 Action action;
025 PropertyChangeSupport support = new PropertyChangeSupport (this);
026
027 public MaskedAction (String masked, Action action) {
028 this.masked = masked;
029 this.action = action;
030 action.addPropertyChangeListener (this);
031 }
032
033 public Object getValue (String name) {
034 if (name.equals (masked))
035 return null;
036 else
037 return action.getValue (name);
038 }
039
040 public void putValue (String name, Object obj) {
041 if (!name.equals (masked))
042 action.putValue (name, obj);
043 }
044
045 public void setEnabled (boolean f) {
046 action.setEnabled (f);
047 }
048
049 public boolean isEnabled () {
050 return action.isEnabled ();
051 }
052
053 public void propertyChange (PropertyChangeEvent event) {
054 String name = event.getPropertyName ();
055 if (!name.equals (masked))
056 support.firePropertyChange (name,
057 event.getOldValue (),
058 event.getNewValue ());
059 }
060
061 public void addPropertyChangeListener (PropertyChangeListener listener) {
062 support.addPropertyChangeListener (listener);
063 }
064
065 public void removePropertyChangeListener (PropertyChangeListener listener) {
066 support.removePropertyChangeListener (listener);
067 }
068
069 public void actionPerformed (ActionEvent event) {
070 action.actionPerformed (event);
071 }
072 }