List of usage examples for java.awt PopupMenu addActionListener
public synchronized void addActionListener(ActionListener l)
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java
private PopupMenu createPopupMenu(final ViewState state) { final String ACTIONS_POP_MENU_NAME = "Actions"; final String VIEW_CONDITION_MAP = "View..."; PopupMenu actionsMenu = new PopupMenu(ACTIONS_POP_MENU_NAME); actionsMenu.add(new MenuItem(VIEW_CONDITION_MAP)); actionsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(VIEW_CONDITION_MAP)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath() .getLastPathComponent(); ModelGraph graphToFocus = null; if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS)) || Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) { // if (node.getUserObject() instanceof String && // (node.getUserObject().equals("pre-conditions") || // node.getUserObject().equals("post-conditions"))) { ModelGraph graph = state.getSelected(); if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) { graphToFocus = graph.getPreConditions(); } else { graphToFocus = graph.getPostConditions(); }/*from w w w .ja va 2s . c o m*/ } else if (node.getUserObject() instanceof ModelGraph) { graphToFocus = (ModelGraph) node.getUserObject(); } DefaultTreeView.this .notifyListeners(new ViewChange.NEW_VIEW(graphToFocus, DefaultTreeView.this)); } } }); final String ORDER_SUB_POP_MENU_NAME = "Order"; final String TO_FRONT_ITEM_NAME = "Move To Front"; final String TO_BACK_ITEM_NAME = "Move To Back"; final String FORWARD_ITEM_NAME = "Move Forward"; final String BACKWARDS_ITEM_NAME = "Move Backwards"; actionsMenu.add(orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME)); orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME)); orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME)); orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME)); orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME)); orderSubMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ModelGraph graph = state.getSelected(); ModelGraph parent = graph.getParent(); if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) { if (parent.getChildren().remove(graph)) { parent.getChildren().add(0, graph); } } else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) { if (parent.getChildren().remove(graph)) { parent.getChildren().add(graph); } } else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) { int index = parent.getChildren().indexOf(graph); if (index != -1) { parent.getChildren().remove(index); parent.getChildren().add(Math.max(0, index + 1), graph); } } else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) { int index = parent.getChildren().indexOf(graph); if (index != -1) { parent.getChildren().remove(index); parent.getChildren().add(Math.max(0, index - 1), graph); } } DefaultTreeView.this.notifyListeners(); DefaultTreeView.this.refreshView(state); } }); return actionsMenu; }