Example #1
0
 /** Select or grow image when clicked. */
 public void mousePressed(MouseEvent e) {
   Dimension size = fComponent.getSize();
   if (e.getX() >= size.width - 7 && e.getY() >= size.height - 7 && getSelectionState() == 2) {
     // Click in selected grow-box:
     if (DEBUG) CampaignData.mwlog.infoLog("ImageView: grow!!! Size=" + fWidth + "x" + fHeight);
     Point loc = fComponent.getLocationOnScreen();
     fGrowBase = new Point(loc.x + e.getX() - fWidth, loc.y + e.getY() - fHeight);
     // fGrowProportionally = e.isShiftDown();
   } else {
     // Else select image:
     fGrowBase = null;
     JTextComponent comp = (JTextComponent) fContainer;
     int start = fElement.getStartOffset();
     int end = fElement.getEndOffset();
     int mark = comp.getCaret().getMark();
     int dot = comp.getCaret().getDot();
     if (e.isShiftDown()) {
       // extend selection if shift key down:
       if (mark <= start) comp.moveCaretPosition(end);
       else comp.moveCaretPosition(start);
     } else {
       // just select image, without shift:
       if (mark != start) comp.setCaretPosition(start);
       if (dot != end) comp.moveCaretPosition(end);
     }
   }
 }
Example #2
0
  @Override
  public void focusGained(final FocusEvent e) {
    final JTextComponent component = getComponent();
    if (!component.isEnabled() || !component.isEditable()) {
      super.focusGained(e);
      return;
    }

    mFocused = true;
    if (!shouldSelectAllOnFocus) {
      shouldSelectAllOnFocus = true;
      super.focusGained(e);
      return;
    }

    if (isMultiLineEditor) {
      super.focusGained(e);
      return;
    }

    final int end = component.getDocument().getLength();
    final int dot = getDot();
    final int mark = getMark();
    if (dot == mark) {
      if (dot == 0) {
        component.setCaretPosition(end);
        component.moveCaretPosition(0);
      } else if (dot == end) {
        component.setCaretPosition(0);
        component.moveCaretPosition(end);
      }
    }

    super.focusGained(e);
  }
  /**
   * This applies quick fixes which require insertion in the editor panel.
   *
   * @param markThisPart
   */
  void insertSentenceStub(
      IvanErrorInstance myerror, List<String> stubs, String defaultStub, String markThisPart) {
    String[] unlocatedNames = myerror.Reference;
    /* Create location sentences.
     * 1. find the insertion point. The insertion point is somewhere to the right of the last cue.
     * 2. set the caret to the insertion point
     * 3. for each Name without location, insert a sentence. (unlocatedNames)
     *   a) build a sentence: Name + Stub. Then insert it.
     *   b) if you run out of stubs, create Name + " is on the … side." and then select the three dots.
     **/
    // focus is important, so the user can readily start typing after clicking
    txtEditor.requestFocusInWindow();
    // get insertion point
    int insertionpoint = findInsertionPoint(myerror.Codepoints);
    // set the caret
    txtEditor.setCaretPosition(insertionpoint);

    String sentence;
    if (stubs.size() > 0) {
      // build a sentence from a stub
      sentence = "\n" + unlocatedNames[0] + stubs.get(0) + " ";
      stubs.remove(0);
      // finalise last sentence with a period, if not present
      try {
        String text = txtEditor.getText(insertionpoint - 1, 1);
        if (!text.equals(".")) {
          sentence = "." + sentence;
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
      // insert the sentence
      txtEditor.replaceSelection(sentence);
    } else {
      sentence = "\n" + unlocatedNames[0] + defaultStub;
      // finalise last sentence with a period, if not present
      try {
        String text = txtEditor.getText(insertionpoint - 1, 1);
        if (!text.equals(".")) {
          sentence = "." + sentence;
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
      // insert the sentence
      txtEditor.replaceSelection(sentence);
      // select the …
      int dotspoint = txtEditor.getText().indexOf(markThisPart, insertionpoint);
      if (dotspoint > 0) {
        txtEditor.setCaretPosition(dotspoint);
        txtEditor.moveCaretPosition(dotspoint + markThisPart.length());
      }
    }
  }
Example #4
0
  private void moveCtrlRight(boolean select) {
    String text = _textPane.getText();
    int pos = _textPane.getCaretPosition() + 1;

    if (pos > text.length()) {
      return;
    }

    for (; pos < text.length(); ++pos) {
      if (isToStopAt(text.charAt(pos), text.charAt(pos - 1))) {
        break;
      }
    }

    if (select) {
      _textPane.moveCaretPosition(pos);
    } else {
      _textPane.setCaretPosition(pos);
    }
  }
Example #5
0
  private void moveCtrlLeft(boolean select) {
    String text = _textPane.getText();
    int pos = _textPane.getCaretPosition() - 1;

    if (pos < 0) {
      return;
    }

    for (; pos > 0; --pos) {
      if (isToStopAt(text.charAt(pos - 1), text.charAt(pos))) {
        break;
      }
    }

    if (select) {
      _textPane.moveCaretPosition(pos);
    } else {
      _textPane.setCaretPosition(pos);
    }
  }
 private void highlightCompletedText(int start) {
   editor.setCaretPosition(getLength());
   editor.moveCaretPosition(start);
 }