Java Code Examples for javax.swing.JPopupMenu#addSeparator()

The following examples show how to use javax.swing.JPopupMenu#addSeparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RightClickMouseAdapter.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JPopupMenu generatePopupMenu(RobotComponent component) {
    JPopupMenu menu = new JPopupMenu();

    List<JMenu> submenus = new LinkedList<>();
    TreeModel model = Palette.getInstance().getPaletteModel();
    Enumeration children = ((DefaultMutableTreeNode) model.getRoot()).children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        JMenu submenu = generateMenu(new JMenu("Add " + child.getUserObject()), child, component);
        if (submenu.getSubElements().length > 0) {
            submenus.add(submenu);
        }
    }

    if (submenus.size() > 1) {
        submenus.forEach(menu::add);
    } else if (submenus.size() == 1) {
        for (Component element : submenus.get(0).getMenuComponents()) {
            menu.add(element);
        }
    }

    if (isDeletable(component)) {
        if (menu.getSubElements().length > 0) {
            menu.addSeparator();
        }
        menu.add(new DeleteItemAction("Delete", component));
    }

    return menu;
}
 
Example 2
Source File: LayerTree.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Get a custom, context-sensitive popup menu for the selected node. */
private JPopupMenu getPopupMenu(DefaultMutableTreeNode node) {
	Object ob = node.getUserObject();
	LayerThing thing = null;
	if (ob instanceof LayerThing) {
		thing = (LayerThing)ob;
	} else {
		return null;
	}
	// context-sensitive popup
	JMenuItem[] item = thing.getPopupItems(this);
	if (0 == item.length) return null;
	JPopupMenu popup = new JPopupMenu();
	for (int i=0; i<item.length; i++) {
		if (null == item[i] || "" == item[i].getText()) popup.addSeparator();
		else popup.add(item[i]);
	}
	return popup;
}
 
Example 3
Source File: ExtendedJTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
public void populatePopupMenu(final JPopupMenu menu) {
	menu.add(ROW_ACTION);
	menu.add(COLUMN_ACTION);

	if (getTableHeader() != null) {
		menu.addSeparator();
		menu.add(FIT_COLUMN_ACTION);
		menu.add(FIT_ALL_COLUMNS_ACTION);
		menu.add(EQUAL_WIDTHS_ACTION);
	}

	if (isSortable()) {
		menu.addSeparator();
		menu.add(SORTING_ASCENDING_ACTION);
		menu.add(SORTING_DESCENDING_ACTION);
	}

	if (getTableHeader() != null) {
		if (getTableHeader().getReorderingAllowed()) {
			menu.addSeparator();
			menu.add(SORT_COLUMNS_BY_NAME_ACTION);
			menu.add(RESTORE_COLUMN_ORDER_ACTION);
		}
	}
}
 
Example 4
Source File: HistFrame.java    From rest-client with Apache License 2.0 6 votes vote down vote up
/**
* 
* @Title      : initPopupMenu 
* @Description: PopupMenu Initialization 
* @Param      :  
* @Return     : void
* @Throws     :
 */
public void initPopupMenu()
{
    pm = new JPopupMenu();

    miRmSelHdr = new JMenuItem(RESTConst.RM_SEL);
    miRmSelHdr.setName(RESTConst.RM_SEL);
    miRmSelHdr.addActionListener(this);

    miNewHdr = new JMenuItem(RESTConst.NEW_HDR);
    miNewHdr.setName(RESTConst.NEW_HDR);
    miNewHdr.addActionListener(this);

    pm.add(miNewHdr);
    pm.addSeparator();
    pm.add(miRmSelHdr);
}
 
Example 5
Source File: ProfilerToolbarDropdownAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getToolbarPresenter() {
    if (toolbarPresenter == null) {
        // gets the real action registered in the menu from layer
        Action a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachMainProject"); // NOI18N
        final Action attachProjectAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
        
        // gets the real action registered in the menu from layer
        a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachAction"); // NOI18N
        final Action attachProcessAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();

        JPopupMenu dropdownPopup = new JPopupMenu();
        dropdownPopup.add(createDropdownItem(defaultAction));
        dropdownPopup.add(createDropdownItem(attachProjectAction));
        dropdownPopup.addSeparator();
        dropdownPopup.add(createDropdownItem(attachProcessAction));

        JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(
                new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
        Actions.connect(button, defaultAction);

        toolbarPresenter = button;
    }

    return toolbarPresenter;
}
 
Example 6
Source File: OutputTab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addFoldingActionsToPopUpMenu(JPopupMenu menu,
        List<TabAction> activeActions) {
    JMenu submenu = new JMenu(NbBundle.getMessage(
            OutputTab.class, "LBL_OutputFolds"));                   //NOI18N
    for (ACTION a : popUpFoldItems) {
        if (a == null) {
            submenu.addSeparator();
        } else {
            TabAction ta = action(a);
            activeActions.add(ta);
            submenu.add(new JMenuItem(ta));
        }
    }
    menu.addSeparator();
    menu.add(submenu);
}
 
Example 7
Source File: PopupMenuHandler.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private void rearrangeMenuItems(JPopupMenu popupMenu) {
    Component[] components = popupMenu.getComponents();
    Arrays.sort(components, (o1, o2) -> getGroupName(o1).compareToIgnoreCase(getGroupName(o2)));
    popupMenu.removeAll();
    Component lastComponent = null;
    String lastGroupName = null;
    for (Component component : components) {
        String groupName = getGroupName(component);
        if (lastGroupName != null
                && !lastGroupName.equals(groupName)
                && !(lastComponent instanceof JSeparator)) {
            popupMenu.addSeparator();
        }
        lastGroupName = groupName;
        lastComponent = component;
        if (component instanceof JMenuItem) {
            popupMenu.add((JMenuItem) component);
        } else if (component instanceof Action) {
            popupMenu.add((Action) component);
        } else {
            popupMenu.add(component);
        }
    }
}
 
Example 8
Source File: MainPanel.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
private JPopupMenu createContainerPopupMenu() {
    JPopupMenu pop = new JPopupMenu("Container");
    pop.add(setAccessibleContext(new JMenuItem(containerRefreshAction)));
    pop.add(setAccessibleContext(new JMenuItem(containerViewMetaData)));
    pop.addSeparator();
    pop.add(setAccessibleContext(new JMenuItem(containerCreateAction)));
    pop.add(setAccessibleContext(new JMenuItem(containerDeleteAction)));
    pop.addSeparator();
    pop.add(setAccessibleContext(new JMenuItem(containerEmptyAction)));
    pop.addSeparator();
    pop.add(setAccessibleContext(new JMenuItem(containerPurgeAction)));
    return pop;
}
 
Example 9
Source File: JPQLEditorPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public JPQLEditorPopupMouseAdapter() {
    super();
    popupMenu = new JPopupMenu();
    ActionListener actionListener = new PopupActionListener();
    runJPQLMenuItem = popupMenu.add(RUN_JPQL_COMMAND);
    runJPQLMenuItem.setMnemonic('Q');
    runJPQLMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, false));
    runJPQLMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    cutMenuItem = popupMenu.add(CUT_COMMAND);
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, true));
    cutMenuItem.setMnemonic('t');
    cutMenuItem.addActionListener(actionListener);

    copyMenuItem = popupMenu.add(COPY_COMMAND);
    copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK, true));
    copyMenuItem.setMnemonic('y');
    copyMenuItem.addActionListener(actionListener);

    pasteMenuItem = popupMenu.add(PASTE_COMMAND);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, true));
    pasteMenuItem.setMnemonic('P');
    pasteMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    selectAllMenuItem = popupMenu.add(SELECT_ALL_COMMAND);
    selectAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK, true));
    selectAllMenuItem.setMnemonic('A');
    selectAllMenuItem.addActionListener(actionListener);
}
 
Example 10
Source File: JPQLEditorTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JPQLEditorPopupMouseAdapter() {
    super();
    popupMenu = new JPopupMenu();
    ActionListener actionListener = new PopupActionListener();
    runJPQLMenuItem = popupMenu.add(RUN_JPQL_COMMAND);
    runJPQLMenuItem.setMnemonic('Q');
    runJPQLMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, false));
    runJPQLMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    cutMenuItem = popupMenu.add(CUT_COMMAND);
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, true));
    cutMenuItem.setMnemonic('t');
    cutMenuItem.addActionListener(actionListener);

    copyMenuItem = popupMenu.add(COPY_COMMAND);
    copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK, true));
    copyMenuItem.setMnemonic('y');
    copyMenuItem.addActionListener(actionListener);

    pasteMenuItem = popupMenu.add(PASTE_COMMAND);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, true));
    pasteMenuItem.setMnemonic('P');
    pasteMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    selectAllMenuItem = popupMenu.add(SELECT_ALL_COMMAND);
    selectAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK, true));
    selectAllMenuItem.setMnemonic('A');
    selectAllMenuItem.addActionListener(actionListener);
}
 
Example 11
Source File: CBreakpointTable.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Displays the popup menu at the location specified by the click event.
 * 
 * @param event The click event.
 */
private void showPopupMenu(final MouseEvent event) {
  final int row = rowAtPoint(event.getPoint());
  final int column = columnAtPoint(event.getPoint());

  int[] rows = getSelectedRows();

  if ((rows.length == 0) || (rows.length == 1)) {
    changeSelection(row, column, false, false);
    rows = getSelectedRows();
  }

  final JPopupMenu menu = new JPopupMenu();

  menu.add(new JMenuItem(CActionProxy.proxy(new CDeleteAction(m_debuggerProvider, rows))));

  if (CBreakpointFunctions.allDisabled(m_debuggerProvider, rows)) {
    menu.add(new JMenuItem(CActionProxy.proxy(new CEnableAction(m_debuggerProvider, rows))));
  } else if (CBreakpointFunctions.allNotDisabled(m_debuggerProvider, rows)) {
    menu.add(new JMenuItem(CActionProxy.proxy(new CDisableAction(m_debuggerProvider, rows))));
  }

  if (rows.length == 1) {
    menu.addSeparator();

    final Pair<IDebugger, Integer> breakpoint =
        CBreakpointTableHelpers.findBreakpoint(m_debuggerProvider, rows[0]);

    final BreakpointManager manager = breakpoint.first().getBreakpointManager();
    final int breakpointIndex = breakpoint.second();

    final BreakpointAddress address =
        manager.getBreakpoint(BreakpointType.REGULAR, breakpointIndex).getAddress();

    menu.add(new JMenuItem(CActionProxy.proxy(new CZoomBreakpointAction(SwingUtilities
        .windowForComponent(this), m_graph, m_viewContainer, address))));
  }

  menu.show(event.getComponent(), event.getX(), event.getY());
}
 
Example 12
Source File: ExplorerContextMenuFactory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
JPopupMenu createPopupMenu() {
    // Get actions for the node
    List<Action>[] actionsArray = getActions();
    List<Action> defaultActions = actionsArray[0];
    List<Action> actions = actionsArray[1];

    // Return if there are no actions to display
    if (defaultActions.size() == 0 && actions.size() == 0) return null;

    // Create a popup menu
    JPopupMenu popupMenu = new JPopupMenu();

    // Insert default actions
    boolean realDefaultAction = true;
    if (!defaultActions.isEmpty()) {
        for (Action defaultAction : defaultActions) {
            JMenuItem defaultItem = new DataSourceItem(defaultAction);
            if (realDefaultAction) {
                defaultItem.setFont(defaultItem.getFont().deriveFont(Font.BOLD));
                realDefaultAction = false;
            }
            popupMenu.add(defaultItem);
        }
    }

    // Insert separator between default action and other actions
    if (!defaultActions.isEmpty() && !actions.isEmpty()) popupMenu.addSeparator();

    // Insert other actions
    if (!actions.isEmpty()) {
        for (Action action : actions) {
            if (action == null) popupMenu.addSeparator();
            else popupMenu.add(createItem(action));
        }
    }
    
    return popupMenu;
}
 
Example 13
Source File: NodeTreeTableMouseListener.java    From JPPF with Apache License 2.0 5 votes vote down vote up
@Override
protected JPopupMenu createPopupMenu(final MouseEvent event) {
  final Component comp = event.getComponent();
  final Point p = comp.getLocationOnScreen();
  final JPopupMenu menu = new JPopupMenu();
  addItem(menu, "show.information", p);
  menu.addSeparator();
  addItem(menu, "shutdown.restart.driver", p);
  addItem(menu, "load.balancing.settings", p);
  addItem(menu, "driver.reset.statistics", p);
  menu.addSeparator();
  addItem(menu, "update.configuration", p);
  addItem(menu, "update.threads", p);
  addItem(menu, "reset.counter", p);
  menu.addSeparator();
  addItem(menu, "restart.node", p);
  addItem(menu, "restart.node.deferred", p);
  addItem(menu, "shutdown.node", p);
  addItem(menu, "shutdown.node.deferred", p);
  addItem(menu, "reconnect.node", p);
  addItem(menu, "reconnect.node.deferred", p);
  addItem(menu, "cancel.deferred.action", p);
  menu.addSeparator();
  addItem(menu, "toggle.active", p);
  addItem(menu, "node.provisioning", p);
  return menu;
}
 
Example 14
Source File: OperatorTree.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Creates a new popup menu for the selected operator. */
private JPopupMenu createOperatorPopupMenu() {
	JPopupMenu menu = new JPopupMenu();
	menu.add(EXPAND_ALL_ACTION);
	menu.add(COLLAPSE_ALL_ACTION);
	menu.addSeparator();
	String name = "Tree";
	if (mainFrame.getProcess().getProcessLocation() != null) {
		name = mainFrame.getProcess().getProcessLocation().getShortName();
	}
	menu.add(PrintingTools.makeExportPrintMenu(this, name));

	return menu;
}
 
Example 15
Source File: MergeDialogComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static JPopupMenu createPopupMenu(MergePanel panel) {
    JPopupMenu popup = new JPopupMenuPlus();
    SystemAction[] actions = panel.getSystemActions();
    for (int i = 0; i < actions.length; i++) {
        if (actions[i] == null) {
            popup.addSeparator();
        } else if (actions[i] instanceof CallableSystemAction) {
            popup.add(((CallableSystemAction)actions[i]).getPopupPresenter());
            //add FileSystemAction to pop-up menu
        } else if (actions[i] instanceof FileSystemAction) {
            popup.add(((FileSystemAction)actions[i]).getPopupPresenter());
        }
    }
    return popup;
}
 
Example 16
Source File: CMenuBuilder.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Adds menus related to node selection to a given node context menu.
 *
 * @param menu The node context menu to extend.
 * @param graph The graph the clicked node belongs to.
 * @param node The clicked node.
 */
public static void addSelectionMenus(
    final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
  Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
  Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
  Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");

  final JMenu selectionMenu = new JMenu("Selection");

  selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
  selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));

  if (graph.getSelectedNodes().size() > 0) {
    selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
  }

  if (node.getRawNode() instanceof INaviCodeNode) {
    try {
      final INaviFunction parentFunction =
          ((INaviCodeNode) node.getRawNode()).getParentFunction();

      selectionMenu.add(CActionProxy.proxy(
          new CActionSelectSameParentFunction(graph, parentFunction)));
    } catch (final MaybeNullException exception) {
      // Obviously we can not select nodes of the same parent function if there
      // is no parent function.
    }
  } else if (node.getRawNode() instanceof INaviFunctionNode) {
    final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();

    selectionMenu.add(CActionProxy.proxy(
        new CActionSelectSameFunctionType(graph, function.getType())));
  }

  menu.add(selectionMenu);

  menu.addSeparator();
}
 
Example 17
Source File: TwoDPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset,
    Range<Double> rtRange, Range<Double> mzRange, String whichPlotTypeStr) {

  super(null, true);

  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  setBackground(Color.white);
  setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

  // set the X axis (retention time) properties
  xAxis = new NumberAxis("Retention time");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  // set the Y axis (intensity) properties
  yAxis = new NumberAxis("m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  // set the plot properties
  if (whichPlotTypeStr == "default") {
    plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  } else if (whichPlotTypeStr == "point2D") {
    plot = new PointTwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
  }
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // chart properties
  chart = new JFreeChart("", titleFont, plot, false);
  chart.setBackgroundPaint(Color.white);

  setChart(chart);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set crosshair (selection) properties
  plot.setRangeCrosshairVisible(false);
  plot.setDomainCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  peakDataRenderer = new PeakDataRenderer();

  JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode");
  plotTypeMenuItem.addActionListener(visualizer);
  plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE");
  add(plotTypeMenuItem);

  JPopupMenu popupMenu = getPopupMenu();
  popupMenu.addSeparator();
  popupMenu.add(plotTypeMenuItem);

  // Add EMF and EPS options to the save as menu
  JMenuItem saveAsMenu = (JMenuItem) popupMenu.getComponent(3);
  GUIUtils.addMenuItem(saveAsMenu, "EMF...", this, "SAVE_EMF");
  GUIUtils.addMenuItem(saveAsMenu, "EPS...", this, "SAVE_EPS");


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 18
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void addAction(JTextComponent component, JPopupMenu popupMenu, Action action) {
    Lookup contextLookup = getContextLookup(component);
    
    // issue #69688
    EditorKit kit = component.getUI().getEditorKit(component);
    if (contextLookup == null && (kit instanceof NbEditorKit) &&
            ((NbEditorKit)kit).systemAction2editorAction.containsKey(action.getClass().getName())){
        addAction(component, popupMenu, (String) ((NbEditorKit)kit).systemAction2editorAction.get(action.getClass().getName()));
        return;
    }
    
    action = translateContextLookupAction(contextLookup, action);

    if (action != null) {
        JMenuItem item = createLocalizedMenuItem(action);
        if (item instanceof DynamicMenuContent) {
            Component[] cmps = ((DynamicMenuContent)item).getMenuPresenters();
            for (int i = 0; i < cmps.length; i++) {
                if(cmps[i] != null) {
                    popupMenu.add(cmps[i]);
                } else {
                    popupMenu.addSeparator();
                }
            }
        } else {
            if (Boolean.TRUE.equals(action.getValue(DynamicMenuContent.HIDE_WHEN_DISABLED)) && !action.isEnabled()) {
                return;
            }
            if (item == null) {
                LOG.log(Level.WARNING, "Null menu item produced by action {0}.", action);
            } else {
                item.setEnabled(action.isEnabled());
                Object helpID = action.getValue ("helpID"); // NOI18N
                if (helpID != null && (helpID instanceof String)) {
                    item.putClientProperty ("HelpID", helpID); // NOI18N
                }
                assignAccelerator(component.getKeymap(), action, item);
                debugPopupMenuItem(item, action);
                popupMenu.add(item);
            }
        }
    }
}
 
Example 19
Source File: KseFrame.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private void initKeyStoreTabPopupMenu() {
	jpmKeyStoreTab = new JPopupMenu();

	jmiKeyStoreTabSave = new JMenuItem(saveAction);
	jmiKeyStoreTabSave.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabSave, (String) saveAction.getValue(Action.LONG_DESCRIPTION), this);
	jpmKeyStoreTab.add(jmiKeyStoreTabSave);

	jmiKeyStoreTabSaveAll = new JMenuItem(saveAllAction);
	jmiKeyStoreTabSaveAll.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabSaveAll, (String) saveAllAction.getValue(Action.LONG_DESCRIPTION),
			this);
	jpmKeyStoreTab.add(jmiKeyStoreTabSaveAll);

	jpmKeyStoreTab.addSeparator();

	jmiKeyStoreTabPaste = new JMenuItem(pasteAction);
	jmiKeyStoreTabPaste.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabPaste, (String) pasteAction.getValue(Action.LONG_DESCRIPTION), this);
	jpmKeyStoreTab.add(jmiKeyStoreTabPaste);

	jpmKeyStoreTab.addSeparator();

	jmiKeyStoreTabClose = new JMenuItem(closeAction);
	jmiKeyStoreTabClose.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabClose, (String) closeAction.getValue(Action.LONG_DESCRIPTION), this);
	jpmKeyStoreTab.add(jmiKeyStoreTabClose);

	jmiKeyStoreTabCloseOthers = new JMenuItem(closeOthersAction);
	jmiKeyStoreTabCloseOthers.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabCloseOthers,
			(String) closeOthersAction.getValue(Action.LONG_DESCRIPTION), this);
	jpmKeyStoreTab.add(jmiKeyStoreTabCloseOthers);

	jmiKeyStoreTabCloseAll = new JMenuItem(closeAllAction);
	jmiKeyStoreTabCloseAll.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabCloseAll, (String) closeAllAction.getValue(Action.LONG_DESCRIPTION),
			this);
	jpmKeyStoreTab.add(jmiKeyStoreTabCloseAll);

	jpmKeyStoreTab.addSeparator();

	jmiKeyStoreTabProperties = new JMenuItem(propertiesAction);
	jmiKeyStoreTabProperties.setToolTipText(null);
	new StatusBarChangeHandler(jmiKeyStoreTabProperties,
			(String) propertiesAction.getValue(Action.LONG_DESCRIPTION), this);
	jpmKeyStoreTab.add(jmiKeyStoreTabProperties);
}
 
Example 20
Source File: CMemoryMenu.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the context menu of a memory viewer component.
 * 
 * @param offset The memory offset where the context menu will be shown.
 * 
 * @return The context menu for the specified address.
 */
@Override
public JPopupMenu createMenu(final long offset) {
  final JPopupMenu menu = new JPopupMenu();

  final IDebugger debugger = m_debugger.getCurrentSelectedDebugger();

  if (debugger == null) {
    return null;
  }

  menu.add(CActionProxy.proxy(new CSearchAction(m_parent, m_debugger, m_memoryView)));
  menu.add(CActionProxy.proxy(new CGotoAction(m_parent, m_memoryView, m_debugger)));

  if (canReadDword(debugger.getProcessManager().getMemoryMap(), offset)) {
    final byte[] data = debugger.getProcessManager().getMemory().getData(offset, 4);
    final IAddress dword = new CAddress(ByteHelpers.readDwordLittleEndian(data, 0));

    if (canReadDword(debugger.getProcessManager().getMemoryMap(), dword.toLong())) {
      menu.add(CActionProxy.proxy(new CFollowDumpAction(m_debugger, dword)));
    }
  }

  menu.addSeparator();

  final long firstOffset = m_memoryView.getHexView().getBaseAddress();
  final int size = m_memoryView.getHexView().getData().getDataLength();

  menu.add(new CLoadAllAction(m_parent, debugger, new CAddress(firstOffset), size));

  // Offer the option to dump memory
  final JMenu dumpMenu = new JMenu("Dump to file");

  dumpMenu.add(CActionProxy.proxy(new CDumpMemoryRangeAction(m_parent, debugger, m_memoryView
      .getHexView().getData(), new CAddress(firstOffset), size)));

  menu.add(dumpMenu);

  menu.addSeparator();

  final BookmarkManager manager = debugger.getBookmarkManager();

  // At first offer the option to add or remove a bookmark
  // at the specified position.
  final CBookmark bookmark = manager.getBookmark(new CAddress(offset));

  if (bookmark == null) {
    menu.add(new JMenuItem(CActionProxy.proxy(new CCreateBookmarkAction(manager, new CAddress(
        offset)))));
  } else {
    menu.add(new JMenuItem(CActionProxy.proxy(new CDeleteBookmarkAction(manager, bookmark))));
  }

  if (manager.getNumberOfBookmarks() != 0) {
    // Afterwards list all currently active bookmarks.

    menu.addSeparator();

    final JMenu bookmarksItem = new JMenu("Bookmarks");

    for (int i = 0; i < manager.getNumberOfBookmarks(); i++) {
      bookmarksItem.add(CActionProxy.proxy(new CGotoBookmarkAction(m_debugger, manager
          .getBookmark(i))));
    }

    menu.add(bookmarksItem);
  }

  menu.addSeparator();

  menu.add(HexViewOptionsMenu.createHexViewOptionsMenu(m_memoryView.getHexView()));

  return menu;
}