1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import javax.help.*;
import javax.swing.*;
/** Creates a context sensitive action.
* <br>Such action may be re-used to create buttons and menuitems.
*/
public class ContextHelpAction
extends CSH.DisplayHelpAfterTracking implements Action {
/** Map of values.
*/
private java.util.Map<String, Object> propertyMap = new HashMap<String, Object>();
/** Fire events.
*/
private PropertyChangeSupport support = new PropertyChangeSupport(this);
/** Creates a new instance.
* @param broker The help broker.
*/
public ContextHelpAction(HelpBroker broker) {
super(broker);
putValue("enabled", true);
// We put an help topic onto this action as well.
// Be careful though, this property may not be properly caried over to children buttons by the default action=>button configuration method.
// We may need to do :
// JButton child1 = toolBar.add(contextHelpAction);
// child1.putClientProperty("HelpID", contextHelpAction.getValue("HelpID"));
// JMenuItem child2 = menu.add(contextHelpAction);
// child2.putClientProperty("HelpID", contextHelpAction.getValue("HelpID"));
putValue("HelpID", "HelpContextAction");
// Configure action eg: put label, icon, tooltip, mnemonic, keystroke.
}
/** {@inheritDoc}
*/
public void putValue(String key, Object value) {
Object old = propertyMap.put(key, value);
support.firePropertyChange(key, old, value);
}
/** {@inheritDoc}
*/
public Object getValue(String key) {
return propertyMap.get(key);
}
/** {@inheritDoc}
*/
public boolean isEnabled() {
return (Boolean) getValue("enabled");
}
/** {@inheritDoc}
*/
public void setEnabled(boolean enabled) {
putValue("enabled", enabled);
}
///////////////////////
// Event management. //
///////////////////////
/** {@inheritDoc}
*/
public void actionPerformed(ActionEvent event) {
try {
super.actionPerformed(event);
}
catch (Throwable t) {
// Handle JavaHelp error.
}
}
/** {@inheritDoc}
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
/** {@inheritDoc}
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}
} |
Partager