Search in sources :

Example 1 with ContextMenuItemManipulator

use of org.gephi.datalab.spi.ContextMenuItemManipulator in project gephi by gephi.

the class GraphContextMenu method createMenuItemFromGraphContextMenuItem.

public JMenuItem createMenuItemFromGraphContextMenuItem(final GraphContextMenuItem item, final Graph graph, final Node[] nodes) {
    ContextMenuItemManipulator[] subItems = item.getSubItems();
    if (subItems != null && item.canExecute()) {
        JMenu subMenu = new JMenu();
        subMenu.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            subMenu.setToolTipText(item.getDescription());
        }
        subMenu.setIcon(item.getIcon());
        Integer lastItemType = null;
        for (ContextMenuItemManipulator subItem : subItems) {
            ((GraphContextMenuItem) subItem).setup(graph, nodes);
            if (lastItemType == null) {
                lastItemType = subItem.getType();
            }
            if (lastItemType != subItem.getType()) {
                subMenu.addSeparator();
            }
            lastItemType = subItem.getType();
            if (subItem.isAvailable()) {
                subMenu.add(createMenuItemFromGraphContextMenuItem((GraphContextMenuItem) subItem, graph, nodes));
            }
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for opening a sub menu
            subMenu.setMnemonic(item.getMnemonicKey());
        }
        return subMenu;
    } else {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            menuItem.setToolTipText(item.getDescription());
        }
        menuItem.setIcon(item.getIcon());
        if (item.canExecute()) {
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Thread() {

                        @Override
                        public void run() {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }.start();
                }
            });
        } else {
            menuItem.setEnabled(false);
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for executing the action
            menuItem.setMnemonic(item.getMnemonicKey());
            //And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
            menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
        }
        return menuItem;
    }
}
Also used : GraphContextMenuItem(org.gephi.visualization.spi.GraphContextMenuItem) ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 2 with ContextMenuItemManipulator

use of org.gephi.datalab.spi.ContextMenuItemManipulator in project gephi by gephi.

the class DataTableTopComponent method mapItems.

private void mapItems(ContextMenuItemManipulator[] items, Map<Integer, ContextMenuItemManipulator> map) {
    Integer key;
    ContextMenuItemManipulator[] subItems;
    for (ContextMenuItemManipulator item : items) {
        key = item.getMnemonicKey();
        if (key != null) {
            if (!map.containsKey(key)) {
                map.put(key, item);
            }
        }
        subItems = item.getSubItems();
        if (subItems != null) {
            mapItems(subItems, map);
        }
    }
}
Also used : ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator)

Example 3 with ContextMenuItemManipulator

use of org.gephi.datalab.spi.ContextMenuItemManipulator in project gephi by gephi.

the class DataTableTopComponent method eventDispatched.

/**
     * To react to Ctrl+F keys combination calling Search/Replace general action
     * (and nodes/edges context menu mappings)
     *
     * @param event
     */
@Override
public void eventDispatched(AWTEvent event) {
    KeyEvent evt = (KeyEvent) event;
    if (evt.getID() == KeyEvent.KEY_RELEASED && (evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) {
        DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
        if (evt.getKeyCode() == KeyEvent.VK_F) {
            //Call Search replace with 'F' without general actions key mappings support:
            GeneralActionsManipulator gam = dlh.getGeneralActionsManipulatorByName("SearchReplace");
            if (gam != null) {
                dlh.executeManipulator(gam);
            }
            evt.consume();
        } else {
            //Nodes/edges mappings:
            if (isShowingNodesTable()) {
                final ContextMenuItemManipulator item = nodesActionMappings.get(evt.getKeyCode());
                if (item != null) {
                    Node[] nodes = nodeTable.getElementsFromSelectedRows().toArray(new Node[0]);
                    if (nodes.length > 0) {
                        ((NodesManipulator) item).setup(nodes, nodes[0]);
                        if (item.isAvailable() && item.canExecute()) {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }
                    evt.consume();
                }
            } else if (isShowingEdgesTable()) {
                final ContextMenuItemManipulator item = edgesActionMappings.get(evt.getKeyCode());
                if (item != null) {
                    Edge[] edges = edgeTable.getElementsFromSelectedRows().toArray(new Edge[0]);
                    if (edges.length > 0) {
                        ((EdgesManipulator) item).setup(edges, edges[0]);
                        if (item.isAvailable() && item.canExecute()) {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }
                    evt.consume();
                }
            }
        }
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) GeneralActionsManipulator(org.gephi.datalab.spi.general.GeneralActionsManipulator) PluginGeneralActionsManipulator(org.gephi.datalab.spi.general.PluginGeneralActionsManipulator) Node(org.gephi.graph.api.Node) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator) Edge(org.gephi.graph.api.Edge)

Example 4 with ContextMenuItemManipulator

use of org.gephi.datalab.spi.ContextMenuItemManipulator in project gephi by gephi.

the class PopupMenuUtils method createMenuItemFromNodesManipulator.

public static JMenuItem createMenuItemFromNodesManipulator(final NodesManipulator item, final Node clickedNode, final Node[] nodes) {
    ContextMenuItemManipulator[] subItems = item.getSubItems();
    if (subItems != null && item.canExecute()) {
        JMenu subMenu = new JMenu();
        subMenu.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            subMenu.setToolTipText(item.getDescription());
        }
        subMenu.setIcon(item.getIcon());
        Integer lastItemType = null;
        for (ContextMenuItemManipulator subItem : subItems) {
            ((NodesManipulator) subItem).setup(nodes, clickedNode);
            if (lastItemType == null) {
                lastItemType = subItem.getType();
            }
            if (lastItemType != subItem.getType()) {
                subMenu.addSeparator();
            }
            lastItemType = subItem.getType();
            if (subItem.isAvailable()) {
                subMenu.add(createMenuItemFromNodesManipulator((NodesManipulator) subItem, clickedNode, nodes));
            }
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for opening a sub menu
            subMenu.setMnemonic(item.getMnemonicKey());
        }
        return subMenu;
    } else {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            menuItem.setToolTipText(item.getDescription());
        }
        menuItem.setIcon(item.getIcon());
        if (item.canExecute()) {
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Thread() {

                        @Override
                        public void run() {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }.start();
                }
            });
        } else {
            menuItem.setEnabled(false);
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for executing the action
            menuItem.setMnemonic(item.getMnemonicKey());
            //And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
            menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
        }
        return menuItem;
    }
}
Also used : ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 5 with ContextMenuItemManipulator

use of org.gephi.datalab.spi.ContextMenuItemManipulator in project gephi by gephi.

the class PopupMenuUtils method createMenuItemFromEdgesManipulator.

public static JMenuItem createMenuItemFromEdgesManipulator(final EdgesManipulator item, final Edge clickedEdge, final Edge[] edges) {
    ContextMenuItemManipulator[] subItems = item.getSubItems();
    if (subItems != null && item.canExecute()) {
        JMenu subMenu = new JMenu();
        subMenu.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            subMenu.setToolTipText(item.getDescription());
        }
        subMenu.setIcon(item.getIcon());
        Integer lastItemType = null;
        for (ContextMenuItemManipulator subItem : subItems) {
            ((EdgesManipulator) subItem).setup(edges, clickedEdge);
            if (lastItemType == null) {
                lastItemType = subItem.getType();
            }
            if (lastItemType != subItem.getType()) {
                subMenu.addSeparator();
            }
            lastItemType = subItem.getType();
            if (subItem.isAvailable()) {
                subMenu.add(createMenuItemFromEdgesManipulator((EdgesManipulator) subItem, clickedEdge, edges));
            }
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for opening a sub menu
            subMenu.setMnemonic(item.getMnemonicKey());
        }
        return subMenu;
    } else {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            menuItem.setToolTipText(item.getDescription());
        }
        menuItem.setIcon(item.getIcon());
        if (item.canExecute()) {
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Thread() {

                        @Override
                        public void run() {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }.start();
                }
            });
        } else {
            menuItem.setEnabled(false);
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for executing the action
            menuItem.setMnemonic(item.getMnemonicKey());
            //And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
            menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
        }
        return menuItem;
    }
}
Also used : ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) EdgesManipulator(org.gephi.datalab.spi.edges.EdgesManipulator) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

ContextMenuItemManipulator (org.gephi.datalab.spi.ContextMenuItemManipulator)5 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JMenu (javax.swing.JMenu)3 JMenuItem (javax.swing.JMenuItem)3 NodesManipulator (org.gephi.datalab.spi.nodes.NodesManipulator)2 KeyEvent (java.awt.event.KeyEvent)1 DataLaboratoryHelper (org.gephi.datalab.api.DataLaboratoryHelper)1 EdgesManipulator (org.gephi.datalab.spi.edges.EdgesManipulator)1 GeneralActionsManipulator (org.gephi.datalab.spi.general.GeneralActionsManipulator)1 PluginGeneralActionsManipulator (org.gephi.datalab.spi.general.PluginGeneralActionsManipulator)1 Edge (org.gephi.graph.api.Edge)1 Node (org.gephi.graph.api.Node)1 GraphContextMenuItem (org.gephi.visualization.spi.GraphContextMenuItem)1