KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > graph > actions > NodePopupMenuProvider


1 /*
2  * NodePopupMenuProvider.java
3  *
4  * Created on February 2, 2007, 6:46 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.web.jsf.navigation.graph.actions;
11
12 import org.netbeans.modules.web.jsf.navigation.vwmodel.Page;
13 import org.netbeans.modules.web.jsf.navigation.graph.NavigationBridgeUtilities;
14 import java.awt.Point JavaDoc;
15 import java.awt.event.ActionEvent JavaDoc;
16 import java.awt.event.InputEvent JavaDoc;
17 import java.awt.event.KeyEvent JavaDoc;
18 import javax.swing.AbstractAction JavaDoc;
19 import javax.swing.Action JavaDoc;
20 import javax.swing.ActionMap JavaDoc;
21 import javax.swing.InputMap JavaDoc;
22 import javax.swing.JComponent JavaDoc;
23 import javax.swing.JMenuItem JavaDoc;
24 import javax.swing.JPopupMenu JavaDoc;
25 import javax.swing.JSeparator JavaDoc;
26 import javax.swing.KeyStroke JavaDoc;
27 import org.netbeans.api.visual.action.PopupMenuProvider;
28 import org.netbeans.api.visual.vmd.VMDNodeWidget;
29 import org.netbeans.api.visual.widget.Widget;
30 import org.netbeans.modules.web.jsf.navigation.graph.NavigationGraphScene;
31 import org.openide.util.NbBundle;
32
33 /**
34  *
35  * @author joelle
36  */

37 public class NodePopupMenuProvider implements PopupMenuProvider {
38     
39     NavigationGraphScene graphScene;
40     
41     private JMenuItem JavaDoc miDelete;
42     private JMenuItem JavaDoc miDelete1;
43     private JMenuItem JavaDoc miAddWebPage;
44     private JMenuItem JavaDoc miAddButton;
45     private JMenuItem JavaDoc miAddHyperlink;
46     private JMenuItem JavaDoc miAddImageHyperlink;
47     private JMenuItem JavaDoc miOpenPage;
48     
49     private static final String JavaDoc OPEN_PAGE = "openPage"; // NOI18N
50
// private static final String DELETE_ALL_CP_ACTION = "deleteAllCPAction"; // NOI18N
51
private static final String JavaDoc DELETE_TRANSITION = "deleteTransition"; // NOI18N
52

53     String JavaDoc openForm = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_OpenForm");
54     String JavaDoc delete = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_Delete");
55     String JavaDoc deletePage = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_DeletePage");
56     String JavaDoc addPage = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddPage");
57     String JavaDoc addButton = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddButton");
58     String JavaDoc addHyperlink = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddHyperlink");
59     String JavaDoc addImageHyperlink = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddImageHyperlink");
60     
61     private JPopupMenu JavaDoc menu;
62     private VMDNodeWidget node;
63 // private ConnectionWidget edge;
64
private Point JavaDoc point;
65     private ActionMap JavaDoc actionMap;
66     private InputMap JavaDoc inputMap;
67     
68     public NodePopupMenuProvider(NavigationGraphScene graphScene) {
69         
70         this.graphScene = graphScene;
71         JComponent JavaDoc view = graphScene.getView();
72         actionMap = view.getActionMap();
73         inputMap = view.getInputMap();
74         
75         initActionMap(actionMap);
76         initInputMap(inputMap);
77         initialize();
78     }
79     
80     private void initialize() {
81         
82         menu = new JPopupMenu JavaDoc("Transition Menu");
83         
84         miOpenPage = menu.add(handleOpenPage);
85 // miOpenPage = new JMenuItem(openForm);
86
miOpenPage.setActionCommand(OPEN_PAGE);
87         miOpenPage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0));
88 // miOpenPage.addActionListener(this);
89
ActionMap JavaDoc actionMap = miOpenPage.getActionMap();
90         menu.add(miOpenPage);
91         
92         menu.add(new JSeparator JavaDoc());
93         
94         miAddButton = menu.add(handleAddCommandButton);
95         miAddButton = new JMenuItem JavaDoc(addButton);
96         miAddButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,0));
97 // miAddButton.addActionListener(this);
98
menu.add(miAddButton);
99         
100         miAddHyperlink = menu.add(handleAddCommandLink);
101         miAddHyperlink = new JMenuItem JavaDoc(addHyperlink);
102         miAddHyperlink.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,0));
103 // miAddHyperlink.addActionListener(this);
104
menu.add(miAddHyperlink);
105         
106         miAddImageHyperlink = new JMenuItem JavaDoc(addImageHyperlink);
107         miAddImageHyperlink.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,0));
108 // miAddImageHyperlink.addActionListener(this);
109
menu.add(miAddImageHyperlink);
110         
111         menu.add(new JSeparator JavaDoc());
112         
113         miDelete = new JMenuItem JavaDoc(handleDeleteKey);
114         miDelete = new JMenuItem JavaDoc(delete);
115 // miDelete.addActionListener(this);
116
menu.add(miDelete);
117     }
118     
119     
120     
121     public JPopupMenu JavaDoc getPopupMenu(Widget widget, Point JavaDoc point){
122         if (widget instanceof VMDNodeWidget) {
123             this.node = (VMDNodeWidget) widget;
124             this.point=point;
125             page = (Page)graphScene.findObject(node);
126             return menu;
127         }
128         return null;
129     }
130     
131     Page page;
132     
133 // public void actionPerformed(ActionEvent e) {
134
//
135
// String message;
136
// String title;
137
// page = (Page)graphScene.findObject(node);
138
// if ((e.getSource() == miDelete) || (e.getSource() == miDelete1)) { // Delete menu item call back
139
// NavigationBridgeUtilities.getInstance().removeNode(page);
140
// }else if(e.getSource() == miOpenPage){
141
// NavigationBridgeUtilities.getInstance().openPage(page);
142
// }else if(e.getSource() == miAddButton){
143
// NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.BUTTON);
144
// }else if(e.getSource() == miAddHyperlink){
145
// NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.HYPERLINK);
146
// }else if(e.getSource() == miAddImageHyperlink){
147
// NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.IMAGE_HYPERLINK);
148
// } else {
149
// return;
150
// }
151
//
152
// }
153

154     public Action JavaDoc handleOpenPage = new AbstractAction JavaDoc() {
155         public void actionPerformed(ActionEvent JavaDoc e) {
156             NavigationBridgeUtilities.getInstance().openPage(page);
157         }
158     };
159     
160     public Action JavaDoc handleAddCommandButton = new AbstractAction JavaDoc() {
161         
162         public void actionPerformed(ActionEvent JavaDoc e) {
163             NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.BUTTON);
164             
165         }
166     };
167     
168     public Action JavaDoc handleAddCommandLink = new AbstractAction JavaDoc() {
169         public void actionPerformed(ActionEvent JavaDoc e) {
170             NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.HYPERLINK);
171             
172         }
173     };
174     
175     public Action JavaDoc handleAddImageHyperLink = new AbstractAction JavaDoc() {
176         public void actionPerformed(ActionEvent JavaDoc e) {
177             NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.IMAGE_HYPERLINK);
178         }
179     };
180     
181     public Action JavaDoc handleDeleteKey = new AbstractAction JavaDoc() {
182         public void actionPerformed(ActionEvent JavaDoc e) {
183
184                 NavigationBridgeUtilities.getInstance().removeNode(page);
185
186         }
187     };
188     
189     
190     private void initActionMap(ActionMap JavaDoc actionMap) {
191 // // Install the actions
192
// actionMap.put("handleTab", handleTab);
193
// actionMap.put("handleEscape", handleEscape);
194
//
195
// actionMap.put("handleLinkStart", handleLinkStart);
196
// actionMap.put("handleLinkEnd", handleLinkEnd);
197
//
198
// actionMap.put("handleZoomPage", handleZoomPage);
199
// actionMap.put("handleUnZoomPage", handleUnZoomPage);
200
actionMap.put("handleOpenPage", handleOpenPage);
201 // actionMap.put("handleNewWebForm", handleNewWebForm);
202
//
203
// actionMap.put("handleLeftArrowKey", handleLeftArrowKey);
204
// actionMap.put("handleRightArrowKey", handleRightArrowKey);
205
// actionMap.put("handleUpArrowKey", handleUpArrowKey);
206
// actionMap.put("handleDownArrowKey", handleDownArrowKey);
207
//
208
actionMap.put("handleAddCommandButton", handleAddCommandButton);
209         actionMap.put("handleAddCommandLink", handleAddCommandLink);
210         actionMap.put("handleAddImageHyperLink", handleAddImageHyperLink);
211 // actionMap.put("handlePopupMenu", handlePopupMenu);
212
actionMap.put("handleDeleteKey", handleDeleteKey);
213     }
214     
215     private void initInputMap(InputMap JavaDoc inputMap) {
216 // // Tab Key
217
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0), "handleTab");
218
// // Esc Key
219
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), "handleEscape");
220
//
221
// //Lower Case a
222
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK), "handleNewWebForm");
223
//
224
// //Lower Case s,e,z,u
225
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S,0), "handleLinkStart");
226
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_E,0), "handleLinkEnd");
227
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z,0), "handleZoomPage");
228
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_U,0), "handleUnZoomPage");
229
//
230
// Keys enter, b,l,i
231
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "handleOpenPage");
232         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B,0), "handleAddCommandButton");
233         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L,0), "handleAddCommandLink");
234         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_I,0), "handleAddImageHyperLink");
235 //
236
// // Upper Case S,E,Z,U
237
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.SHIFT_MASK), "handleLinkStart");
238
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.SHIFT_MASK), "handleLinkEnd");
239
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.SHIFT_MASK), "handleZoomPage");
240
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_U,InputEvent.SHIFT_MASK), "handleUnZoomPage");
241
//
242
// Keys B,L, I
243
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B,InputEvent.SHIFT_MASK), "handleAddCommandButton");
244         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L,InputEvent.SHIFT_MASK), "handleAddCommandLink");
245         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_I,InputEvent.SHIFT_MASK), "handleAddImageHyperLink");
246 //
247
// // Non Numeric Key Pad arrow keys
248
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0), "handleLeftArrowKey");
249
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0), "handleRightArrowKey");
250
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0), "handleUpArrowKey");
251
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0), "handleDownArrowKey");
252
//
253
// // Numeric Key Pad arrow keys
254
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT,0), "handleLeftArrowKey");
255
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT,0), "handleRightArrowKey");
256
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP,0), "handleUpArrowKey");
257
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN,0), "handleDownArrowKey");
258
//
259
// // SHIFT + F10
260
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10,InputEvent.SHIFT_MASK), "handlePopupMenu");
261
//
262
// DELETE
263
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "handleDeleteKey");
264     }
265     
266     
267     
268 }
269
Popular Tags