1 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 ; 15 import java.awt.event.ActionEvent ; 16 import java.awt.event.InputEvent ; 17 import java.awt.event.KeyEvent ; 18 import javax.swing.AbstractAction ; 19 import javax.swing.Action ; 20 import javax.swing.ActionMap ; 21 import javax.swing.InputMap ; 22 import javax.swing.JComponent ; 23 import javax.swing.JMenuItem ; 24 import javax.swing.JPopupMenu ; 25 import javax.swing.JSeparator ; 26 import javax.swing.KeyStroke ; 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 37 public class NodePopupMenuProvider implements PopupMenuProvider { 38 39 NavigationGraphScene graphScene; 40 41 private JMenuItem miDelete; 42 private JMenuItem miDelete1; 43 private JMenuItem miAddWebPage; 44 private JMenuItem miAddButton; 45 private JMenuItem miAddHyperlink; 46 private JMenuItem miAddImageHyperlink; 47 private JMenuItem miOpenPage; 48 49 private static final String OPEN_PAGE = "openPage"; private static final String DELETE_TRANSITION = "deleteTransition"; 53 String openForm = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_OpenForm"); 54 String delete = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_Delete"); 55 String deletePage = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_DeletePage"); 56 String addPage = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddPage"); 57 String addButton = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddButton"); 58 String addHyperlink = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddHyperlink"); 59 String addImageHyperlink = NbBundle.getMessage(NodePopupMenuProvider.class, "MSG_AddImageHyperlink"); 60 61 private JPopupMenu menu; 62 private VMDNodeWidget node; 63 private Point point; 65 private ActionMap actionMap; 66 private InputMap inputMap; 67 68 public NodePopupMenuProvider(NavigationGraphScene graphScene) { 69 70 this.graphScene = graphScene; 71 JComponent 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 ("Transition Menu"); 83 84 miOpenPage = menu.add(handleOpenPage); 85 miOpenPage.setActionCommand(OPEN_PAGE); 87 miOpenPage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0)); 88 ActionMap actionMap = miOpenPage.getActionMap(); 90 menu.add(miOpenPage); 91 92 menu.add(new JSeparator ()); 93 94 miAddButton = menu.add(handleAddCommandButton); 95 miAddButton = new JMenuItem (addButton); 96 miAddButton.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,0)); 97 menu.add(miAddButton); 99 100 miAddHyperlink = menu.add(handleAddCommandLink); 101 miAddHyperlink = new JMenuItem (addHyperlink); 102 miAddHyperlink.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,0)); 103 menu.add(miAddHyperlink); 105 106 miAddImageHyperlink = new JMenuItem (addImageHyperlink); 107 miAddImageHyperlink.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,0)); 108 menu.add(miAddImageHyperlink); 110 111 menu.add(new JSeparator ()); 112 113 miDelete = new JMenuItem (handleDeleteKey); 114 miDelete = new JMenuItem (delete); 115 menu.add(miDelete); 117 } 118 119 120 121 public JPopupMenu getPopupMenu(Widget widget, Point 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 154 public Action handleOpenPage = new AbstractAction () { 155 public void actionPerformed(ActionEvent e) { 156 NavigationBridgeUtilities.getInstance().openPage(page); 157 } 158 }; 159 160 public Action handleAddCommandButton = new AbstractAction () { 161 162 public void actionPerformed(ActionEvent e) { 163 NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.BUTTON); 164 165 } 166 }; 167 168 public Action handleAddCommandLink = new AbstractAction () { 169 public void actionPerformed(ActionEvent e) { 170 NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.HYPERLINK); 171 172 } 173 }; 174 175 public Action handleAddImageHyperLink = new AbstractAction () { 176 public void actionPerformed(ActionEvent e) { 177 NavigationBridgeUtilities.getInstance().addPageBean(page, NavigationBridgeUtilities.IMAGE_HYPERLINK); 178 } 179 }; 180 181 public Action handleDeleteKey = new AbstractAction () { 182 public void actionPerformed(ActionEvent e) { 183 184 NavigationBridgeUtilities.getInstance().removeNode(page); 185 186 } 187 }; 188 189 190 private void initActionMap(ActionMap actionMap) { 191 actionMap.put("handleOpenPage", handleOpenPage); 201 actionMap.put("handleAddCommandButton", handleAddCommandButton); 209 actionMap.put("handleAddCommandLink", handleAddCommandLink); 210 actionMap.put("handleAddImageHyperLink", handleAddImageHyperLink); 211 actionMap.put("handleDeleteKey", handleDeleteKey); 213 } 214 215 private void initInputMap(InputMap inputMap) { 216 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 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 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "handleDeleteKey"); 264 } 265 266 267 268 } 269 | Popular Tags |