Search in sources :

Example 1 with AbstractCyAction

use of org.cytoscape.application.swing.AbstractCyAction 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 AbstractCyAction

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

the class CytoscapeMenuBar method configgedAction.

private AbstractCyAction configgedAction(CyAction action) {
    String mappedAction = actionOverrideMap.get(action.getName());
    if (mappedAction != null) {
        String[] tokens = mappedAction.split(TABSTR);
        // assert tokens.length == 9;
        String name = tokens[0];
        String accelerator = tokens[1];
        // -------------------- !!!!!!!!!!!!!!  ----------- this will break, as setters aren't in the api yet
        if (// its the full table (otherwise its just accelerator definition)
        tokens.length == 9) {
            boolean inMenuBar = "T".equals(tokens[2]);
            String prefMenu = tokens[3];
            String gravity = tokens[4];
            boolean inToolBar = "T".equals(tokens[5]);
            String toolgravity = tokens[6];
            // last two not used
            boolean enabled = "T".equals(tokens[7]);
            String classname = tokens[8];
            action.setEnabled(enabled);
            // action.setIsInMenuBar(inMenuBar);
            // action.setPreferredMenu(prefMenu);
            float f = 0, g = 0;
            try {
                f = Float.parseFloat(gravity);
            } catch (Exception e) {
            }
            // action.setMenuGravity(g);
            try {
                g = Float.parseFloat(toolgravity);
            } catch (Exception e) {
            }
        // action.setToolbarGravity(g);
        // action.setIsInToolBar(inToolBar);
        }
        if (verbose && !produceActionTable) {
            KeyStroke key = KeyStroke.getKeyStroke(accelerator);
        // if (key != action.getAcceleratorKeyStroke())
        // System.out.println("Overriding: " + name + " with " + accelerator);  // + (inMenuBar ? " menu" : "") + (inToolBar ? " tool" : "")
        }
        try {
            AbstractCyAction cast = (AbstractCyAction) action;
            cast.setAcceleratorKeyStroke(KeyStroke.getKeyStroke(accelerator));
        } catch (ClassCastException e) {
            System.err.println("WTF? action isn't an AbstractCyAction");
        }
    }
    return (AbstractCyAction) action;
}
Also used : AbstractCyAction(org.cytoscape.application.swing.AbstractCyAction) KeyStroke(javax.swing.KeyStroke) IOException(java.io.IOException)

Example 3 with AbstractCyAction

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

the class CytoscapeToolBar method addAction.

/**
 * If the given Action has an absent or false inToolBar property, return;
 * otherwise delegate to addAction( String, Action ) with the value of its
 * gravity property.
 */
public boolean addAction(CyAction action) {
    if (!action.isInToolBar())
        return false;
    // At present we allow an Action to be in this tool bar only once.
    if (actionButtonMap.containsKey(action))
        return false;
    boolean insertSepBefore = false;
    boolean insertSepAfter = false;
    if (action instanceof AbstractCyAction) {
        insertSepBefore = ((AbstractCyAction) action).insertToolbarSeparatorBefore();
        insertSepAfter = ((AbstractCyAction) action).insertToolbarSeparatorAfter();
    }
    final JButton button = createToolBarButton(action);
    if (insertSepBefore)
        addSeparator(action.getToolbarGravity() - .0001f);
    if (insertSepAfter)
        addSeparator(action.getToolbarGravity() + .0001f);
    componentGravity.put(button, action.getToolbarGravity());
    actionButtonMap.put(action, button);
    int addIndex = getInsertLocation(action.getToolbarGravity());
    orderedList.add(addIndex, button);
    if (stopList.contains(action.getName()))
        button.setVisible(false);
    addComponents();
    return true;
}
Also used : AbstractCyAction(org.cytoscape.application.swing.AbstractCyAction) JButton(javax.swing.JButton)

Example 4 with AbstractCyAction

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

the class VizMapperMediator method onTaskFactoryRegistered.

/**
 * Create menu items for related registered Task Factories.
 */
public void onTaskFactoryRegistered(final TaskFactory taskFactory, final Map<?, ?> properties) {
    // First filter the service...
    final String serviceType = ServicePropertiesUtil.getServiceType(properties);
    if (serviceType == null || !serviceType.toString().startsWith("vizmapUI"))
        return;
    final String title = ServicePropertiesUtil.getTitle(properties);
    if (title == null) {
        logger.error("Cannot create VizMapper menu item for: " + taskFactory + "; \"" + ServiceProperties.TITLE + "\" metadata is missing from properties: " + properties);
        return;
    }
    // Add new menu to the pull-down
    final HashMap<String, String> config = new HashMap<>();
    config.put(ServiceProperties.TITLE, title.toString());
    final AbstractCyAction action = new AbstractCyAction(config, taskFactory) {

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

                @Override
                public void run() {
                    servicesUtil.get(DialogTaskManager.class).execute(taskFactory.createTaskIterator());
                }
            }.start();
        }
    };
    invokeOnEDT(() -> {
        final JMenuItem menuItem = createMenuItem(action, properties);
        if (menuItem != null)
            taskFactories.put(taskFactory, menuItem);
    });
}
Also used : AbstractCyAction(org.cytoscape.application.swing.AbstractCyAction) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem)

Aggregations

AbstractCyAction (org.cytoscape.application.swing.AbstractCyAction)4 JMenuItem (javax.swing.JMenuItem)2 KeyStroke (javax.swing.KeyStroke)2 ActionEvent (java.awt.event.ActionEvent)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 JButton (javax.swing.JButton)1 JMenu (javax.swing.JMenu)1 GravityTracker (org.cytoscape.util.swing.GravityTracker)1