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;
}
}
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);
}
}
}
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();
}
}
}
}
}
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;
}
}
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;
}
}
Aggregations