Package javax.swing.text

Examples of javax.swing.text.Caret


        terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple"));
        terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan"));
        final Font f = new Font("Monospaced", Font.PLAIN, application.scaled(14));
        terminalArea = new JTextPane();
        terminalArea.setStyledDocument(new MyDocument());
        final Caret caret = new DefaultCaret() {
            @Override
            protected synchronized void damage(final Rectangle r) {
                if (r != null) {
                    x = r.x;
                    y = r.y;
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

    // 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();
    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 (regex==false) {
      int pos = getNextMatchPos(text, findIn, forward,
                      matchCase, wholeWord);
      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, matchCase, wholeWord);
      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.
   */
  protected 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();
    int start = makeMarkAndDotEqual(textArea, forward);

    String findIn = getFindInText(textArea, start, forward);
    if (findIn==null) return false;

    // Find the next location of the text we're searching for.
    RegExReplaceInfo info = getRegExReplaceInfo(toFind, findIn,
                      forward, matchCase,
                      wholeWord, replaceWith);

    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

      super(textArea);
    }

    @Override
    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 mouseDragged(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

    public void mousePressed(MouseEvent e) {
      if (e.isPopupTrigger()) { // OS X popup triggers are on pressed
        showPopup(e);
      }
      else if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        Caret caret = getCaret();
        dot = caret.getDot();
        mark = caret.getMark();
        fireCaretUpdate(this);
      }
    }
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 new SearchResult();
    }
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.