Search in sources :

Example 1 with EdgesManipulator

use of org.gephi.datalab.spi.edges.EdgesManipulator in project gephi by gephi.

the class DataLaboratoryHelper method getEdgesManipulators.

/**
     * <p>Prepares an array with one new instance of every EdgesManipulator
     * that has a builder registered and returns it.</p>
     * <p>It also returns the manipulators ordered first by type and then by position.</p>
     * @return Array of all EdgesManipulator implementations
     */
public EdgesManipulator[] getEdgesManipulators() {
    ArrayList<EdgesManipulator> edgesManipulators = new ArrayList<>();
    for (EdgesManipulatorBuilder em : Lookup.getDefault().lookupAll(EdgesManipulatorBuilder.class)) {
        edgesManipulators.add(em.getEdgesManipulator());
    }
    sortManipulators(edgesManipulators);
    return edgesManipulators.toArray(new EdgesManipulator[0]);
}
Also used : ArrayList(java.util.ArrayList) EdgesManipulator(org.gephi.datalab.spi.edges.EdgesManipulator) EdgesManipulatorBuilder(org.gephi.datalab.spi.edges.EdgesManipulatorBuilder)

Example 2 with EdgesManipulator

use of org.gephi.datalab.spi.edges.EdgesManipulator in project gephi by gephi.

the class EdgesPopupAdapter method createPopup.

@Override
protected JPopupMenu createPopup(Point p) {
    final List<Edge> selectedElements = elementsDataTable.getElementsFromSelectedRows();
    final Edge clickedElement = elementsDataTable.getElementFromRow(table.rowAtPoint(p));
    JPopupMenu contextMenu = new JPopupMenu();
    //First add edges manipulators items:
    DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    Integer lastManipulatorType = null;
    for (EdgesManipulator em : dlh.getEdgesManipulators()) {
        em.setup(selectedElements.toArray(new Edge[0]), clickedElement);
        if (lastManipulatorType == null) {
            lastManipulatorType = em.getType();
        }
        if (lastManipulatorType != em.getType()) {
            contextMenu.addSeparator();
        }
        lastManipulatorType = em.getType();
        if (em.isAvailable()) {
            contextMenu.add(PopupMenuUtils.createMenuItemFromEdgesManipulator(em, clickedElement, selectedElements.toArray(new Edge[0])));
        }
    }
    //Add AttributeValues manipulators submenu:
    Column column = elementsDataTable.getColumnAtIndex(table.columnAtPoint(p));
    if (column != null) {
        contextMenu.add(PopupMenuUtils.createSubMenuFromRowColumn(clickedElement, column));
    }
    return contextMenu;
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) Column(org.gephi.graph.api.Column) EdgesManipulator(org.gephi.datalab.spi.edges.EdgesManipulator) Edge(org.gephi.graph.api.Edge) JPopupMenu(javax.swing.JPopupMenu)

Example 3 with EdgesManipulator

use of org.gephi.datalab.spi.edges.EdgesManipulator 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

EdgesManipulator (org.gephi.datalab.spi.edges.EdgesManipulator)3 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 DataLaboratoryHelper (org.gephi.datalab.api.DataLaboratoryHelper)1 ContextMenuItemManipulator (org.gephi.datalab.spi.ContextMenuItemManipulator)1 EdgesManipulatorBuilder (org.gephi.datalab.spi.edges.EdgesManipulatorBuilder)1 Column (org.gephi.graph.api.Column)1 Edge (org.gephi.graph.api.Edge)1