Search in sources :

Example 1 with GravityTracker

use of org.cytoscape.util.swing.GravityTracker in project cytoscape-impl by cytoscape.

the class CytoscapeMenuBar method addAction.

/**
 * If the given Action has a present and false inMenuBar property, return;
 * otherwise create the menu item.
 */
public boolean addAction(final CyAction action) {
    if (null == action.getName())
        return false;
    if (produceActionTable)
        dumpActionToTable(action);
    AbstractCyAction configgedAction = configgedAction(action);
    if (configgedAction == null)
        return false;
    if (!configgedAction.isInMenuBar())
        return false;
    // System.out.println("addAction in CytoscapeMenuBar");
    boolean insertSepBefore = configgedAction.insertSeparatorBefore();
    ;
    boolean insertSepAfter = configgedAction.insertSeparatorAfter();
    // We allow an Action to be in this menu bar only once.
    if (actionMenuItemMap.containsKey(configgedAction))
        return false;
    // Actions with no preferredMenu don't show up in any menu.
    String menu_name = configgedAction.getPreferredMenu();
    if (menu_name == null || menu_name.isEmpty())
        return false;
    final GravityTracker gravityTracker = menuTracker.getGravityTracker(menu_name);
    final JMenuItem menu_item = createMenuItem(configgedAction);
    String item = configgedAction.getName();
    if (stopList.contains(item))
        menu_item.setVisible(false);
    // Add an Accelerator Key, if wanted
    final KeyStroke accelerator = configgedAction.getAcceleratorKeyStroke();
    if (accelerator != null)
        menu_item.setAccelerator(accelerator);
    ((JMenu) gravityTracker.getMenu()).addMenuListener(configgedAction);
    if (insertSepBefore)
        gravityTracker.addMenuSeparator(configgedAction.getMenuGravity() - .0001);
    gravityTracker.addMenuItem(menu_item, configgedAction.getMenuGravity());
    if (insertSepAfter)
        gravityTracker.addMenuSeparator(configgedAction.getMenuGravity() + .0001);
    logger.debug("Inserted action for menu: " + menu_name + " with gravity: " + configgedAction.getMenuGravity());
    actionMenuItemMap.put(configgedAction, menu_item);
    revalidate();
    repaint();
    return true;
}
Also used : AbstractCyAction(org.cytoscape.application.swing.AbstractCyAction) GravityTracker(org.cytoscape.util.swing.GravityTracker) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 2 with GravityTracker

use of org.cytoscape.util.swing.GravityTracker in project cytoscape-impl by cytoscape.

the class CytoscapeMenuBar method addSeparator.

public void addSeparator(String menu_name, final double gravity) {
    if (menu_name == null || menu_name.isEmpty())
        menu_name = DEFAULT_MENU_SPECIFIER;
    final GravityTracker gravityTracker = menuTracker.getGravityTracker(menu_name);
    gravityTracker.addMenuSeparator(gravity);
}
Also used : GravityTracker(org.cytoscape.util.swing.GravityTracker)

Example 3 with GravityTracker

use of org.cytoscape.util.swing.GravityTracker in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method addMenuItem.

/**
 * This method creates popup menu submenus and menu items based on the
 * "title" and "preferredMenu" keywords, depending on which are present
 * in the service properties.
 */
private void addMenuItem(View<?> view, JPopupMenu popup, NamedTaskFactory tf, Object tunableContext, JMenuTracker tracker, Map props) {
    String title = (String) (props.get(TITLE));
    String pref = (String) (props.get(PREFERRED_MENU));
    String toolTip = (String) (props.get(TOOLTIP));
    String menuGravity = (String) (props.get(MENU_GRAVITY));
    String prefAction = (String) (props.get(PREFERRED_ACTION));
    boolean insertSepBefore = getBooleanProperty(props, INSERT_SEPARATOR_BEFORE);
    boolean insertSepAfter = getBooleanProperty(props, INSERT_SEPARATOR_AFTER);
    boolean useCheckBoxMenuItem = getBooleanProperty(props, "useCheckBoxMenuItem");
    double gravity;
    if ("View".equalsIgnoreCase(pref))
        // TODO Should we show 'View' options here (e.g. zoom in/out, fit selected)?
        return;
    if (menuGravity != null) {
        gravity = Double.parseDouble(menuGravity);
    } else {
        // gravity = largeValue++;
        // Alphabetize by default
        gravity = -1;
    }
    if (pref == null) {
        if (prefAction != null && prefAction.equalsIgnoreCase("OPEN"))
            pref = ".";
        else
            pref = APPS_MENU;
    }
    // otherwise create our own popup menus
    final Object targetVP = props.get("targetVP");
    boolean isSelected = false;
    if (view != null) {
        if (targetVP != null && targetVP instanceof String) {
            // TODO remove this at first opportunity whenever lookup gets refactored.
            Class<?> clazz = CyNetwork.class;
            if (view.getModel() instanceof CyNode)
                clazz = CyNode.class;
            else if (view.getModel() instanceof CyEdge)
                clazz = CyEdge.class;
            final VisualProperty<?> vp = graphView.getVisualLexicon().lookup(clazz, targetVP.toString());
            if (vp == null)
                isSelected = false;
            else
                isSelected = view.isValueLocked(vp);
        } else if (targetVP instanceof VisualProperty) {
            isSelected = view.isValueLocked((VisualProperty<?>) targetVP);
        }
    }
    // no title
    if (title == null) {
        int last = pref.lastIndexOf(".");
        // if the preferred menu is delimited
        if (last > 0) {
            title = pref.substring(last + 1);
            pref = pref.substring(0, last);
            if (APPS_MENU.equals(title))
                return;
            final GravityTracker gravityTracker = tracker.getGravityTracker(pref);
            final JMenuItem item = createMenuItem(tf, title, useCheckBoxMenuItem, toolTip);
            if (useCheckBoxMenuItem) {
                final JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) item;
                checkBox.setSelected(isSelected);
            }
            if (insertSepBefore)
                gravityTracker.addMenuSeparator(gravity - .0001);
            gravityTracker.addMenuItem(item, gravity);
            if (insertSepAfter)
                gravityTracker.addMenuSeparator(gravity + .0001);
        } else {
            // otherwise just use the preferred menu as the menuitem name
            title = pref;
            if (APPS_MENU.equals(title))
                return;
            // popup.add( createMenuItem(tf, title, useCheckBoxMenuItem, toolTip) );
            final GravityTracker gravityTracker = tracker.getGravityTracker(pref);
            final JMenuItem item = createMenuItem(tf, title, useCheckBoxMenuItem, toolTip);
            gravityTracker.addMenuItem(item, gravity);
        }
    // title and preferred menu
    } else {
        final GravityTracker gravityTracker = tracker.getGravityTracker(pref);
        if (insertSepBefore)
            gravityTracker.addMenuSeparator(gravity - .0001);
        gravityTracker.addMenuItem(createMenuItem(tf, title, useCheckBoxMenuItem, toolTip), gravity);
        if (insertSepAfter)
            gravityTracker.addMenuSeparator(gravity + .0001);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) Point(java.awt.Point) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) GravityTracker(org.cytoscape.util.swing.GravityTracker) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNode(org.cytoscape.model.CyNode) JMenuItem(javax.swing.JMenuItem)

Example 4 with GravityTracker

use of org.cytoscape.util.swing.GravityTracker in project cytoscape-impl by cytoscape.

the class CytoscapeMenuBar method removeAction.

/**
 * If the given Action has a present and false inMenuBar property, return;
 * otherwise, if there's a menu item for the action, remove it. Its menu is
 * determined by its preferredMenu property if it is present; otherwise by
 *  DEFAULT_MENU_SPECIFIER.
 */
public boolean removeAction(CyAction action) {
    JMenuItem menu_item = actionMenuItemMap.remove(action);
    if (menu_item == null)
        return false;
    String menu_name = null;
    if (action.isInMenuBar())
        menu_name = action.getPreferredMenu();
    else
        return false;
    if (menu_name == null)
        menu_name = DEFAULT_MENU_SPECIFIER;
    GravityTracker gravityTracker = menuTracker.getGravityTracker(menu_name);
    gravityTracker.removeComponent(menu_item);
    ((JMenu) gravityTracker.getMenu()).removeMenuListener(action);
    return true;
}
Also used : GravityTracker(org.cytoscape.util.swing.GravityTracker) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 5 with GravityTracker

use of org.cytoscape.util.swing.GravityTracker in project cytoscape-impl by cytoscape.

the class CytoscapeMenuBar method addMenu.

public JMenu addMenu(String menu_string, final double gravity) {
    menu_string += "[" + gravity + "]";
    final GravityTracker gravityTracker = menuTracker.getGravityTracker(menu_string);
    return (JMenu) gravityTracker.getMenu();
}
Also used : GravityTracker(org.cytoscape.util.swing.GravityTracker) JMenu(javax.swing.JMenu)

Aggregations

GravityTracker (org.cytoscape.util.swing.GravityTracker)7 JMenu (javax.swing.JMenu)5 JMenuItem (javax.swing.JMenuItem)4 Point (java.awt.Point)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1 KeyStroke (javax.swing.KeyStroke)1 AbstractCyAction (org.cytoscape.application.swing.AbstractCyAction)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1