Search in sources :

Example 1 with CyMenuItem

use of org.cytoscape.application.swing.CyMenuItem in project cytoscape-impl by cytoscape.

the class DynamicNodeLinkoutMenuFactory method createMenuItem.

@Override
public CyMenuItem createMenuItem(CyNetworkView netView, View<CyNode> nodeView) {
    DynamicSupport support = new DynamicSupport(browser, synTaskManager);
    // Gravity from ServiceProperties
    CyMenuItem menuItem = new CyMenuItem(new JMenu(NODE_DYNAMIC_LINKOUTS_MENU), 1100);
    support.createSubMenus(menuItem, netView.getModel(), nodeView.getModel());
    return menuItem;
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) JMenu(javax.swing.JMenu)

Example 2 with CyMenuItem

use of org.cytoscape.application.swing.CyMenuItem in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method createNetworkViewMenu.

/**
 * Creates a menu based on the NetworkView.
 *
 * @param action Acceptable values are "NEW" or "OPEN." Case does not matter.
 */
void createNetworkViewMenu(Point rawPt, Point xformPt, String action) {
    Collection<NetworkViewTaskFactory> usableTFs = getPreferredActions(graphView.emptySpaceTFs, action);
    Collection<NetworkViewLocationTaskFactory> usableTFs2 = getPreferredActions(graphView.networkViewLocationTfs, action);
    Collection<CyNetworkViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyNetworkViewContextMenuFactory, action);
    // remove TaskFactories that can't be executed from double-click menu
    if (action.equalsIgnoreCase("OPEN")) {
        Iterator<NetworkViewTaskFactory> i = usableTFs.iterator();
        while (i.hasNext()) {
            if (!i.next().isReady(graphView))
                i.remove();
        }
        Iterator<NetworkViewLocationTaskFactory> i2 = usableTFs2.iterator();
        while (i2.hasNext()) {
            if (!i2.next().isReady(graphView, rawPt, xformPt))
                i2.remove();
        }
    }
    int menuItemCount = usableTFs.size() + usableTFs2.size() + usableCMFs.size();
    int tfCount = usableTFs.size() + usableTFs2.size();
    if (action.equalsIgnoreCase("OPEN") && menuItemCount == 1 && tfCount == 1) {
        // Double click on open space and there is only one menu item, execute it
        final DialogTaskManager taskManager = serviceRegistrar.getService(DialogTaskManager.class);
        if (usableTFs.size() == 1) {
            NetworkViewTaskFactory tf = usableTFs.iterator().next();
            taskManager.execute(tf.createTaskIterator(graphView));
        } else if (usableTFs2.size() == 1) {
            NetworkViewLocationTaskFactory tf = usableTFs2.iterator().next();
            taskManager.execute(tf.createTaskIterator(graphView, rawPt, xformPt));
        }
    } else {
        final JPopupMenu menu = createMenu("Double Click Menu: empty");
        final JMenuTracker tracker = new JMenuTracker(menu);
        if (!action.equalsIgnoreCase("OPEN")) {
            initializeNetworkTracker(tracker);
            tracker.getGravityTracker(".").addMenuSeparator(-0.1);
            tracker.getGravityTracker(".").addMenuSeparator(999.99);
        }
        for (NetworkViewTaskFactory nvtf : usableTFs) {
            NamedTaskFactory provisioner = factoryProvisioner.createFor(nvtf, graphView);
            addMenuItem(null, menu, provisioner, null, tracker, graphView.emptySpaceTFs.get(nvtf));
        }
        for (NetworkViewLocationTaskFactory nvltf : usableTFs2) {
            NamedTaskFactory provisioner = factoryProvisioner.createFor(nvltf, graphView, rawPt, xformPt);
            addMenuItem(null, menu, provisioner, null, tracker, graphView.networkViewLocationTfs.get(nvltf));
        }
        for (CyNetworkViewContextMenuFactory netVMF : usableCMFs) {
            try {
                CyMenuItem menuItem = netVMF.createMenuItem(graphView);
                addCyMenuItem(graphView, menu, menuItem, tracker, graphView.cyNetworkViewContextMenuFactory.get(netVMF));
            } catch (Throwable t) {
                logger.error("Could not display context menu.", t);
            }
        }
        // There are more than one menu item, let user make the selection
        menu.show(invoker, (int) (rawPt.getX()), (int) (rawPt.getY()));
    }
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) JMenuTracker(org.cytoscape.util.swing.JMenuTracker) NetworkViewLocationTaskFactory(org.cytoscape.task.NetworkViewLocationTaskFactory) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) CyNetworkViewContextMenuFactory(org.cytoscape.application.swing.CyNetworkViewContextMenuFactory) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory)

Example 3 with CyMenuItem

use of org.cytoscape.application.swing.CyMenuItem in project cytoscape-impl by cytoscape.

the class DynamicEdgeLinkoutMenuFactory method createMenuItem.

@Override
public CyMenuItem createMenuItem(CyNetworkView netView, View<CyEdge> edgeView) {
    DynamicSupport support = new DynamicSupport(browser, synTaskManager);
    // Gravity comes from ServiceProperties
    CyMenuItem menuItem = new CyMenuItem(new JMenuItem(EDGE_DYNAMIC_LINKOUTS_MENU), 1050);
    support.createSubMenus(menuItem, netView.getModel(), edgeView.getModel());
    return menuItem;
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) JMenuItem(javax.swing.JMenuItem)

Example 4 with CyMenuItem

use of org.cytoscape.application.swing.CyMenuItem in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method createNodeViewMenu.

/**
 * Creates a menu based on the NodeView.
 *
 * @param action Acceptable values are "NEW", "OPEN", or "EDGE". Case does not matter.
 */
void createNodeViewMenu(NodeView nview, int x, int y, String action) {
    if (nview != null) {
        Collection<NodeViewTaskFactory> usableTFs = getPreferredActions(graphView.nodeViewTFs, action);
        Collection<CyNodeViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyNodeViewContextMenuFactory, action);
        View<CyNode> nv = (DNodeView) nview;
        // If the action is NEW, we should also include the Edge Actions
        if (action.equalsIgnoreCase("NEW")) {
            usableTFs.addAll(getPreferredActions(graphView.nodeViewTFs, "Edge"));
            usableCMFs.addAll(getPreferredActions(graphView.cyNodeViewContextMenuFactory, "Edge"));
        } else // remove TaskFactories that can't be executed from double-click menu
        if (action.equalsIgnoreCase("OPEN")) {
            Iterator<NodeViewTaskFactory> i = usableTFs.iterator();
            while (i.hasNext()) {
                if (!i.next().isReady(nv, graphView))
                    i.remove();
            }
        }
        int menuItemCount = usableTFs.size() + usableCMFs.size();
        int tfCount = usableTFs.size();
        if ((action.equalsIgnoreCase("OPEN") || action.equalsIgnoreCase("Edge")) && menuItemCount == 1 && tfCount == 1) {
            NodeViewTaskFactory tf = usableTFs.iterator().next();
            serviceRegistrar.getService(DialogTaskManager.class).execute(tf.createTaskIterator(nv, graphView));
        } else {
            String nodeLabel = graphView.getModel().getRow(nv.getModel()).get(CyNetwork.NAME, String.class);
            JPopupMenu menu = createMenu(nodeLabel);
            JMenuTracker tracker = new JMenuTracker(menu);
            if (!action.equalsIgnoreCase("OPEN")) {
                initializeNodeTracker(tracker);
                tracker.getGravityTracker(".").addMenuSeparator(-0.1);
                tracker.getGravityTracker(".").addMenuSeparator(999.99);
            }
            for (NodeViewTaskFactory nvtf : usableTFs) {
                Object context = null;
                NamedTaskFactory provisioner = factoryProvisioner.createFor(nvtf, nv, graphView);
                addMenuItem(nv, menu, provisioner, context, tracker, graphView.nodeViewTFs.get(nvtf));
            }
            for (CyNodeViewContextMenuFactory nodeCMF : usableCMFs) {
                // menu.add(nodeVMF.createMenuItem(m_view,  nv).getMenuItem());
                try {
                    CyMenuItem menuItem = nodeCMF.createMenuItem(graphView, nv);
                    addCyMenuItem(nv, menu, menuItem, tracker, graphView.cyNodeViewContextMenuFactory.get(nodeCMF));
                } catch (Throwable t) {
                    logger.error("Could not display context menu.", t);
                }
            }
            menu.show(invoker, x, y);
        }
    }
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) JMenuTracker(org.cytoscape.util.swing.JMenuTracker) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Iterator(java.util.Iterator) CyNode(org.cytoscape.model.CyNode) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory) CyNodeViewContextMenuFactory(org.cytoscape.application.swing.CyNodeViewContextMenuFactory)

Example 5 with CyMenuItem

use of org.cytoscape.application.swing.CyMenuItem in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method createEdgeViewMenu.

/**
 * Creates a menu based on the EdgeView.
 *
 * @param action Acceptable values are "NEW" or "OPEN." Case does not matter.
 */
void createEdgeViewMenu(EdgeView edgeView, int x, int y, String action) {
    if (edgeView != null) {
        Collection<EdgeViewTaskFactory> usableTFs = getPreferredActions(graphView.edgeViewTFs, action);
        Collection<CyEdgeViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyEdgeViewContextMenuFactory, action);
        View<CyEdge> ev = (DEdgeView) edgeView;
        // remove TaskFactories that can't be executed from double-click menu
        if (action.equalsIgnoreCase("OPEN")) {
            Iterator<EdgeViewTaskFactory> i = usableTFs.iterator();
            while (i.hasNext()) {
                if (!i.next().isReady(ev, graphView))
                    i.remove();
            }
        }
        int tfCount = usableTFs.size();
        int menuItemCount = usableTFs.size() + usableCMFs.size();
        if (action.equalsIgnoreCase("OPEN") && menuItemCount == 1 && tfCount == 1) {
            EdgeViewTaskFactory tf = usableTFs.iterator().next();
            serviceRegistrar.getService(DialogTaskManager.class).execute(tf.createTaskIterator(ev, graphView));
        } else {
            String edgeLabel = graphView.getModel().getRow(ev.getModel()).get(CyEdge.INTERACTION, String.class);
            JPopupMenu menu = createMenu(edgeLabel);
            JMenuTracker tracker = new JMenuTracker(menu);
            if (!action.equalsIgnoreCase("OPEN")) {
                initializeEdgeTracker(tracker);
                tracker.getGravityTracker(".").addMenuSeparator(-0.1);
                tracker.getGravityTracker(".").addMenuSeparator(999.99);
            }
            for (EdgeViewTaskFactory evtf : usableTFs) {
                Object context = null;
                NamedTaskFactory provisioner = factoryProvisioner.createFor(evtf, ev, graphView);
                addMenuItem(ev, menu, provisioner, context, tracker, graphView.edgeViewTFs.get(evtf));
            }
            for (CyEdgeViewContextMenuFactory edgeCMF : usableCMFs) {
                // menu.add(edgeCMF.createMenuItem(m_view, ev).getMenuItem());
                try {
                    CyMenuItem menuItem = edgeCMF.createMenuItem(graphView, ev);
                    addCyMenuItem(ev, menu, menuItem, tracker, graphView.cyEdgeViewContextMenuFactory.get(edgeCMF));
                } catch (Throwable t) {
                    logger.error("Could not display context menu.", t);
                }
            }
            menu.show(invoker, x, y);
        }
    }
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) CyEdgeViewContextMenuFactory(org.cytoscape.application.swing.CyEdgeViewContextMenuFactory) JMenuTracker(org.cytoscape.util.swing.JMenuTracker) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) CyEdge(org.cytoscape.model.CyEdge) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Aggregations

CyMenuItem (org.cytoscape.application.swing.CyMenuItem)5 Point (java.awt.Point)3 JPopupMenu (javax.swing.JPopupMenu)3 JMenuTracker (org.cytoscape.util.swing.JMenuTracker)3 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)3 Iterator (java.util.Iterator)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 CyEdgeViewContextMenuFactory (org.cytoscape.application.swing.CyEdgeViewContextMenuFactory)1 CyNetworkViewContextMenuFactory (org.cytoscape.application.swing.CyNetworkViewContextMenuFactory)1 CyNodeViewContextMenuFactory (org.cytoscape.application.swing.CyNodeViewContextMenuFactory)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 EdgeViewTaskFactory (org.cytoscape.task.EdgeViewTaskFactory)1 NetworkViewLocationTaskFactory (org.cytoscape.task.NetworkViewLocationTaskFactory)1 NetworkViewTaskFactory (org.cytoscape.task.NetworkViewTaskFactory)1 NodeViewTaskFactory (org.cytoscape.task.NodeViewTaskFactory)1