예제 #1
0
  private ActionMap createDefaultActions() {
    ActionMapUIResource am = new ActionMapUIResource();
    Action action = new ToolBarAction();

    am.put("navigateLeft", action);
    am.put("navigateRight", action);
    am.put("navigateUp", action);
    am.put("navigateDown", action);

    return am;
  }
  /*
   * Create a new instance of ActionMap.
   */
  private ActionMap createActionMap(final JRootPane root) {
    ActionMapUIResource actionMap = new ActionMapUIResource();

    actionMap.put("press", new DefaultButtonAction(root, true));
    actionMap.put("release", new DefaultButtonAction(root, false));
    actionMap.put(
        "postPopup",
        new AbstractAction() {
          public void actionPerformed(final ActionEvent e) {
            JComponent focusOwner = getFocusOwner();
            JPopupMenu menu = focusOwner.getComponentPopupMenu();
            if (menu == null) {
              return;
            }
            Point location = focusOwner.getPopupLocation(null);
            if (location == null) {
              location = Utilities.getMousePointerScreenLocation();
              SwingUtilities.convertPointFromScreen(location, focusOwner);
            }

            menu.show(focusOwner, location.x, location.y);
          }

          public boolean isEnabled() {
            JComponent focusOwner = getFocusOwner();
            return focusOwner != null && focusOwner.getComponentPopupMenu() != null;
          }

          private JComponent getFocusOwner() {
            Component focusOwner =
                KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
            return focusOwner instanceof JComponent ? (JComponent) focusOwner : null;
          }
        });

    return actionMap;
  }
예제 #3
0
 @Override
 public void clear() {
   loadIfNecessary();
   super.clear();
 }
예제 #4
0
 @Override
 public void remove(Object key) {
   loadIfNecessary();
   super.remove(key);
 }
예제 #5
0
 @Override
 public void put(Object key, Action action) {
   loadIfNecessary();
   super.put(key, action);
 }
예제 #6
0
 @Override
 public void setParent(ActionMap map) {
   loadIfNecessary();
   super.setParent(map);
 }