Example #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));
  }
  public void loadBindingMap(InputMap im, ActionMap am) {
    results.append("Bound Actions\n");
    String unboundActions = "";
    String unboundInputKeys = "";
    Hashtable mi = buildReverseMap(im);
    Object[] k = am.allKeys();
    if (k != null) {
      for (int i = 0; i < k.length; i++) {
        if (mi.containsKey(k[i])) {
          results.append("  " + getActionName(k[i]));
          results.append(";" + mi.get(k[i]) + "\n");
        } else {
          unboundActions += ("  " + getActionName(k[i]) + "\n");
        }
      }
      results.append("\nUnbound Actions\n\n");
      results.append(unboundActions);
    }

    results.append("\nUnbound InputMap Entries\n");
    k = im.allKeys();
    if (k != null) {
      for (int i = 0; i < k.length; i++) {
        KeyStroke key = (KeyStroke) k[i];
        Object actionKey = im.get(key);
        if (am.get(actionKey) == null) {
          results.append("  " + im.get((KeyStroke) k[i]) + ": " + k[i] + "\n");
        }
      }
    }
  }
Example #3
0
 // -------->
 // original code:
 // ftp://ftp.oreilly.de/pub/examples/english_examples/jswing2/code/goodies/Mapper.java
 // modified by terai
 //     private Hashtable<Object, ArrayList<KeyStroke>> buildReverseMap(InputMap im) {
 //         Hashtable<Object, ArrayList<KeyStroke>> h = new Hashtable<>();
 //         if (Objects.isNull(im.allKeys())) {
 //             return h;
 //         }
 //         for (KeyStroke ks: im.allKeys()) {
 //             Object name = im.get(ks);
 //             if (h.containsKey(name)) {
 //                 h.get(name).add(ks);
 //             } else {
 //                 ArrayList<KeyStroke> keylist = new ArrayList<>();
 //                 keylist.add(ks);
 //                 h.put(name, keylist);
 //             }
 //         }
 //         return h;
 //     }
 private void loadBindingMap(Integer focusType, InputMap im, ActionMap am) {
   if (Objects.isNull(im.allKeys())) {
     return;
   }
   ActionMap tmpAm = new ActionMap();
   for (Object actionMapKey : am.allKeys()) {
     tmpAm.put(actionMapKey, am.get(actionMapKey));
   }
   for (KeyStroke ks : im.allKeys()) {
     Object actionMapKey = im.get(ks);
     Action action = am.get(actionMapKey);
     if (Objects.isNull(action)) {
       model.addBinding(new Binding(focusType, "____" + actionMapKey.toString(), ks.toString()));
     } else {
       model.addBinding(new Binding(focusType, actionMapKey.toString(), ks.toString()));
     }
     tmpAm.remove(actionMapKey);
   }
   if (Objects.isNull(tmpAm.allKeys())) {
     return;
   }
   for (Object actionMapKey : tmpAm.allKeys()) {
     model.addBinding(new Binding(focusType, actionMapKey.toString(), ""));
   }
 }
Example #4
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);
 }
Example #5
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);
  }
 private static void installActions(JTable table) {
   InputMap inputMap = table.getInputMap(WHEN_FOCUSED);
   inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), "selectLastRow");
   inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), "selectFirstRow");
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_HOME, KeyEvent.SHIFT_DOWN_MASK),
       "selectFirstRowExtendSelection");
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_END, KeyEvent.SHIFT_DOWN_MASK),
       "selectLastRowExtendSelection");
 }
Example #7
0
 private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) {
   if (myInputMap.get(stroke) != null) {
     final Action action = myActionMap.get(myInputMap.get(stroke));
     if (action != null && action.isEnabled()) {
       action.actionPerformed(
           new ActionEvent(
               getContent(), event.getID(), "", event.getWhen(), event.getModifiers()));
       return true;
     }
   }
   return false;
 }
 public void loadInputMap(InputMap im, String indent) {
   KeyStroke[] k = im.allKeys();
   if (k == null) {
     results.append(indent + "No InputMap defined\n");
   } else {
     results.append(indent + "\nInputMap (" + k.length + " local keys)\n");
   }
   if (k != null) {
     for (int i = 0; i < k.length; i++) {
       results.append(indent + "  Key:  " + k[i] + ", binding: " + im.get(k[i]) + "\n");
     }
   }
 }
  private void initActions() {
    @NonNls InputMap inputMap = getInputMap(WHEN_FOCUSED);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), "moveFocusDown");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), "moveFocusUp");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), "collapse");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), "expand");

    @NonNls ActionMap actionMap = getActionMap();
    actionMap.put("moveFocusDown", new MoveFocusAction(true));
    actionMap.put("moveFocusUp", new MoveFocusAction(false));
    actionMap.put("collapse", new ExpandAction(false));
    actionMap.put("expand", new ExpandAction(true));
  }
  /** Enables the actions when a key is pressed, for now closes the window when esc is pressed. */
  private void enableKeyActions() {
    @SuppressWarnings("serial")
    UIAction act =
        new UIAction() {
          public void actionPerformed(ActionEvent e) {
            close(true);
          }
        };

    getRootPane().getActionMap().put("close", act);

    InputMap imap = this.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
  }
  /** Enables the actions when a key is pressed, for now closes the window when esc is pressed. */
  private void enableKeyActions() {

    UIAction act =
        new UIAction() {
          public void actionPerformed(ActionEvent e) {
            ChatRoomAuthenticationWindow.this.setVisible(false);
          }
        };

    getRootPane().getActionMap().put("close", act);

    InputMap imap = this.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
  }
Example #12
0
 protected void setActive(Component component, boolean active) {
   if (component instanceof Tile) {
     Tile tile = (Tile) component;
     if (active) {
       tile.addTiledView(_points);
       tile.addMouseListener(_ml);
       tile.addMouseWheelListener(_mwl);
       InputMap im = tile.getInputMap();
       ActionMap am = tile.getActionMap();
       im.put(KS_BACK_SPACE, "backspace");
       im.put(KS_UP, "up");
       im.put(KS_DOWN, "down");
       am.put("backspace", _bsa);
       am.put("up", _uaa);
       am.put("down", _daa);
     } else {
       tile.removeTiledView(_points);
       tile.removeMouseListener(_ml);
       tile.removeMouseWheelListener(_mwl);
       InputMap im = tile.getInputMap();
       ActionMap am = tile.getActionMap();
       im.remove(KS_BACK_SPACE);
       im.remove(KS_UP);
       im.remove(KS_DOWN);
       am.remove("backspace");
       am.remove("up");
       am.remove("down");
     }
   }
 }
Example #13
0
  private void addCancelByEscapeKey() {
    String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY";
    int noModifiers = 0;
    KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, noModifiers, false);
    InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    inputMap.put(escapeKey, CANCEL_ACTION_KEY);
    AbstractAction cancelAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            cancelButtonActionPerformed();
          }
        };

    getRootPane().getActionMap().put(CANCEL_ACTION_KEY, cancelAction);
  }
Example #14
0
  /*
   * Aqui eu sobrescrevo o comportamento do ENTER na tabela, por default ele
   * vai para a proxima linha, mas neste caso quero que pegue o valor da atual
   * para exibir o dados.
   */
  public void alteraComportamentEnterTabela() {

    tabela.setSelectionMode(0); // somente uma linha pode ser selecionada
    InputMap im = tabela.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke enter = KeyStroke.getKeyStroke("ENTER");
    im.put(enter, im.get(KeyStroke.getKeyStroke(KeyEvent.VK_GREATER, 0)));

    Action enterAction =
        new AbstractAction() {

          public void actionPerformed(ActionEvent e) {
            JTable tabela = (JTable) e.getSource();
          }
        };
    tabela.getActionMap().put(im.get(enter), enterAction);
  }
  static {
    // Set up the input map that will be shared by all instances

    inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
    inputMap.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
    inputMap.put(KeyStroke.getKeyStroke("shift LEFT"), "yearBackward");
    inputMap.put(KeyStroke.getKeyStroke("shift RIGHT"), "yearForward");
    inputMap.put(KeyStroke.getKeyStroke("LEFT"), "monthBackward");
    inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "monthForward");

    actionMap.put("setNullDate", setNullDate);
    actionMap.put("yearBackward", yearBackward);
    actionMap.put("yearForward", yearForward);
    actionMap.put("monthBackward", monthBackward);
    actionMap.put("monthForward", monthForward);
  }
Example #16
0
 public final void registerAction(
     @NonNls String aActionName,
     int aKeyCode,
     @JdkConstants.InputEventMask int aModifier,
     Action aAction) {
   myInputMap.put(KeyStroke.getKeyStroke(aKeyCode, aModifier), aActionName);
   myActionMap.put(aActionName, aAction);
 }
Example #17
0
 private Hashtable buildReverseMap(InputMap im) {
   KeyStroke k[] = im.allKeys();
   Hashtable h = new Hashtable();
   if (k != null) {
     for (int i = 0; i < k.length; i++) {
       Object nk = im.get(k[i]);
       Object cv = h.get(nk);
       if (h.containsKey(nk)) {
         ((Vector) cv).add(k[i]);
       } else {
         Vector v = new Vector();
         v.add(k[i]);
         h.put(nk, v);
       }
     }
   }
   return h;
 }
  private void updateMnemonic(int lastMnemonic, int mnemonic) {
    if (mnemonic == lastMnemonic) {
      return;
    }
    InputMap windowInputMap = SwingUtilities.getUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW);

    int mask = SystemInfo.isMac ? InputEvent.ALT_MASK | InputEvent.CTRL_MASK : InputEvent.ALT_MASK;
    if (lastMnemonic != 0 && windowInputMap != null) {
      windowInputMap.remove(KeyStroke.getKeyStroke(lastMnemonic, mask, false));
    }
    if (mnemonic != 0) {
      if (windowInputMap == null) {
        windowInputMap = new ComponentInputMapUIResource(this);
        SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
      }
      windowInputMap.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "doClick");
    }
  }
Example #19
0
  public void alteraComportamentoEnterTabela() {

    /*
     * Aqui eu sobrescrevo o comportamento do ENTER na tabela, por default
     * ele vai para a proxima linha, mas neste caso quero que pegue o valor
     * da atual para exibir o dados.
     */
    tabela.setSelectionMode(0); // somente uma linha pode ser selecionada
    InputMap im = tabela.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke enter = KeyStroke.getKeyStroke("ENTER");
    im.put(enter, im.get(KeyStroke.getKeyStroke(KeyEvent.VK_GREATER, 0)));
    Action enterAction =
        new AbstractAction() {

          public void actionPerformed(ActionEvent e) {
            JTable tabela = (JTable) e.getSource();
          }
        };
    tabela.getActionMap().put(im.get(enter), enterAction);
  }
 private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
   String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
   String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
   String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
   // Ctrl+Ins, Shift+Ins, Shift+Del
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       cutActionKey);
   // Ctrl+C, Ctrl+V, Ctrl+X
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       DefaultEditorKit.cutAction);
 }
Example #21
0
  // {{{ _preprocessKeyEvent() method
  private KeyEvent _preprocessKeyEvent(KeyEvent evt) {
    if (view.isClosed()) return null;
    Component focusOwner = view.getFocusOwner();
    if (focusOwner instanceof JComponent) {
      JComponent comp = (JComponent) focusOwner;
      InputMap map = comp.getInputMap();
      ActionMap am = comp.getActionMap();

      if (map != null && am != null && comp.isEnabled()) {
        KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(evt);
        Object binding = map.get(keyStroke);
        if (binding != null && am.get(binding) != null) {
          return null;
        }
      }
    }

    if (focusOwner instanceof JTextComponent) {
      // fix for the bug where key events in JTextComponents
      // inside views are also handled by the input handler
      if (evt.getID() == KeyEvent.KEY_PRESSED) {
        switch (evt.getKeyCode()) {
          case KeyEvent.VK_ENTER:
          case KeyEvent.VK_TAB:
          case KeyEvent.VK_BACK_SPACE:
          case KeyEvent.VK_SPACE:
            return null;
        }
      }
    }

    if (evt.isConsumed()) return null;

    if (Debug.DUMP_KEY_EVENTS) {
      Log.log(Log.DEBUG, this, "Key event (preprocessing) : " + AbstractInputHandler.toString(evt));
    }

    return KeyEventWorkaround.processKeyEvent(evt);
  } // }}}
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
Example #23
0
  private void buildGUI() {
    setLayout(new BorderLayout());

    _tree = new PsiViewerTree(_model);
    _tree.getSelectionModel().addTreeSelectionListener(_treeSelectionListener);

    ActionMap actionMap = _tree.getActionMap();
    actionMap.put(
        "EditSource",
        new AbstractAction("EditSource") {
          public void actionPerformed(ActionEvent e) {
            debug("key typed " + e);
            if (getSelectedElement() == null) return;
            Editor editor = _caretMover.openInEditor(getSelectedElement());
            selectElementAtCaret(editor, TREE_SELECTION_CHANGED);
            editor.getContentComponent().requestFocus();
          }
        });
    InputMap inputMap = _tree.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0, true), "EditSource");

    _propertyPanel = new PropertySheetPanel();

    _splitPane =
        new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JBScrollPane(_tree), _propertyPanel) {
          public void setDividerLocation(int location) {
            debug(
                "Divider location changed to "
                    + location
                    + " component below "
                    + (getRightComponent().isVisible() ? "visible" : "not visible"));
            if (getRightComponent().isVisible())
              _projectComponent.setSplitDividerLocation(location);
            super.setDividerLocation(location);
          }
        };
    _splitPane.setDividerLocation(_projectComponent.getSplitDividerLocation());
    add(_splitPane);
  }
Example #24
0
  private Container createReturnPane() {
    // Create return button
    returnButton = new JButton(returnAction);

    // Create text fields
    retISBN = new JTextField(15);
    retCustID = new JTextField(15);

    // Create panel and layout
    JPanel pane = new JPanel();
    pane.setOpaque(false);
    GridBagLayout gb = new GridBagLayout();
    pane.setLayout(gb);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 5, 1, 5);

    // Fill panel
    c.anchor = GridBagConstraints.EAST;
    addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1);

    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    addToGridBag(gb, c, pane, retISBN, 1, 0, 3, 1);
    addToGridBag(gb, c, pane, retCustID, 1, 1, 3, 1);

    c.fill = GridBagConstraints.NONE;
    addToGridBag(gb, c, pane, returnButton, 4, 0, 1, 3);

    // Set up VK_ENTER triggering the return button in this panel
    InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    input.put(getKeyStroke("ENTER"), "returnAction");
    pane.getActionMap().put("returnAction", returnAction);

    return pane;
  }
 @SuppressWarnings({"HardCodedStringLiteral"})
 public static void initInputMapDefaults(UIDefaults defaults) {
   // Make ENTER work in JTrees
   InputMap treeInputMap = (InputMap) defaults.get("Tree.focusInputMap");
   if (treeInputMap != null) { // it's really possible. For example,  GTK+ doesn't have such map
     treeInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "toggle");
   }
   // Cut/Copy/Paste in JTextAreas
   InputMap textAreaInputMap = (InputMap) defaults.get("TextArea.focusInputMap");
   if (textAreaInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textAreaInputMap, false);
   }
   // Cut/Copy/Paste in JTextFields
   InputMap textFieldInputMap = (InputMap) defaults.get("TextField.focusInputMap");
   if (textFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textFieldInputMap, false);
   }
   // Cut/Copy/Paste in JPasswordField
   InputMap passwordFieldInputMap = (InputMap) defaults.get("PasswordField.focusInputMap");
   if (passwordFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(passwordFieldInputMap, false);
   }
   // Cut/Copy/Paste in JTables
   InputMap tableInputMap = (InputMap) defaults.get("Table.ancestorInputMap");
   if (tableInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(tableInputMap, true);
   }
 }
Example #26
0
  /**
   * Registers the keystroke of the given action as "command" of the given component.
   *
   * <p>This code is based on the Sulky-tools, found at &lt;http://github.com/huxi/sulky&gt;.
   *
   * @param aComponent the component that should react on the keystroke, cannot be <code>null</code>
   *     ;
   * @param aAction the action of the keystroke, cannot be <code>null</code>;
   * @param aCommandName the name of the command to register the keystore under.
   */
  public static void registerKeystroke(
      final JComponent aComponent, final Action aAction, final String aCommandName) {
    final KeyStroke keyStroke = (KeyStroke) aAction.getValue(Action.ACCELERATOR_KEY);
    if (keyStroke == null) {
      return;
    }

    InputMap inputMap = aComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = aComponent.getActionMap();
    inputMap.put(keyStroke, aCommandName);
    actionMap.put(aCommandName, aAction);

    inputMap = aComponent.getInputMap(JComponent.WHEN_FOCUSED);
    Object value = inputMap.get(keyStroke);
    if (value != null) {
      inputMap.put(keyStroke, aCommandName);
    }

    inputMap = aComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    value = inputMap.get(keyStroke);
    if (value != null) {
      inputMap.put(keyStroke, aCommandName);
    }
  }
Example #27
0
  public void teclasAtalhos() {

    // BOTAO EXCLUIR LOTE
    Action actionExcluir =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            // simula o click no botão
            jBExcluirLote.grabFocus();
            jBExcluirLote.doClick();
          }
        };

    // Associa o listener com a tecla f2 para que seja disparado toda vez, mesmo quando o foco não
    // está no botão
    KeyStroke keyStrokeExcluir = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
    String actionNameExcluir = "TECLA_F1";
    InputMap inputMapExcluir = jBExcluirLote.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapExcluir.put(keyStrokeExcluir, actionNameExcluir);
    ActionMap actionMapExcluir = jBExcluirLote.getActionMap();
    actionMapExcluir.put(actionNameExcluir, actionExcluir);

    // BOTAO SAIR TELA
    // Action para o botao fechar
    Action actionTeclaFechar =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            // simula o click no botão
            jBFechar.grabFocus();
            jBFechar.doClick();
          }
        };
    // Associa o listener com a tecla esc para que seja disparado toda vez, mesmo quando o foco não
    // está no botão
    KeyStroke keyStrokeFechar = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    String actionNameFechar = "TECLA_ESC";
    InputMap inputMapFechar = jBFechar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapFechar.put(keyStrokeFechar, actionNameFechar);
    ActionMap actionMapFechar = jBFechar.getActionMap();
    actionMapFechar.put(actionNameFechar, actionTeclaFechar);

    // BOTAO ATUALIZAR
    // Action para o botao Atualizar
    Action actionTeclaAtualizar =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            // simula o click no botão
            jBAtualizar.grabFocus();
            jBAtualizar.doClick();
          }
        };
    // Associa o listener com a tecla f6 para que seja disparado toda vez, mesmo quando o foco não
    // está no botão
    KeyStroke keyStrokeAtualizar = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0);
    String actionNameAtualizar = "TECLA_F6";
    InputMap inputMapAtualizar = jBAtualizar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapAtualizar.put(keyStrokeAtualizar, actionNameAtualizar);
    ActionMap actionMapAtualizar = jBAtualizar.getActionMap();
    actionMapAtualizar.put(actionNameAtualizar, actionTeclaAtualizar);

    // BOTAO MOSTRAR TODOS
    // Action para o botao  exibir todos
    Action actionTeclaExibirTodos =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            // simula o click no botão
            jBMostrarTodos.grabFocus();
            jBMostrarTodos.doClick();
          }
        };
    // Associa o listener com a tecla f4 para que seja disparado toda vez, mesmo quando o foco não
    // está no botão
    KeyStroke keyStrokeExibirTodos = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
    String actionNameExibirTodos = "TECLA_F5";
    InputMap inputMapExibirTodos = jBMostrarTodos.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapExibirTodos.put(keyStrokeExibirTodos, actionNameExibirTodos);
    ActionMap actionMapExibirTodos = jBMostrarTodos.getActionMap();
    actionMapExibirTodos.put(actionNameExibirTodos, actionTeclaExibirTodos);
  }
Example #28
0
  EditFrame(RopeFrame parent) {
    super(parent);

    // Implement a smarter way to set the initial frame position and size
    setLocation(0, 0);
    setSize(670, 705);

    try {
      jbInit();
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    sourceArea.addCaretListener(this);
    browseButton.addActionListener(this);
    optionsButton.addActionListener(this);
    assembleButton.addActionListener(this);
    saveButton.addActionListener(this);

    messageList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent event) {
            highlightError(messageList.locationToIndex(event.getPoint()));
          }
        });

    undoMgr = new CompoundUndoManager(sourceArea);

    undoAction = undoMgr.getUndoAction();
    redoAction = undoMgr.getRedoAction();

    undoMgr.updateUndoAction = new UpdateUndoAction();
    undoMgr.updateRedoAction = new UpdateRedoAction();

    document = sourceArea.getDocument();

    ActionMap am = sourceArea.getActionMap();
    InputMap im = sourceArea.getInputMap(JComponent.WHEN_FOCUSED);

    // Remove automatic key bindings because we want them controlled by menu items
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks), "none");
    im.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks + InputEvent.SHIFT_MASK),
        "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, RopeHelper.modifierMaks), "none");

    // Set custom binding action for tab key
    String action = "tabKeyAction";
    im.put(KeyStroke.getKeyStroke("TAB"), action);
    am.put(
        action,
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int endLine = sourceArea.getLineEndOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos >= 39 && linePos < 79) {
                caretPos = startLine + linePos + 10 - ((linePos + 1) % 10);
              } else if (linePos >= 20 && linePos <= 39) {
                caretPos = startLine + 39;
              } else if (linePos >= 15 && linePos <= 19) {
                caretPos = startLine + 20;
              } else if (linePos >= 5 && linePos <= 14) {
                caretPos = startLine + 15;
              } else {
                caretPos = startLine + 5;
              }

              // If the line is shorter than the new position fo the caret add enough spaces...
              if (caretPos > endLine) {
                StringBuilder str = new StringBuilder();
                int size = caretPos - endLine;
                while (size-- >= 0) {
                  str.append(' ');
                }
                document.insertString(endLine - 1, str.toString(), null);
              }

              sourceArea.setCaretPosition(caretPos);
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    // Set custom binding action for return/enter key
    String actionKey = "backspaceKeyAction";
    im.put(KeyStroke.getKeyStroke("BACK_SPACE"), actionKey);
    am.put(
        actionKey,
        new AbstractAction()
        // How can I get the original action?
        {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int endLine = sourceArea.getLineEndOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos == 15) {
                int endPos = 5;
                int charPos = linePos;
                for (; charPos > endPos; charPos--) {
                  char ch = sourceArea.getText().charAt((startLine + charPos) - 1);
                  if (!Character.isWhitespace(ch)) {
                    break;
                  }
                }

                sourceArea.setCaretPosition(startLine + charPos);
              } else {
                int startSel = sourceArea.getSelectionStart();
                int endSel = sourceArea.getSelectionEnd();
                if (startSel == endSel) {
                  startSel = caretPos - 1;
                  endSel = caretPos;
                }

                StringBuilder sb = new StringBuilder(sourceArea.getText());
                sb.replace(startSel, endSel, "");
                sourceArea.setText(sb.toString());
                sourceArea.setCaretPosition(startSel);
              }
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    // Set custom binding action for return/enter key
    action = "enterKeyAction";
    im.put(KeyStroke.getKeyStroke("ENTER"), action);
    am.put(
        action,
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos >= 5) {
                document.insertString(caretPos, "\n     ", null);
              } else {
                document.insertString(caretPos, "\n", null);
              }
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    document.addDocumentListener(
        new DocumentListener() {
          @Override
          public void insertUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }

          @Override
          public void removeUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }

          @Override
          public void changedUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }
        });
  }
Example #29
0
  public Viewport(CConn cc_) {
    cc = cc_;
    updateTitle();
    setFocusable(false);
    setFocusTraversalKeysEnabled(false);
    setIconImage(VncViewer.frameImage);
    UIManager.getDefaults()
        .put("ScrollPane.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {}));
    sp = new JScrollPane();
    sp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    sp.getViewport().setBackground(Color.BLACK);
    InputMap im = sp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    int ctrlAltShiftMask = Event.SHIFT_MASK | Event.CTRL_MASK | Event.ALT_MASK;
    if (im != null) {
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ctrlAltShiftMask), "unitScrollUp");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ctrlAltShiftMask), "unitScrollDown");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ctrlAltShiftMask), "unitScrollLeft");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ctrlAltShiftMask), "unitScrollRight");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, ctrlAltShiftMask), "scrollUp");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, ctrlAltShiftMask), "scrollDown");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, ctrlAltShiftMask), "scrollLeft");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, ctrlAltShiftMask), "scrollRight");
    }
    tb = new Toolbar(cc);
    add(tb, BorderLayout.PAGE_START);
    getContentPane().add(sp);
    if (VncViewer.os.startsWith("mac os x")) {
      macMenu = new MacMenuBar(cc);
      setJMenuBar(macMenu);
      if (VncViewer.getBooleanProperty("turbovnc.lionfs", true)) enableLionFS();
    }
    // NOTE: If Lion FS mode is enabled, then the viewport is only created once
    // as a non-full-screen viewport, so we tell showToolbar() to ignore the
    // full-screen state.
    showToolbar(cc.showToolbar, canDoLionFS);

    addWindowFocusListener(
        new WindowAdapter() {
          public void windowGainedFocus(WindowEvent e) {
            if (sp.getViewport().getView() != null)
              sp.getViewport().getView().requestFocusInWindow();
            if (isVisible() && keyboardTempUngrabbed) {
              vlog.info("Keyboard focus regained. Re-grabbing keyboard.");
              grabKeyboardHelper(true);
              keyboardTempUngrabbed = false;
            }
          }

          public void windowLostFocus(WindowEvent e) {
            if (cc.keyboardGrabbed && isVisible()) {
              vlog.info("Keyboard focus lost. Temporarily ungrabbing keyboard.");
              grabKeyboardHelper(false);
              keyboardTempUngrabbed = true;
            }
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            cc.close();
          }
        });

    addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            if (cc.opts.scalingFactor == Options.SCALE_AUTO
                || cc.opts.scalingFactor == Options.SCALE_FIXEDRATIO) {
              if ((sp.getSize().width != cc.desktop.scaledWidth)
                  || (sp.getSize().height != cc.desktop.scaledHeight)) {
                cc.desktop.setScaledSize();
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
                sp.validate();
                if (getExtendedState() != JFrame.MAXIMIZED_BOTH && !cc.opts.fullScreen) {
                  sp.setSize(new Dimension(cc.desktop.scaledWidth, cc.desktop.scaledHeight));
                  int w = cc.desktop.scaledWidth + VncViewer.insets.left + VncViewer.insets.right;
                  int h = cc.desktop.scaledHeight + VncViewer.insets.top + VncViewer.insets.bottom;
                  if (tb.isVisible()) h += tb.getHeight();
                  if (cc.opts.scalingFactor == Options.SCALE_FIXEDRATIO) setSize(w, h);
                }
              }
            } else if (cc.opts.desktopSize.mode == Options.SIZE_AUTO
                && !cc.firstUpdate
                && !cc.pendingServerResize) {
              Dimension availableSize = cc.viewport.getAvailableSize();
              if (availableSize.width >= 1
                  && availableSize.height >= 1
                  && (availableSize.width != cc.desktop.scaledWidth
                      || availableSize.height != cc.desktop.scaledHeight)) {
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                sp.validate();
                if (timer != null) timer.stop();
                ActionListener actionListener =
                    new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                        Dimension availableSize = cc.viewport.getAvailableSize();
                        if (availableSize.width < 1 || availableSize.height < 1)
                          throw new ErrorException("Unexpected zero-size component");
                        cc.sendDesktopSize(availableSize.width, availableSize.height, true);
                      }
                    };
                timer = new Timer(500, actionListener);
                timer.setRepeats(false);
                timer.start();
              }
            } else {
              sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
              sp.validate();
            }
            if (cc.desktop.cursor != null) {
              Cursor cursor = cc.desktop.cursor;
              if (cursor.hotspot != null)
                // hotspot will be null until the first cursor update is received
                // from the server.
                cc.setCursor(
                    cursor.width(),
                    cursor.height(),
                    cursor.hotspot,
                    (int[]) cursor.data,
                    cursor.mask);
            }
            if (((sp.getSize().width > cc.desktop.scaledWidth)
                    || (sp.getSize().height > cc.desktop.scaledHeight))
                && cc.opts.desktopSize.mode != Options.SIZE_AUTO) {
              int w = sp.getSize().width - adjustWidth;
              int h = sp.getSize().height - adjustHeight;
              dx =
                  (w <= cc.desktop.scaledWidth)
                      ? 0
                      : (int) Math.floor((w - cc.desktop.scaledWidth) / 2);
              dy =
                  (h <= cc.desktop.scaledHeight)
                      ? 0
                      : (int) Math.floor((h - cc.desktop.scaledHeight) / 2);
            } else {
              dx = dy = 0;
            }
            repaint();
          }
        });
  }
  /**
   * Set up the calendar panel with the basic layout and components. These are not date specific.
   */
  private void createCalendarComponents() {
    // The date panel will hold the calendar and/or the time spinner

    JPanel datePanel = new JPanel(new BorderLayout(2, 2));

    // Create the calendar if we are displaying a calendar

    if ((selectedComponents & DISPLAY_DATE) > 0) {
      formatMonth = new SimpleDateFormat("MMM", locale);
      formatWeekDay = new SimpleDateFormat("EEE", locale);

      // Set up the shared keyboard bindings

      setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
      setActionMap(actionMap);

      // Set up the decrement buttons

      yearDecrButton =
          new JButton(
              new ButtonAction(
                  "YearDecrButton",
                  "YearDecrButtonMnemonic",
                  "YearDecrButtonAccelerator",
                  "YearDecrButtonImage",
                  "YearDecrButtonShort",
                  "YearDecrButtonLong",
                  YEAR_DECR_BUTTON));
      monthDecrButton =
          new JButton(
              new ButtonAction(
                  "MonthDecrButton",
                  "MonthDecrButtonMnemonic",
                  "MonthDecrButtonAccelerator",
                  "MonthDecrButtonImage",
                  "MonthDecrButtonShort",
                  "MonthDecrButtonLong",
                  MONTH_DECR_BUTTON));
      JPanel decrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      decrPanel.add(yearDecrButton);
      decrPanel.add(monthDecrButton);

      // Set up the month/year label

      monthYearLabel = new JLabel();
      monthYearLabel.setHorizontalAlignment(JLabel.CENTER);

      // Set up the increment buttons

      monthIncrButton =
          new JButton(
              new ButtonAction(
                  "MonthIncrButton",
                  "MonthIncrButtonMnemonic",
                  "MonthIncrButtonAccelerator",
                  "MonthIncrButtonImage",
                  "MonthIncrButtonShort",
                  "MonthIncrButtonLong",
                  MONTH_INCR_BUTTON));
      yearIncrButton =
          new JButton(
              new ButtonAction(
                  "YearIncrButton",
                  "YearIncrButtonMnemonic",
                  "YearIncrButtonAccelerator",
                  "YearIncrButtonImage",
                  "YearIncrButtonShort",
                  "YearIncrButtonLong",
                  YEAR_INCR_BUTTON));
      JPanel incrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      incrPanel.add(monthIncrButton);
      incrPanel.add(yearIncrButton);

      // Put them all together

      JPanel monthYearNavigator = new JPanel(new BorderLayout(2, 2));
      monthYearNavigator.add(decrPanel, BorderLayout.WEST);
      monthYearNavigator.add(monthYearLabel);
      monthYearNavigator.add(incrPanel, BorderLayout.EAST);

      // Set up the day panel

      JPanel dayPanel = new JPanel(new GridLayout(7, 7));
      int firstDay = displayCalendar.getFirstDayOfWeek();

      // Get the week day labels. The following technique is used so
      // that we can start the calendar on the right day of the week and
      // we can get the week day labels properly localized

      Calendar temp = Calendar.getInstance(locale);
      temp.set(2000, Calendar.MARCH, 15);
      while (temp.get(Calendar.DAY_OF_WEEK) != firstDay) {
        temp.add(Calendar.DATE, 1);
      }
      dayOfWeekLabels = new JLabel[7];
      for (int i = 0; i < 7; i++) {
        Date date = temp.getTime();
        String dayOfWeek = formatWeekDay.format(date);
        dayOfWeekLabels[i] = new JLabel(dayOfWeek);
        dayOfWeekLabels[i].setHorizontalAlignment(JLabel.CENTER);
        dayPanel.add(dayOfWeekLabels[i]);
        temp.add(Calendar.DATE, 1);
      }

      // Add all the day buttons

      dayButtons = new JToggleButton[6][7];
      dayGroup = new ButtonGroup();
      DayListener dayListener = new DayListener();
      for (int row = 0; row < 6; row++) {
        for (int day = 0; day < 7; day++) {
          dayButtons[row][day] = new JToggleButton();
          dayButtons[row][day].addItemListener(dayListener);
          dayPanel.add(dayButtons[row][day]);
          dayGroup.add(dayButtons[row][day]);
        }
      }

      // We add this special button to the button group, so we have a
      // way of unselecting all the visible buttons

      offScreenButton = new JToggleButton("X");
      dayGroup.add(offScreenButton);

      // Combine the navigators and days

      datePanel.add(monthYearNavigator, BorderLayout.NORTH);
      datePanel.add(dayPanel);
    }

    // Create the time spinner field if we are displaying the time

    if ((selectedComponents & DISPLAY_TIME) > 0) {

      // Create the time component

      spinnerDateModel = new SpinnerDateModel();
      spinnerDateModel.addChangeListener(new TimeListener());
      spinner = new JSpinner(spinnerDateModel);

      JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, timePattern);
      dateEditor.getTextField().setEditable(false);
      dateEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
      spinner.setEditor(dateEditor);

      // Set the input/action maps for the spinner. (Only BACK_SPACE
      // seems to work!)

      InputMap sim = new InputMap();
      sim.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
      sim.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
      sim.setParent(spinner.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));

      ActionMap sam = new ActionMap();
      sam.put(
          "setNullDate",
          new AbstractAction("setNullDate") {
            public void actionPerformed(ActionEvent e) {
              JCalendar.this.setDate(null);
            }
          });
      sam.setParent(spinner.getActionMap());

      spinner.setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, sim);
      spinner.setActionMap(sam);

      // Create a special panel for the time display

      JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 2, 2));
      timePanel.add(spinner);

      // Now add it to the bottom

      datePanel.add(timePanel, BorderLayout.SOUTH);
    }

    setLayout(new BorderLayout(2, 2));
    add(datePanel);

    // Add today's date at the bottom of the calendar/time, if needed

    if (isTodayDisplayed) {
      Object[] args = {new Date()};
      String todaysDate = MessageFormat.format(bundle.getString("Today"), args);
      todaysLabel = new JLabel(todaysDate);
      todaysLabel.setHorizontalAlignment(JLabel.CENTER);

      // Add today's date at the very bottom

      add(todaysLabel, BorderLayout.SOUTH);
    }
  }