javax.swing.JComponent#getActionMap ( )源码实例Demo

下面列出了javax.swing.JComponent#getActionMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jclic   文件: Actions.java
public static void mapAction(JComponent jc, Map<String, Object[]> actionKeys, Action act, String key) {
  if (actionKeys == null) {
    actionKeys = getActionKeys(jc);
  }
  if (jc != null && actionKeys != null) {
    ActionMap am = jc.getActionMap();
    Object[] keys = actionKeys.get(key);
    boolean replaced = false;
    if (keys != null) {
      for (Object k : keys) {
        am.put(k, act);
        if (k.equals(key)) {
          replaced = true;
        }
      }
    }
    if (!replaced) {
      am.put(key, act);
    }
  }
}
 
源代码2 项目: netbeans   文件: ToolTipManagerEx.java
/**
    * Registers a component for tooltip management.
    * <p>
    * This will register key bindings to show and hide the tooltip text
    * only if <code>component</code> has focus bindings. This is done
    * so that components that are not normally focus traversable, such
    * as <code>JLabel</code>, are not made focus traversable as a result
    * of invoking this method.
    *
    * @param component  a <code>JComponent</code> object to add
    * @see JComponent#isFocusTraversable
    */
   protected void registerComponent(JComponent component) {
       component.removeMouseListener(this);
       component.addMouseListener(this);
       component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    // register our accessibility keybindings for this component
    // this will apply globally across L&F
    // Post Tip: Ctrl+F1
    // Unpost Tip: Esc and Ctrl+F1
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
源代码3 项目: jclic   文件: Actions.java
/**
 * Collects the keys of all the actions linked to a specific
 * {@link javax.swing.JComponent} and groups them in arrays by action names.
 *
 * @param jc The JComponent with the actions linked to.
 * @return A HashMap formed by pairs of action names (key) and arrays of action
 *         keys (value). Usually each action name has only one action key
 *         associated to it, and the value of the pair is an object array with
 *         only one string, but this is not an imperative: several actions can
 *         be associated to a single name.
 */
public static Map<String, Object[]> getActionKeys(JComponent jc) {
  Map<String, Object[]> result = new HashMap<String, Object[]>();
  ActionMap am = jc.getActionMap();
  for (Object amk : am.allKeys()) {
    Action act = am.get(amk);
    Object o = act.getValue(Action.NAME);
    if (o == null)
      o = "";
    String name = o.toString();
    Object[] keys = result.get(name);
    if (keys == null)
      keys = new Object[] { amk };
    else {
      Object[] k2 = new Object[keys.length + 1];
      int j;
      for (j = 0; j < keys.length; j++)
        k2[j] = keys[j];
      k2[j] = amk;
      keys = k2;
    }
    result.put(name, keys);
  }
  return result;
}
 
源代码4 项目: jdk8u-dev-jdk   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码5 项目: TencentKona-8   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码6 项目: openjdk-8   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码7 项目: openjdk-jdk8u   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码8 项目: netbeans   文件: ToolTipManagerEx.java
/**
    * Removes a component from tooltip control.
    *
    * @param component  a <code>JComponent</code> object to remove
    */
   protected void unregisterComponent(JComponent component) {
       component.removeMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
源代码9 项目: netbeans-mmd-plugin   文件: MMDGraphEditor.java
private void registerCustomCCPActions(@Nonnull final JComponent component) {
  final ActionMap actionMap = component.getActionMap();
  actionMap.put(DefaultEditorKit.cutAction, this.actionCut);
  actionMap.put(DefaultEditorKit.copyAction, this.actionCopy);
  actionMap.put(DefaultEditorKit.pasteAction, this.actionPaste);
  actionMap.put(FindAction.class.getName(), findAction);
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码11 项目: Bytecoder   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码12 项目: openjdk-jdk9   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码13 项目: jdk8u-jdk   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码14 项目: pgptool   文件: JCheckList.java
private void addSpaceActionhandler(JComponent host) {
	InputMap inputMap = host.getInputMap();
	ActionMap actionMap = host.getActionMap();
	KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
	String key = keyStroke.toString();
	inputMap.put(keyStroke, key);
	actionMap.put(key, invertCheckAction);
}
 
源代码15 项目: audiveris   文件: ScrollView.java
private void bindKeys (JComponent component)
{
    InputMap inputMap;
    //        inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    //        inputMap = component.getInputMap(JComponent.WHEN_FOCUSED); // Default
    inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    ActionMap actionMap = component.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke("UP"), "UpAction");
    actionMap.put("UpAction", new UpAction());

    inputMap.put(KeyStroke.getKeyStroke("DOWN"), "DownAction");
    actionMap.put("DownAction", new DownAction());

    inputMap.put(KeyStroke.getKeyStroke("shift UP"), "ShiftUpAction");
    actionMap.put("ShiftUpAction", new ShiftUpAction());

    inputMap.put(KeyStroke.getKeyStroke("shift DOWN"), "ShiftDownAction");
    actionMap.put("ShiftDownAction", new ShiftDownAction());

    inputMap.put(KeyStroke.getKeyStroke("LEFT"), "LeftAction");
    actionMap.put("LeftAction", new LeftAction());

    inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "RightAction");
    actionMap.put("RightAction", new RightAction());

    inputMap.put(KeyStroke.getKeyStroke("shift LEFT"), "ShiftLeftAction");
    actionMap.put("ShiftLeftAction", new ShiftLeftAction());

    inputMap.put(KeyStroke.getKeyStroke("shift RIGHT"), "ShiftRightAction");
    actionMap.put("ShiftRightAction", new ShiftRightAction());
}
 
源代码16 项目: jdk8u_jdk   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码17 项目: Java8CN   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码18 项目: hottub   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码19 项目: openjdk-8-source   文件: BasicLookAndFeel.java
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
源代码20 项目: pentaho-reporting   文件: WelcomePane.java
private void init( final ReportDesignerContext reportDesignerContext ) {
  if ( reportDesignerContext == null ) {
    throw new NullPointerException();
  }

  setTitle( Messages.getString( "WelcomePane.title" ) ); // NON-NLS
  this.reportDesignerContext = reportDesignerContext;

  this.newReportAction = new NewReportAction();
  this.newReportAction.setReportDesignerContext( reportDesignerContext );

  this.closeActionListener = new CloseActionListener();

  showOnStartupCheckbox = new JCheckBox(
    Messages.getString( "WelcomePane.showAtStartup" ), WorkspaceSettings.getInstance().isShowLauncher() ); // NON-NLS
  showOnStartupCheckbox.addActionListener( new TriggerShowWelcomePaneAction() );

  backgroundImage = Toolkit.getDefaultToolkit().createImage(
    IconLoader.class.getResource( "/org/pentaho/reporting/designer/core/icons/WelcomeBackground.png" ) ); // NON-NLS

  final WaitingImageObserver obs = new WaitingImageObserver( backgroundImage );
  obs.waitImageLoaded();

  setResizable( false );

  initGUI();

  pack();


  final JComponent contentPane = (JComponent) getContentPane();
  final InputMap inputMap = contentPane.getInputMap();
  final ActionMap actionMap = contentPane.getActionMap();

  inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "cancel" ); // NON-NLS
  actionMap.put( "cancel", new CloseActionListener() ); // NON-NLS

}