Java Swing Key Action setupAction(Action action, ResourceBundle bundle, String actionId)

Here you can find the source of setupAction(Action action, ResourceBundle bundle, String actionId)

Description

Sets action values according to values specified by resource bundle.

License

Open Source License

Parameter

Parameter Description
action modified action
bundle source bundle
actionId action identifier and bundle key prefix

Declaration

public static void setupAction(Action action, ResourceBundle bundle,
        String actionId) 

Method Source Code

//package com.java2s;
/*/*from w  w  w.  j a  v  a  2  s  .c  o m*/
 * Copyright (C) ExBin Project
 *
 * This application or library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * This application or library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along this application.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ResourceBundle;
import javax.swing.Action;

public class Main {
    public static final String ACTION_ID = "actionId";
    public static final String ACTION_NAME_POSTFIX = ".text";
    public static final String ACTION_SHORT_DESCRIPTION_POSTFIX = ".shortDescription";
    public static final String ACTION_SMALL_ICON_POSTFIX = ".smallIcon";
    public static final String ACTION_SMALL_LARGE_POSTFIX = ".largeIcon";

    /**
     * Sets action values according to values specified by resource bundle.
     *
     * @param action modified action
     * @param bundle source bundle
     * @param actionId action identifier and bundle key prefix
     */
    public static void setupAction(Action action, ResourceBundle bundle,
            String actionId) {
        action.putValue(Action.NAME,
                bundle.getString(actionId + ACTION_NAME_POSTFIX));
        action.putValue(ACTION_ID, actionId);

        // TODO keystroke from string with meta mask translation
        if (bundle.containsKey(actionId + ACTION_SHORT_DESCRIPTION_POSTFIX)) {
            action.putValue(
                    Action.SHORT_DESCRIPTION,
                    bundle.getString(actionId
                            + ACTION_SHORT_DESCRIPTION_POSTFIX));
        }
        if (bundle.containsKey(actionId + ACTION_SMALL_ICON_POSTFIX)) {
            action.putValue(
                    Action.SMALL_ICON,
                    new javax.swing.ImageIcon(action.getClass()
                            .getResource(
                                    bundle.getString(actionId
                                            + ACTION_SMALL_ICON_POSTFIX))));
        }
        if (bundle.containsKey(actionId + ACTION_SMALL_LARGE_POSTFIX)) {
            action.putValue(
                    Action.LARGE_ICON_KEY,
                    new javax.swing.ImageIcon(action.getClass()
                            .getResource(
                                    bundle.getString(actionId
                                            + ACTION_SMALL_LARGE_POSTFIX))));
        }
    }
}

Related

  1. setDefaultOkCancelKeyStrokes(final JRootPane rootPane, final Action okAction, final Action cancelAction)
  2. setEscapeKeyboardAction(final Window window, JComponent pane)
  3. setKeyEvent(JComponent widget, int keyEvent, Runnable action)
  4. setMnemonic(Action action)
  5. setTabFocusTraversalKeys(final JComponent component)
  6. setUseStandardFocusTraversalKeys(Component comp, boolean use)
  7. simulateEnterKey(Component c)
  8. simulateEnterKeyPressed(final Component component, final int delayInMilliseconds)
  9. simulateKeyStrokes(Component comp, String text)