Пример #1
2
  public MainPanel() {
    super(new BorderLayout());

    InputMap im = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    KeyStroke stab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK);
    KeyStroke senter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK);
    im.put(tab, im.get(enter));
    im.put(stab, im.get(senter));

    final Color orgColor = table.getSelectionBackground();
    final Color tflColor = this.getBackground();
    table.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            table.setSelectionForeground(Color.WHITE);
            table.setSelectionBackground(orgColor);
          }

          @Override
          public void focusLost(FocusEvent e) {
            table.setSelectionForeground(Color.BLACK);
            table.setSelectionBackground(tflColor);
          }
        });

    table.setComponentPopupMenu(new TablePopupMenu());
    add(new JScrollPane(table));
    setPreferredSize(new Dimension(320, 240));
  }
Пример #2
1
  public DialogPanel(boolean canok, boolean cancancel) {
    super(new GridBagLayout());
    actions = new LinkedHashMap<String, Action>();
    keystrokes = new HashMap<KeyStroke, String>();

    if (canok) {
      addButton(
          "ok",
          UIManager.getString("OptionPane.okButtonText"),
          KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              acceptDialog();
            }
          });
      keystrokes.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), "ok");
    }

    if (cancancel) {
      addButton(
          "cancel",
          UIManager.getString("OptionPane.cancelButtonText"),
          KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              cancelDialog();
            }
          });
      keystrokes.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, InputEvent.CTRL_MASK), "cancel");
    }
  }
Пример #3
0
  /**
   * Return a list of actions to adjust the size of the snap grid. Current values are 4, 8, 16, and
   * 32.
   *
   * @return List of Actions which adjust the size of the snap grid
   */
  static List<Action> createAdjustSnapActions() {
    List<Action> result = new ArrayList<Action>();
    Action a;
    String name;

    name = Translator.localize("menu.item.snap-4");
    a = new ActionAdjustSnap(4, name);
    a.putValue("ID", "4");
    a.putValue("shortcut", KeyStroke.getKeyStroke(KeyEvent.VK_1, Event.ALT_MASK + Event.CTRL_MASK));
    result.add(a);

    name = Translator.localize("menu.item.snap-8");
    a = new ActionAdjustSnap(8, name);
    a.putValue("ID", "8"); /* This ID is used as DEFAULT_ID ! */
    a.putValue("shortcut", KeyStroke.getKeyStroke(KeyEvent.VK_2, Event.ALT_MASK + Event.CTRL_MASK));
    result.add(a);

    name = Translator.localize("menu.item.snap-16");
    a = new ActionAdjustSnap(16, name);
    a.putValue("ID", "16");
    a.putValue("shortcut", KeyStroke.getKeyStroke(KeyEvent.VK_3, Event.ALT_MASK + Event.CTRL_MASK));
    result.add(a);

    name = Translator.localize("menu.item.snap-32");
    a = new ActionAdjustSnap(32, name);
    a.putValue("ID", "32");
    a.putValue("shortcut", KeyStroke.getKeyStroke(KeyEvent.VK_4, Event.ALT_MASK + Event.CTRL_MASK));
    result.add(a);

    return result;
  }
 public KeyStroke[] getStopEvents() {
   return new KeyStroke[] {
     KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0),
     KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.SHIFT_DOWN_MASK),
     KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.CTRL_DOWN_MASK)
   };
 }
  private void removeDefaultKeys() {
    InputMap mainMap = SwingUtilities.getUIInputMap(this, JComponent.WHEN_FOCUSED);

    mainMap.remove(KeyStroke.getKeyStroke("ctrl C"));
    mainMap.remove(KeyStroke.getKeyStroke("ctrl X"));
    mainMap.remove(KeyStroke.getKeyStroke("ctrl V"));
  }
Пример #6
0
  private void installShortcuts() {
    Action toggleRequest =
        new AbstractAction() {
          /** */
          private static final long serialVersionUID = -9087215230742742495L;

          public void actionPerformed(ActionEvent e) {
            System.out.println("Toggle request");
            interceptRequestCheckBox.doClick();
          }
        };
    KeyStroke toggleRequestKey =
        KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK | Event.ALT_MASK);
    SwingUtilities.getRootPane(this)
        .registerKeyboardAction(
            toggleRequest, "TOGGLEREQUEST", toggleRequestKey, WHEN_IN_FOCUSED_WINDOW);

    Action toggleResponse =
        new AbstractAction() {
          /** */
          private static final long serialVersionUID = 6167233061339024122L;

          public void actionPerformed(ActionEvent e) {
            System.out.println("Toggle response");
            interceptResponseCheckBox.doClick();
          }
        };
    KeyStroke toggleResponseKey =
        KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK | Event.ALT_MASK);
    SwingUtilities.getRootPane(this)
        .registerKeyboardAction(
            toggleResponse, "TOGGLERESPONSE", toggleResponseKey, WHEN_IN_FOCUSED_WINDOW);
  }
  private void setPointButtonAction() {
    JButton button = calculator.getButtonPoint();
    Action action =
        new AbstractAction("colonAction") {
          @Override
          public void actionPerformed(ActionEvent e) {
            appendTextInCalculatorDisplay(".");
          }
        };

    // Shortcut al punto normal
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, 0));
    button.getActionMap().put("colonAction", action);
    button
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "colonAction");

    // Shortcut al punto del numpad
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DECIMAL, 0));
    button.getActionMap().put("colonAction", action);
    button
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "colonAction");

    button.addActionListener(action);
  }
  private void setMinusButtonAction() {
    JButton button = calculator.getButtonMinus();
    Action action =
        new AbstractAction("buttonMinusAction") {
          @Override
          public void actionPerformed(ActionEvent e) {
            appendTextInCalculatorDisplay("-");
          }
        };

    // Shortcut al menos del numpad
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0));
    button.getActionMap().put("buttonMinusAction", action);
    button
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "buttonMinusAction");

    // Shortcut al guion alto
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0));
    button.getActionMap().put("buttonMinusAction", action);
    button
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "buttonMinusAction");
    button.addActionListener(action);
  }
  private void setButtonAction(JButton button, final String key) {

    Action action =
        new AbstractAction("button" + key + "Action") {
          @Override
          public void actionPerformed(ActionEvent e) {
            appendTextInCalculatorDisplay(key.toLowerCase());
          }
        };

    // Shortcuts a los numeros comunes
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(key));
    button.getActionMap().put("button" + key + "Action", action);
    button
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "button" + key + "Action");

    // Shortcuts a los del numpad
    if (getNumpadVk(key) != null) {
      action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(getNumpadVk(key), 0));
      button.getActionMap().put("button" + key + "Action", action);
      button
          .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
          .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), "button" + key + "Action");
    }

    button.addActionListener(action);
  }
Пример #10
0
  public ImagePanel(Kdu_coords viewSize) throws KduException {
    int width = Math.min(viewSize.Get_x(), 1600);
    int height = Math.min(viewSize.Get_y(), 1200);

    setPreferredSize(new Dimension(width, height));

    getInputMap().put(KeyStroke.getKeyStroke("UP"), "pressedUpArrow");
    getActionMap()
        .put(
            "pressedUpArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
    getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "pressedDownArrow");
    getActionMap()
        .put(
            "pressedDownArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
  }
Пример #11
0
  private void createFileMenu() {
    JMenu fileMenu = new JMenu("File");

    openMenuItem = new JMenuItem("Open...");
    openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

    saveMenuItem = new JMenuItem("Save");
    saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));

    exitMenuItem = new JMenuItem("Exit");

    JMenu newMenu = new JMenu("New");

    buyMenuItem = new JMenuItem("Buy...");
    buyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK));

    sellMenuItem = new JMenuItem("Sell...");
    sellMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));

    newMenu.add(buyMenuItem);
    newMenu.add(sellMenuItem);

    fileMenu.add(newMenu);
    fileMenu.add(openMenuItem);
    fileMenu.add(saveMenuItem);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitMenuItem);

    add(fileMenu);
  }
Пример #12
0
  private void initWizard(final String title) {
    setTitle(title);
    myCurrentStep = 0;
    myPreviousButton = new JButton(IdeBundle.message("button.wizard.previous"));
    myNextButton = new JButton(IdeBundle.message("button.wizard.next"));
    myCancelButton = new JButton(CommonBundle.getCancelButtonText());
    myHelpButton = new JButton(CommonBundle.getHelpButtonText());
    myContentPanel = new JPanel(new CardLayout());

    myIcon = new TallImageComponent(null);

    JRootPane rootPane = getRootPane();
    if (rootPane != null) { // it will be null in headless mode, i.e. tests
      rootPane.registerKeyboardAction(
          new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
              helpAction();
            }
          },
          KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0),
          JComponent.WHEN_IN_FOCUSED_WINDOW);

      rootPane.registerKeyboardAction(
          new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
              helpAction();
            }
          },
          KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0),
          JComponent.WHEN_IN_FOCUSED_WINDOW);
    }
  }
Пример #13
0
  /** ******************************************************************* */
  protected HelpMenu() {
    super("Help");

    setMnemonic('H');

    Icon icon;
    JMenuItem menuItem;

    //
    // Online Help menu item
    //
    icon = UIManager.getIcon("help");
    menuItem = new JMenuItem("Online Help", icon);
    menuItem.addActionListener(new HelpActionListener());
    menuItem.setMnemonic('H');
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
    add(menuItem);

    //
    // Separator
    //
    add(new JSeparator());

    //
    // About menu item
    //
    menuItem = new JMenuItem("About...");
    menuItem.addActionListener(new AboutActionListener());
    menuItem.setMnemonic('A');
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK));
    add(menuItem);
  }
  private ActionToolbar createToolbar() {
    DefaultActionGroup group = new DefaultActionGroup();

    BackAction back = new BackAction();
    back.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), this);
    group.add(back);

    ForwardAction forward = new ForwardAction();
    forward.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), this);
    group.add(forward);

    EditSourceActionBase edit = new EditSourceAction();
    edit.registerCustomShortcutSet(
        new CompositeShortcutSet(CommonShortcuts.getEditSource(), CommonShortcuts.ENTER), this);
    group.add(edit);

    edit = new ShowSourceAction();
    edit.registerCustomShortcutSet(
        new CompositeShortcutSet(CommonShortcuts.getViewSource(), CommonShortcuts.CTRL_ENTER),
        this);
    group.add(edit);

    return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
  }
Пример #15
0
  private void tastenbelegen() {
    javax.swing.ActionMap am = getRootPane().getActionMap();
    javax.swing.InputMap im =
        getRootPane().getInputMap(javax.swing.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // ESC - Taste
    Object EscapeObjekt = new Object();
    javax.swing.KeyStroke EscapeStroke =
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0);
    javax.swing.Action EscapeAction =
        new javax.swing.AbstractAction() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            antwort = false; // Befehl
            setVisible(false);
          }
        };
    im.put(EscapeStroke, EscapeObjekt);
    am.put(EscapeObjekt, EscapeAction);

    // ENTER - Taste
    Object EnterObjekt = new Object();
    javax.swing.KeyStroke EnterStroke =
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0);
    javax.swing.Action EnterAction =
        new javax.swing.AbstractAction() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            antwort = true; // Befehl
            setVisible(false);
          }
        };
    im.put(EnterStroke, EnterObjekt);
    am.put(EnterObjekt, EnterAction);
  }
Пример #16
0
  public static void hideOnEscape(Object ob) {
    if (ob instanceof JComponent) {
      final JComponent comp = (JComponent) ob;
      InputMap inputMap = comp.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap actionMap = comp.getRootPane().getActionMap();

      inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), actionMap);
      actionMap.put(
          actionMap,
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              comp.setVisible(false);
            }
          });
    } else if (ob instanceof JDialog) {
      final JDialog dialog = (JDialog) ob;
      InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      ActionMap actionMap = dialog.getRootPane().getActionMap();

      inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), actionMap);
      actionMap.put(
          actionMap,
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              dialog.dispose();
            }
          });
    }
  }
Пример #17
0
  private void AboutBoxKeyEventActionIntialization() {
    Action ESCactionListener =
        new AbstractAction() {
          public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
            dispose();
          }
        };
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    JComponent comp = this.getRootPane();
    comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ESCAPE");
    ActionMap actionMap = comp.getActionMap();
    actionMap.put("ESCAPE", ESCactionListener);

    /* OK button Action Solves MAC , Linux and Window enter key issue*/
    Action OKactionListener =
        new AbstractAction() {
          public void actionPerformed(ActionEvent actionEvent) {
            btnOKActionPerformed(actionEvent);
          }
        };

    KeyStroke enter_ok = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
    btnOK.getInputMap(JButton.WHEN_FOCUSED).put(enter_ok, "OK");
    actionMap = btnOK.getActionMap();
    actionMap.put("OK", OKactionListener);
    btnOK.setActionMap(actionMap);
  }
Пример #18
0
  /*
   * Assign ENTER and ESCAPE keystrokes to be equivalent to OK and Cancel buttons, respectively.
   */
  @SuppressWarnings("serial")
  protected void setupKeys() {
    // Get the InputMap and ActionMap of the RootPane of this JDialog.
    JRootPane rootPane = this.getRootPane();
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = rootPane.getActionMap();

    // Setup ENTER key.
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
    actionMap.put(
        "enter",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            okChosen();
          }
        });

    // Setup ESCAPE key.
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
    actionMap.put(
        "escape",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            cancelChosen();
          }
        });

    // Stop table_ from consuming the ENTER keystroke and preventing it from being received by this
    // (JDialog).
    table_
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "none");
  }
Пример #19
0
 private void initKeyMap() {
   InputMap map = this.getInputMap();
   int shift = InputEvent.SHIFT_MASK;
   int ctrl = InputEvent.CTRL_MASK;
   map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, shift), SikuliEditorKit.deIndentAction);
   map.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, ctrl), SikuliEditorKit.deIndentAction);
 }
Пример #20
0
  public Input() {

    this.map = new boolean[256];

    for (int i = 0; i < map.length; i++) {

      final int KEY_CODE = i;

      this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
          .put(KeyStroke.getKeyStroke(i, 0, false), i * 2);
      this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
          .put(KeyStroke.getKeyStroke(i, 0, true), i * 2 + 1);

      this.getActionMap()
          .put(
              i * 2,
              new AbstractAction() {
                public void actionPerformed(ActionEvent actionEvent) {
                  Input.this.map[KEY_CODE] = true;
                }
              });

      this.getActionMap()
          .put(
              i * 2 + 1,
              new AbstractAction() {
                public void actionPerformed(ActionEvent actionEvent) {
                  Input.this.map[KEY_CODE] = false;
                }
              });
    }
  }
Пример #21
0
  public void setActionItem(GUIAction aAction) {
    mAction = aAction;
    this.setText(mAction.getTitle());
    if (mAction.getMnemonic() != 0) this.setMnemonic(mAction.getMnemonic());

    setImage(mAction.getIcon());
    if (mAction.getIcon() != null)
      this.setIcon((ImageIcon) mAction.getIcon().resizeIcon(24, true).getData());
    else this.setIcon(null);
    KeyStroke key = KeyStroke.getKeyStroke(mAction.getKeyStroke());
    if (key != null) {
      int key_code = key.getKeyCode();
      int modifier = key.getModifiers();
      int new_modifier = 0;
      if ((modifier & java.awt.event.InputEvent.ALT_MASK) == java.awt.event.InputEvent.ALT_MASK)
        new_modifier += java.awt.event.InputEvent.ALT_MASK;
      if ((modifier & java.awt.event.InputEvent.SHIFT_MASK) == java.awt.event.InputEvent.SHIFT_MASK)
        new_modifier += java.awt.event.InputEvent.SHIFT_MASK;
      if ((modifier & java.awt.event.InputEvent.CTRL_MASK) == java.awt.event.InputEvent.CTRL_MASK)
        new_modifier += getControlKey();
      this.setAccelerator(KeyStroke.getKeyStroke(key_code, new_modifier));
    }
    this.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mAction.actionPerformed();
          }
        });
  }
Пример #22
0
  /** Create the terminal's menubar, all menus and items. */
  private JMenuBar makeMenuBar() {
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu(Config.getString("terminal.options"));
    JMenuItem item;
    item = menu.add(new ClearAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, SHORTCUT_MASK));
    item = menu.add(getCopyAction());
    item.setText(Config.getString("terminal.copy"));
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, SHORTCUT_MASK));
    item = menu.add(new SaveAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, SHORTCUT_MASK));
    menu.add(new PrintAction());
    menu.add(new JSeparator());

    autoClear = new JCheckBoxMenuItem(new AutoClearAction());
    autoClear.setSelected(clearOnMethodCall);
    menu.add(autoClear);

    recordCalls = new JCheckBoxMenuItem(new RecordCallAction());
    recordCalls.setSelected(recordMethodCalls);
    menu.add(recordCalls);

    unlimitedBuffering = new JCheckBoxMenuItem(new BufferAction());
    unlimitedBuffering.setSelected(unlimitedBufferingCall);
    menu.add(unlimitedBuffering);

    menu.add(new JSeparator());
    item = menu.add(new CloseAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, SHORTCUT_MASK));

    menubar.add(menu);
    return menubar;
  }
  public static void addActions(JComponent thePanel, IntActionReceiver theTarget) {
    javax.swing.Action goLeft = new SimpleIntAction("Left", 1, theTarget);
    javax.swing.Action goRight = new SimpleIntAction("Right", 0, theTarget);
    javax.swing.Action goDown = new SimpleIntAction("Down", 2, theTarget);
    javax.swing.Action goUp = new SimpleIntAction("Up", 3, theTarget);

    thePanel
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "goLeft");
    thePanel.getActionMap().put("goLeft", goLeft);
    thePanel
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "goRight");
    thePanel.getActionMap().put("goRight", goRight);
    thePanel
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "goDown");
    thePanel.getActionMap().put("goDown", goDown);
    thePanel
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "goUp");
    thePanel.getActionMap().put("goUp", goUp);

    thePanel.add(new JButton(goLeft));
    thePanel.add(new JButton(goRight));
    thePanel.add(new JButton(goUp));
    thePanel.add(new JButton(goDown));
  }
Пример #24
0
  /**
   * A helper for creating and updating key bindings for components with mnemonics. The {@code
   * pressed} action will be invoked when the mnemonic is activated and the {@code released} action
   * will be invoked when the mnemonic is deactivated.
   *
   * <p>TODO establish an interface for the mnemonic properties, such as {@code MnemonicEnabled} and
   * change signature to {@code public static <T extends JComponent & MnemonicEnabled> void
   * updateMnemonicBinding(T c, String pressed, String released)}
   *
   * @param c the component bindings to update
   * @param pressed the name of the action in the action map to invoke when the mnemonic is pressed
   * @param released the name of the action in the action map to invoke when the mnemonic is
   *     released (if the action is a toggle style, then this parameter should be {@code null})
   * @throws NullPointerException if the component is {@code null}
   */
  public static void updateMnemonicBinding(JComponent c, String pressed, String released) {
    Class<?> clazz = c.getClass();
    int m = -1;

    try {
      Method mtd = clazz.getMethod("getMnemonic");
      m = (Integer) mtd.invoke(c);
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new IllegalArgumentException("unable to access mnemonic", e);
    }

    InputMap map = SwingUtilities.getUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW);

    if (m != 0) {
      if (map == null) {
        map = new ComponentInputMapUIResource(c);
        SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
      }

      map.clear();

      // TODO is ALT_MASK right for all platforms?
      map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, false), pressed);
      map.put(KeyStroke.getKeyStroke(m, InputEvent.ALT_MASK, true), released);
      map.put(KeyStroke.getKeyStroke(m, 0, true), released);
    } else {
      if (map != null) {
        map.clear();
      }
    }
  }
Пример #25
0
  /**
   * Creates and initializes items in the file menu.
   *
   * @return the new "File" menu.
   */
  @Override
  protected JMenu createFileMenu() {
    JMenu fileMenu = new JMenu("File");
    JMenuItem open = new JMenuItem("Open");
    fileMenu.add(open);
    open.setAccelerator(KeyStroke.getKeyStroke("control O"));
    open.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doOpen();
          }
        });

    JMenuItem save = new JMenuItem("Save");
    save.setAccelerator(KeyStroke.getKeyStroke("control S"));
    fileMenu.add(save);
    save.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doSave();
          }
        });

    JMenuItem exit = new JMenuItem("Exit");
    fileMenu.add(exit);
    exit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    return fileMenu;
  }
Пример #26
0
  public ActionFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    buttonPanel = new JPanel();

    // define actions
    Action yellowAction = new ColorAction("Yellow", new ImagIcon("yellow-ball.gif"), Color.YELLOW);
    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED);

    // add buttons for these actions
    buttonPanel.add(new JButton(yellowAction));
    buttonPanel.add(new JButton(blueAction));
    buttonPanel.add(new JButton(recAction));

    // add panel to frame
    add(buttonPanel);

    // associate the Y, B, and R keys with names
    InputMap imap = buttonPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow");
    imap.put(KeyStroke.getKeyStroke("Ctrl B"), "panel.blue");
    imap.put(KeyStroke.getKeyStroke("ctrl R"), "panel.red");

    // associate the names with actions
    ActionMap amap = buttonPanel.getActionMap();
    amap.put("panel.yellow", yellowAction);
    amap.put("panel.blue", blueAction);
    amap.put("panel.red", redAction);
  }
Пример #27
0
  private class Listener implements ActionListener, KeyListener {

    private KeyStroke backspaceKS = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
    private KeyStroke tabKS = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

    private String key = "";

    public void keyTyped(KeyEvent e) {
      e.consume();
    }

    public void keyPressed(KeyEvent e) {
      KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());

      boolean add =
          e.getKeyCode() != e.VK_SHIFT
              && e.getKeyCode() != e.VK_CONTROL
              && e.getKeyCode() != e.VK_ALT
              && e.getKeyCode() != e.VK_META
              && e.getKeyCode() != e.VK_ALT_GRAPH;

      if (keyStroke.equals(backspaceKS) && !key.equals("")) {
        // delete last key
        int i = key.lastIndexOf(' ');
        if (i < 0) key = "";
        else key = key.substring(0, i);
        tfShortcut.setText(key);
      } else
        // add key
        addKeyStroke(keyStroke, add);

      e.consume();
    }

    public void keyReleased(KeyEvent e) {
      e.consume();
    }

    public void actionPerformed(ActionEvent e) {
      if (e.getSource() == bClear) {
        key = "";
        tfShortcut.setText(key);
        tfShortcut.requestFocusInWindow();
      } else if (e.getSource() == bTab) {
        addKeyStroke(tabKS, true);
        tfShortcut.requestFocusInWindow();
      }
    }

    private void addKeyStroke(KeyStroke keyStroke, boolean add) {
      String k = WizardUtils.keyStrokeToString(keyStroke);
      if (key.equals("")) {
        tfShortcut.setText(k);
        if (add) key = k;
      } else {
        tfShortcut.setText(key + " " + k);
        if (add) key += " " + k;
      }
    }
  }
Пример #28
0
  public OkCancelDialog(
      final UIEventsExecutor executor,
      final ActionPane pane,
      final String title,
      final JFrame mainScreen) {
    super(mainScreen);
    this.executor = executor;
    SwingUtils.makeLocationrelativeToParent(this, mainScreen);
    this.setTitle(title);

    final JPanel panel = pane.getPanel();
    if (panel == null) {
      throw new IllegalStateException("panel must not be null");
    }

    this.setLayout(new BorderLayout());
    this.add(panel, BorderLayout.CENTER);
    this.add(
        new BinaryButtonBar(
            new Runnable() {
              @Override
              public void run() {
                doAction(pane);
              }
            },
            new Runnable() {
              @Override
              public void run() {
                OkCancelDialog.this.setVisible(false);
              }
            },
            "ok",
            "cancel"),
        BorderLayout.SOUTH);

    this.getRootPane()
        .registerKeyboardAction(
            new ActionListener() {
              @Override
              public void actionPerformed(final ActionEvent e) {
                OkCancelDialog.this.setVisible(false);
              }
            },
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    this.getRootPane()
        .registerKeyboardAction(
            new ActionListener() {
              @Override
              public void actionPerformed(final ActionEvent e) {
                doAction(pane);
              }
            },
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    this.pack();
  }
Пример #29
0
 @Override
 public KeyStroke[] getClearBufferKeyStrokes() {
   return new KeyStroke[] {
     UIUtil.isMac
         ? KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.META_DOWN_MASK)
         : KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_DOWN_MASK)
   };
 }
Пример #30
0
  private void initMenu() {

    menuBar = new JMenuBar();
    frmVisualizadord.setJMenuBar(menuBar);

    mnArchivo = new JMenu("Archivo");
    menuBar.add(mnArchivo);

    mntmCargarArchivo = new JMenuItem("Cargar Archivo");
    mntmCargarArchivo.setIcon(new ImageIcon(Visualizador3D.class.getResource("/icon/open.png")));
    mntmCargarArchivo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    mntmCargarArchivo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            abrirArchivo();
          }
        });
    mnArchivo.add(mntmCargarArchivo);

    mntmGuardarComo = new JMenuItem("Guardar Como");
    mntmGuardarComo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            guardarImagenComo();
          }
        });
    mntmGuardarComo.setIcon(new ImageIcon(Visualizador3D.class.getResource("/icon/save.png")));
    mntmGuardarComo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    mnArchivo.add(mntmGuardarComo);

    separator = new JSeparator();
    mnArchivo.add(separator);

    mntmSalir = new JMenuItem("Salir");
    mntmSalir.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            frmVisualizadord.dispose();
          }
        });
    mntmSalir.setIcon(new ImageIcon(Visualizador3D.class.getResource("/icon/close.png")));
    mntmSalir.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
    mnArchivo.add(mntmSalir);

    mnAyuda = new JMenu("Ayuda");
    menuBar.add(mnAyuda);

    mntmAcercaDe = new JMenuItem("Acerca De");
    mntmAcercaDe.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            AcercaDe acercaDe = new AcercaDe();
            acercaDe.setVisible(true);
          }
        });
    mntmAcercaDe.setIcon(new ImageIcon(Visualizador3D.class.getResource("/icon/about.png")));
    mnAyuda.add(mntmAcercaDe);
  }