/plugins/CommonControls/tags/cc_0_9_0/common/gui/actions/CustomAction.java

# · Java · 79 lines · 49 code · 16 blank · 14 comment · 0 complexity · 894f9068edb4520dd890945790acacaa MD5 · raw file

  1. package common.gui.actions;
  2. import java.awt.event.*;
  3. import java.net.*;
  4. import javax.swing.*;
  5. /**
  6. * Description of the Class
  7. *
  8. * @author mace
  9. * @created October 24, 2002
  10. * @modified $Date: 2004-02-09 03:49:01 +0100 (Mon, 09 Feb 2004) $ by $Author: bemace $
  11. * @version $Revision: 1347 $
  12. */
  13. public abstract class CustomAction extends AbstractAction {
  14. public final static int CTRL = KeyEvent.CTRL_MASK;
  15. public final static int ALT = KeyEvent.ALT_MASK;
  16. public final static int SHIFT = KeyEvent.SHIFT_MASK;
  17. public final static int META = KeyEvent.META_MASK;
  18. /**
  19. * The Action's tool tip text is set to it's name by default.
  20. *
  21. * @param name Description of the Parameter
  22. */
  23. public CustomAction(String name) {
  24. super(name);
  25. setActionCommand(name);
  26. setToolTipText(name);
  27. }
  28. public CustomAction(String name, Icon icon) {
  29. super(name, icon);
  30. setActionCommand(name);
  31. setToolTipText(name);
  32. }
  33. public void setToolTipText(String text) {
  34. putValue(SHORT_DESCRIPTION, text);
  35. }
  36. public void setContextualHelp(String text) {
  37. putValue(LONG_DESCRIPTION, text);
  38. }
  39. public void setAccelerator(KeyStroke ks) {
  40. putValue(ACCELERATOR_KEY, ks);
  41. }
  42. public void setAccelerator(int key, int modifiers) {
  43. KeyStroke ks = KeyStroke.getKeyStroke(key, modifiers);
  44. setAccelerator(ks);
  45. }
  46. public void setMnemonic(int key) {
  47. putValue(MNEMONIC_KEY, new Integer(key));
  48. }
  49. public void setName(String name) {
  50. putValue(NAME, name);
  51. }
  52. public void setIcon(String file) {
  53. //URL iconURL = ClassLoader.getSystemResource(file);
  54. ImageIcon icon = new ImageIcon(file);
  55. setIcon(icon);
  56. }
  57. public void setIcon(Icon i) {
  58. putValue(SMALL_ICON, i);
  59. }
  60. public void setActionCommand(String command) {
  61. putValue(ACTION_COMMAND_KEY, command);
  62. }
  63. }