Esempio n. 1
0
  // ------------------------------------------------------------------
  // from Java Swing 1.2 Orielly - Robert Eckstein
  // ------------------------------------------------------------------
  protected JTextComponent updateKeymapForWord(JTextComponent textComp) {
    // create a new child keymap
    Keymap map = JTextComponent.addKeymap("NslmMap", textComp.getKeymap());

    // define the keystrokeds to be added
    KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK, false);
    // add the new mappings used DefaultEditorKit actions
    map.addActionForKeyStroke(next, getAction(DefaultEditorKit.nextWordAction));

    KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(prev, getAction(DefaultEditorKit.previousWordAction));

    KeyStroke selNext =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selNext, getAction(DefaultEditorKit.selectionNextWordAction));
    KeyStroke selPrev =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LEFT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selPrev, getAction(DefaultEditorKit.selectionPreviousWordAction));

    KeyStroke find = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(find, getAction("find"));

    KeyStroke findAgain = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(findAgain, getAction("findAgain"));

    // set the keymap for the text component
    textComp.setKeymap(map);
    return (textComp);
  } // end updateKeymapForWord
Esempio n. 2
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Esempio n. 3
0
 /** Create an editor to represent the given document. */
 protected JTextComponent createEditor() {
   JTextComponent c = new JTextArea();
   c.setDragEnabled(true);
   c.setFont(new Font("monospaced", Font.PLAIN, 12));
   return c;
 }
Esempio n. 4
0
  // ------------------------------------------------------------------
  // from Java Swing 1.2 Orielly - Robert Eckstein
  // ------------------------------------------------------------------
  protected JTextComponent updateKeymapForEmacs(JTextComponent textComp) {
    // note: it does not look like a key can do more than one action
    // thus no modes.
    // todo: not all of these are correct. such as ctrlK
    // todo: add saving - ctrlXS

    // create a new child keymap
    Keymap map = JTextComponent.addKeymap("NslmMap", textComp.getKeymap());

    KeyStroke selNext =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selNext, getAction(DefaultEditorKit.selectionNextWordAction));

    KeyStroke selPrev =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LEFT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selPrev, getAction(DefaultEditorKit.selectionPreviousWordAction));

    KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(next, getAction(DefaultEditorKit.forwardAction));
    KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(prev, getAction(DefaultEditorKit.backwardAction));

    KeyStroke selectionDown = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selectionDown, getAction(DefaultEditorKit.downAction));
    KeyStroke selectionUp = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selectionUp, getAction(DefaultEditorKit.upAction));

    KeyStroke pageDown = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(pageDown, getAction(DefaultEditorKit.pageDownAction));

    KeyStroke pageUp = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(pageUp, getAction(DefaultEditorKit.pageUpAction));

    KeyStroke endDoc =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_GREATER, InputEvent.META_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(endDoc, getAction(DefaultEditorKit.endAction));
    KeyStroke beginingDoc =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LESS, InputEvent.META_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(beginingDoc, getAction(DefaultEditorKit.beginAction));

    // the VK_SPACE and VK_W not working as in Emacs - space deleting
    // KeyStroke
    // selectionStart=KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,InputEvent.CTRL_MASK,false);
    // map.addActionForKeyStroke(selectionStart,getAction(DefaultEditorKit.selectionForwardAction));
    // //todo: setCharPosAction
    // this is doing nothing because only one char to can be assigned to cut
    // KeyStroke cut1=KeyStroke.getKeyStroke(KeyEvent.VK_W,InputEvent.CTRL_MASK,false);
    // map.addActionForKeyStroke(cut1,getAction(DefaultEditorKit.cutAction));

    // if we do save as XS, this will have to change
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(cut, getAction(DefaultEditorKit.cutAction));

    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(paste, getAction(DefaultEditorKit.pasteAction));

    KeyStroke moveToEndLine = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(moveToEndLine, getAction(DefaultEditorKit.endLineAction));

    // not emacs like
    KeyStroke selWord = KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selWord, getAction(DefaultEditorKit.selectWordAction));

    KeyStroke selLine = KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selLine, getAction(DefaultEditorKit.selectLineAction));

    KeyStroke delNext = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(delNext, getAction(DefaultEditorKit.deleteNextCharAction));

    KeyStroke insertLine = KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(insertLine, getAction(DefaultEditorKit.insertBreakAction));

    KeyStroke searchBackward = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(searchBackward, getAction("findAgain"));

    KeyStroke searchForward = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(searchForward, getAction("findAgain"));

    // set the keymap for the text component
    textComp.setKeymap(map);
    return (textComp);
  } // end updateKeymapForEmacs