Search in sources :

Example 6 with JPopupMenu

use of javax.swing.JPopupMenu in project gephi by gephi.

the class LayoutPanel method initEvents.

private void initEvents() {
    layoutCombobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
                setSelectedLayout(null);
            } else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
                LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
                if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
                    setSelectedLayout(builder);
                }
            }
        }
    });
    infoLabel.addMouseListener(new MouseAdapter() {

        RichTooltip richTooltip;

        @Override
        public void mouseEntered(MouseEvent e) {
            if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
                richTooltip = buildTooltip(model.getSelectedBuilder());
                richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (richTooltip != null) {
                richTooltip.hideTooltip();
                richTooltip = null;
            }
        }
    });
    presetsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu menu = new JPopupMenu();
            List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
            if (presets != null && !presets.isEmpty()) {
                for (final Preset p : presets) {
                    JMenuItem item = new JMenuItem(p.toString());
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
                            refreshProperties();
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
                        }
                    });
                    menu.add(item);
                }
            } else {
                menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
            }
            JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
            saveItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
                    NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
                    question.setInputText(lastPresetName);
                    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
                        String input = question.getInputText();
                        if (input != null && !input.isEmpty()) {
                            layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
                            NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
                        }
                    }
                }
            });
            menu.add(new JSeparator());
            menu.add(saveItem);
            menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
        }
    });
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ItemEvent(java.awt.event.ItemEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Preset(org.gephi.desktop.layout.LayoutPresetPersistence.Preset) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) NotifyDescriptor(org.openide.NotifyDescriptor) RichTooltip(org.gephi.ui.components.richtooltip.RichTooltip) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem)

Example 7 with JPopupMenu

use of javax.swing.JPopupMenu in project gephi by gephi.

the class AbstractPopupAdapter method showPopup.

@Override
protected void showPopup(final MouseEvent e) {
    int selRow = table.rowAtPoint(e.getPoint());
    if (selRow != -1) {
        if (!table.getSelectionModel().isSelectedIndex(selRow)) {
            table.getSelectionModel().clearSelection();
            table.getSelectionModel().setSelectionInterval(selRow, selRow);
        }
        final Point p = e.getPoint();
        new Thread(new Runnable() {

            @Override
            public void run() {
                final JPopupMenu pop = createPopup(p);
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        showPopup(p.x, p.y, pop);
                    }
                });
            }
        }).start();
    } else {
        table.getSelectionModel().clearSelection();
    }
    e.consume();
}
Also used : Point(java.awt.Point) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 8 with JPopupMenu

use of javax.swing.JPopupMenu in project gephi by gephi.

the class SelectionBar method createPopup.

public JPopupMenu createPopup() {
    SelectionManager manager = VizController.getInstance().getSelectionManager();
    final MouseSelectionPopupPanel popupPanel = new MouseSelectionPopupPanel();
    popupPanel.setDiameter(manager.getMouseSelectionDiameter());
    popupPanel.setProportionnalToZoom(manager.isMouseSelectionZoomProportionnal());
    popupPanel.setChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager manager = VizController.getInstance().getSelectionManager();
            manager.setMouseSelectionDiameter(popupPanel.getDiameter());
            manager.setMouseSelectionZoomProportionnal(popupPanel.isProportionnalToZoom());
        }
    });
    JPopupMenu menu = new JPopupMenu();
    menu.add(popupPanel);
    return menu;
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) JPopupMenu(javax.swing.JPopupMenu)

Example 9 with JPopupMenu

use of javax.swing.JPopupMenu in project gephi by gephi.

the class ColumnSelectionPanel method showColumnSelectionPopup.

public static void showColumnSelectionPopup(ColumnSelectionModel[] columns, Component c) {
    JPopupMenu popup = new JPopupMenu();
    for (int col = 0; col < columns.length; col++) {
        final ColumnSelectionModel column = columns[col];
        final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem();
        checkBox.setText(column.getName());
        checkBox.setSelected(column.isSelected());
        checkBox.setEnabled(column.isEnabled());
        checkBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                column.setSelected(checkBox.isSelected());
            }
        });
        popup.add(checkBox);
    }
    popup.show(c, 8, 8);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 10 with JPopupMenu

use of javax.swing.JPopupMenu in project binnavi by google.

the class CMemoryMenu method createMenu.

/**
   * 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;
}
Also used : CDeleteBookmarkAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CDeleteBookmarkAction) CFollowDumpAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CFollowDumpAction) CGotoBookmarkAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CGotoBookmarkAction) CGotoAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CGotoAction) CLoadAllAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CLoadAllAction) JPopupMenu(javax.swing.JPopupMenu) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BookmarkManager(com.google.security.zynamics.binnavi.models.Bookmarks.memory.BookmarkManager) CCreateBookmarkAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CCreateBookmarkAction) CBookmark(com.google.security.zynamics.binnavi.models.Bookmarks.memory.CBookmark) CSearchAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CSearchAction) CDumpMemoryRangeAction(com.google.security.zynamics.binnavi.Gui.Debug.MemoryPanel.Actions.CDumpMemoryRangeAction) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)128 JMenuItem (javax.swing.JMenuItem)56 ActionEvent (java.awt.event.ActionEvent)34 ActionListener (java.awt.event.ActionListener)20 JMenu (javax.swing.JMenu)19 Component (java.awt.Component)17 JButton (javax.swing.JButton)16 JScrollPane (javax.swing.JScrollPane)15 AbstractAction (javax.swing.AbstractAction)14 JLabel (javax.swing.JLabel)14 MouseEvent (java.awt.event.MouseEvent)13 Point (java.awt.Point)11 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)11 JSeparator (javax.swing.JSeparator)11 JPanel (javax.swing.JPanel)10 JTable (javax.swing.JTable)10 Dimension (java.awt.Dimension)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 JCheckBox (javax.swing.JCheckBox)6