01: /*
02: * SimpleActionProvider.java
03: *
04: * Created on January 25, 2004, 3:06 PM
05: */
06:
07: package org.netbeans.actions.simple;
08:
09: import java.util.MissingResourceException;
10: import java.util.ResourceBundle;
11: import javax.swing.Icon;
12: import org.netbeans.actions.spi.ActionProvider;
13:
14: /**
15: *
16: * @author tim
17: */
18: public class SimpleActionProvider extends ActionProvider {
19: private Interpreter interp;
20: private ResourceBundle bundle;
21:
22: /** Creates a new instance of SimpleActionProvider */
23: public SimpleActionProvider(Interpreter interp,
24: ResourceBundle bundle) {
25: this .interp = interp;
26: this .bundle = bundle;
27: }
28:
29: public String[] getActionNames(String containerCtx) {
30: return interp.getActionNames(containerCtx);
31: }
32:
33: public int getActionType(String actionName, String containerCtx) {
34: return ACTION_TYPE_ITEM; //XXX
35: }
36:
37: public String getDescription(String actionName, String containerCtx) {
38: return actionName + "description"; //XXX
39: }
40:
41: public String getDisplayName(String actionName, String containerCtx) {
42: try {
43: return bundle.getString(actionName);
44: } catch (MissingResourceException mre) {
45: mre.printStackTrace();
46: return actionName;
47: }
48: }
49:
50: public Icon getIcon(String actionName, String containerCtx, int type) {
51: Icon result = interp.getIconForAction(actionName);
52: if (result == null) {
53: result = dummyIcon;
54: }
55: return result;
56: }
57:
58: public int getMnemonic(String actionName, String containerCtx) {
59: return 0;
60: }
61:
62: public int getMnemonicIndex(String actionName, String containerCtx) {
63: return 0;
64: }
65:
66: public int getState(String actionName, String containerCtx,
67: java.util.Map context) {
68: if (interp.contextContainsAction(containerCtx, actionName)) {
69: return interp.getState(actionName, context);
70: } else {
71: throw new IllegalStateException("Container " + containerCtx
72: + " does not contain an action " + actionName);
73: }
74: }
75:
76: private Icon dummyIcon = new DummyIcon();
77:
78: private class DummyIcon implements Icon {
79:
80: public int getIconHeight() {
81: return 16;
82: }
83:
84: public int getIconWidth() {
85: return 16;
86: }
87:
88: public void paintIcon(java.awt.Component c,
89: java.awt.Graphics g, int x, int y) {
90: g.setColor(java.awt.Color.BLUE);
91: g.drawRect(x + 4, y + 4, 6, 6);
92: }
93:
94: }
95:
96: }
|