Example usage for javax.swing Action getValue

List of usage examples for javax.swing Action getValue

Introduction

In this page you can find the example usage for javax.swing Action getValue.

Prototype

public Object getValue(String key);

Source Link

Document

Gets one of this object's properties using the associated key.

Usage

From source file:Main.java

/**
 * /*from   www  .j  a  v  a2s  .co  m*/
 * TODO
 * @param action
 * @return
 */
public static AbstractButton createToolbarItem(Action action) {
    final AbstractButton button;
    if (action == null) {
        throw new NullPointerException("Action cannot be null!");
    } else if (action.getValue(Action.SELECTED_KEY) != null) {
        button = new JToggleButton(action);
    } else {
        button = new JButton(action);
    }

    button.setOpaque(false);
    // hide text if icon is available
    if (action != null
            && (action.getValue(Action.SMALL_ICON) != null || action.getValue(Action.LARGE_ICON_KEY) != null)) {
        button.setHideActionText(true);
    }
    button.setHorizontalTextPosition(JButton.CENTER);
    button.setVerticalTextPosition(JButton.BOTTOM);
    return button;
}

From source file:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Adds a component action./*  w  w  w .j  a  va  2s .c om*/
 * 
 * @param component
 *            The compoenet to add the action to
 * @param action
 *            The action to add
 */
public static void addComponentAction(final JComponent component, final Action action) {
    final InputMap imap = component
            .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW);
    final ActionMap amap = component.getActionMap();
    final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
    imap.put(ks, action.getValue(Action.NAME));
    amap.put(action.getValue(Action.NAME), action);
}

From source file:TextComponentDemo.java

private void createActionTable(JTextComponent textComponent) {
    actions = new HashMap<Object, Action>();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }/*from   www  .jav a2s  . c om*/
}

From source file:de.tbuchloh.kiskis.gui.MainFrame.java

/**
 * @see de.tbuchloh.kiskis.gui.systray.IMainFrame#getPopupMenu()
 *//* w  w w .  j  av a2  s .c om*/
@Override
public PopupMenu getPopupMenu() {
    final PopupMenu popup = new PopupMenu();
    for (final Action act : _main.getPopupActions()) {
        if (act == null) {
            popup.addSeparator();
        } else {
            final MenuItem mi = new MenuItem((String) act.getValue(Action.NAME));
            mi.setEnabled(act.isEnabled());
            mi.addActionListener(act);
            mi.setFont(new Font("Arial", Font.BOLD, 12));
            popup.add(mi);
        }
    }
    return popup;
}

From source file:TextComponentDemo.java

private void createActionTable(JTextComponent textComponent) {
    actions = new HashMap();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }//from   ww  w .j a v  a 2s .  c om
}

From source file:TextComponentDemo.java

private HashMap<Object, Action> createActionTable(JTextComponent textComponent) {
    HashMap<Object, Action> actions = new HashMap<Object, Action>();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }/*from  w  w w .  j a v a  2 s.  c  o m*/
    return actions;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

/**
 * @param map// ww w.j  a va  2  s  . co m
 * @param actions
 */
public static void addActionsToMap(ActionMap map, Action[] actions) {
    if ((map != null) && (actions != null)) {
        for (Action a : actions) {
            String cmd = (String) a.getValue(Action.ACTION_COMMAND_KEY);

            if (cmd == null) {
                cmd = (String) a.getValue(Action.NAME);
            }

            map.put(cmd, a);
        }
    }
}

From source file:com.opendoorlogistics.studio.appframe.AppFrame.java

private void initToolbar(ActionFactory actionBuilder, List<? extends Action> fileActions,
        List<? extends Action> editActions) {
    getContentPane().add(mainToolbar, BorderLayout.WEST);

    mainToolbar.setFloatable(false);//from   w w  w.  jav  a  2  s . c o  m

    mainToolbar.removeAll();
    for (Action action : fileActions) {
        if (action != null && action.getValue(Action.LARGE_ICON_KEY) != null) {
            mainToolbar.add(action);
        }
    }
    for (Action action : editActions) {
        if (action != null && action.getValue(Action.LARGE_ICON_KEY) != null) {
            mainToolbar.add(action);
        }
    }

    Action helpsite = actionBuilder.createGotoWebsiteAction(this);
    if (helpsite != null) {
        mainToolbar.add(helpsite);
    }

    mainToolbar.revalidate();
    mainToolbar.repaint();
}

From source file:maltcms.ui.nb.pipelineRunner.actions.RunMaltcmsPipelinesAction.java

protected static JMenu actionsToMenu(String menuName, Action[] actions, Lookup context) {
    //code from Utilities.actionsToPopup
    // keeps actions for which was menu item created already (do not add them twice)
    Set<Action> counted = new HashSet<>();
    // components to be added (separators are null)
    List<Component> components = new ArrayList<>();

    for (Action action : actions) {
        if (action != null && counted.add(action)) {
            // switch to replacement action if there is some
            if (action instanceof ContextAwareAction) {
                //               System.out.println("Context aware action");
                Action contextAwareAction = ((ContextAwareAction) action).createContextAwareInstance(context);
                if (contextAwareAction == null) {
                    Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.WARNING,
                            "ContextAwareAction.createContextAwareInstance(context) returns null. That is illegal!"
                                    + " action={0}, context={1}",
                            new Object[] { action, context });
                } else {
                    action = contextAwareAction;
                }//from  w  ww  .  jav  a  2s .  c  o  m
            }

            JMenuItem item;
            if (action instanceof JMenuItem || action instanceof JMenu) {
                item = (JMenuItem) action;
            } else if (action instanceof Presenter.Popup) {
                //               System.out.println("Popup menu");
                item = ((Presenter.Popup) action).getPopupPresenter();
                if (item == null) {
                    Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.WARNING,
                            "findContextMenuImpl, getPopupPresenter returning null for {0}", action);
                    continue;
                }
            } else if (action instanceof DynamicMenuContent) {
                //               System.out.println("Dynamic content menu");
                DynamicMenuContent dmc = (DynamicMenuContent) action;
                JComponent[] presenters = dmc.getMenuPresenters();
                String name = action.getValue("name").toString();
                item = new JMenuItem(name);
                for (JComponent jc : presenters) {
                    item.add(jc);
                }
            } else {
                //               System.out.println("Plain menu action");
                // We need to correctly handle mnemonics with '&' etc.
                item = ActionPresenterProvider.getDefault().createPopupPresenter(action);
            }

            for (Component c : ActionPresenterProvider.getDefault().convertComponents(item)) {
                if (c instanceof JSeparator) {
                    components.add(null);
                } else {
                    components.add(c);
                }
            }
        } else {
            components.add(null);
        }
    }

    // Now create actual menu. Strip adjacent, leading, and trailing separators.
    JMenu menu = new JMenu(menuName);
    boolean nonempty = false; // has anything been added yet?
    boolean pendingSep = false; // should there be a separator before any following item?
    for (Component c : components) {
        try {
            if (c == null) {
                pendingSep = nonempty;
            } else {
                nonempty = true;
                if (pendingSep) {
                    pendingSep = false;
                    menu.addSeparator();
                }
                menu.add(c);
            }
        } catch (RuntimeException ex) {
            Exceptions.attachMessage(ex, "Current component: " + c); // NOI18N
            Exceptions.attachMessage(ex, "List of components: " + components); // NOI18N
            Exceptions.attachMessage(ex, "List of actions: " + Arrays.asList(actions)); // NOI18N
            Exceptions.printStackTrace(ex);
        }
    }
    return menu;
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

@Override
public JPopupMenu getComponentPopupMenu() {
    JPopupMenu popupMenu = getFileChooser().getComponentPopupMenu();

    if (popupMenu != null) {
        return popupMenu;
    }//from w ww . ja va 2s .  co m

    JMenu aViewMenu = getViewMenu();

    if (contextMenu == null) {
        contextMenu = new JPopupMenu();

        if (aViewMenu != null) {
            contextMenu.add(aViewMenu);

            if (listViewWindowsStyle) {
                contextMenu.addSeparator();
            }
        }

        ActionMap actionMap = getActionMap();
        Action refreshAction = actionMap.get(ACTION_REFRESH);
        Action aNewFolderAction = actionMap.get(ACTION_NEW_FOLDER);
        Action showHiddenFiles = actionMap.get(ACTION_VIEW_HIDDEN);

        if (refreshAction != null) {
            contextMenu.add(refreshAction);

            if (listViewWindowsStyle && (aNewFolderAction != null)) {
                contextMenu.addSeparator();
            }
        }

        if (showHiddenFiles != null) {
            JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem(showHiddenFiles);
            menuitem.setSelected((Boolean) showHiddenFiles.getValue(Action.SELECTED_KEY));
            contextMenu.add(menuitem);
        }

        if (aNewFolderAction != null) {
            contextMenu.add(aNewFolderAction);
        }
    }

    if (aViewMenu != null) {
        aViewMenu.getPopupMenu().setInvoker(aViewMenu);
    }

    return contextMenu;
}