Package javax.swing.text

Examples of javax.swing.text.Caret


    if (mode!=INSERT_MODE && mode!=OVERWRITE_MODE)
      mode = INSERT_MODE;

    if (textMode != mode) {
      Caret caret = getCaret();
      if (caret instanceof ConfigurableCaret) {
        ((ConfigurableCaret)caret).setStyle(carets[mode]);
      }
      textMode = mode;
    }
View Full Code Here


    protected RTextAreaMutableCaretEvent(RTextArea textArea) {
      super(textArea);
    }

    public void focusGained(FocusEvent e) {
      Caret c = getCaret();
      boolean enabled = c.getDot()!=c.getMark();
      cutAction.setEnabled(enabled);
      copyAction.setEnabled(enabled);
      undoManager.updateActions(); // To reflect this text area.
    }
View Full Code Here

    public void focusLost(FocusEvent e) {
    }

    public void mouseDragged(MouseEvent e) {
      if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        Caret caret = getCaret();
        dot = caret.getDot();
        mark = caret.getMark();
        fireCaretUpdate(this);
      }
    }
View Full Code Here

    public void mousePressed(MouseEvent e) {
      // WORKAROUND:  Since JTextComponent only updates the caret
      // location on mouse clicked and released, we'll do it on dragged
      // events when the left mouse button is clicked.
      if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        Caret caret = getCaret();
        dot = caret.getDot();
        mark = caret.getMark();
        fireCaretUpdate(this);
      }
    }
View Full Code Here

          pos = (direction == NORTH) ?
                Math.max(0, view.getEndOffset() - 1) :
                view.getStartOffset();
          break;
        }
        Caret c = (target != null) ? target.getCaret() : null;
        // YECK! Ideally, the x location from the magic caret
        // position would be passed in.
        Point mcp;
        if (c != null)
          mcp = c.getMagicCaretPosition();
        else
          mcp = null;
        int x;
        if (mcp == null) {
          Rectangle loc = target.modelToView(pos);
View Full Code Here

   * @param e The event.
   */
  public void actionPerformed(ActionEvent e) {

    // Don't do anything if they are selecting text.
    Caret c = textArea.getCaret();
    if (c.getDot()!=c.getMark()) {
      return;
    }

    RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
    //long time = System.currentTimeMillis();
    doc.readLock();
    try {

      // Get the token at the caret position.
      int line = textArea.getCaretLineNumber();
      Token tokenList = textArea.getTokenListForLine(line);
      int dot = c.getDot();
      Token t = RSyntaxUtilities.getTokenAtOffset(tokenList, dot);
      if (t==null /* EOL */ || !isValidType(t) || isNonWordChar(t)) {
        // Try to the "left" of the caret.
        dot--;
        try {
View Full Code Here

   * @param textArea The text area to operate on.
   * @throws BadLocationException If something bad happens.
   */
  public void invoke(RSyntaxTextArea textArea) throws BadLocationException {

    Caret c = textArea.getCaret();
    int dot = c.getDot();
    int mark = c.getMark();
    int p0 = Math.min(dot, mark);
    int p1 = Math.max(dot, mark);
    RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
    Element map = doc.getDefaultRootElement();

View Full Code Here

    // Be smart about what position we're "starting" at.  We don't want
    // to find a match in the currently selected text (if any), so we
    // start searching AFTER the selection if searching forward, and
    // BEFORE the selection if searching backward.
    Caret c = textArea.getCaret();
    boolean forward = context.getSearchForward();
    int start = forward ? Math.max(c.getDot(), c.getMark()) :
            Math.min(c.getDot(), c.getMark());

    String findIn = getFindInText(textArea, start, forward);
    if (findIn==null || findIn.length()==0) return false;

    // Find the next location of the text we're searching for.
    if (!context.isRegularExpression()) {
      int pos = getNextMatchPos(text, findIn, forward,
                context.getMatchCase(), context.getWholeWord());
      findIn = null; // May help garbage collecting.
      if (pos!=-1) {
        // Without this, if JTextArea isn't in focus, selection
        // won't appear selected.
        c.setSelectionVisible(true);
        pos = forward ? start+pos : pos;
        selectAndPossiblyCenter(textArea, pos, pos+text.length());
        return true;
      }
    }
    else {
      // Regex matches can have varying widths.  The returned point's
      // x- and y-values represent the start and end indices of the
      // match in findIn.
      Point regExPos = getNextMatchPosRegEx(text, findIn, forward,
                context.getMatchCase(), context.getWholeWord());
      findIn = null; // May help garbage collecting.
      if (regExPos!=null) {
        // Without this, if JTextArea isn't in focus, selection
        // won't appear selected.
        c.setSelectionVisible(true);
        if (forward) {
          regExPos.translate(start, start);
        }
        selectAndPossiblyCenter(textArea, regExPos.x, regExPos.y);
        return true;
View Full Code Here

   *        document (<code>false</code> means backward).
   * @return The new dot and mark position.
   */
  private static int makeMarkAndDotEqual(JTextArea textArea,
                    boolean forward) {
    Caret c = textArea.getCaret();
    int val = forward ? Math.min(c.getDot(), c.getMark()) :
            Math.max(c.getDot(), c.getMark());
    c.setDot(val);
    return val;
  }
View Full Code Here

    // if they are searching backwards and there is a selection such that
    // the dot is past the mark, and the selection is the text for which
    // you're searching, this search will find and return the current
    // selection.  So, in that case we start at the beginning of the
    // selection.
    Caret c = textArea.getCaret();
    boolean forward = context.getSearchForward();
    int start = makeMarkAndDotEqual(textArea, forward);

    CharSequence findIn = getFindInCharSequence(textArea, start, forward);
    if (findIn==null) return false;

    // Find the next location of the text we're searching for.
    RegExReplaceInfo info = getRegExReplaceInfo(findIn, context);

    findIn = null; // May help garbage collecting.

    // If a match was found, do the replace and return!
    if (info!=null) {

      // Without this, if JTextArea isn't in focus, selection won't
      // appear selected.
      c.setSelectionVisible(true);

      int matchStart = info.getStartIndex();
      int matchEnd = info.getEndIndex();
      if (forward) {
        matchStart += start;
View Full Code Here

TOP

Related Classes of javax.swing.text.Caret

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.