Package javax.swing.text

Examples of javax.swing.text.Caret


   * @see #getRoundedSelectionEdges()
   */
  public void setRoundedSelectionEdges(boolean rounded) {
    if (roundedSelectionEdges!=rounded) {
      roundedSelectionEdges = rounded;
      Caret c = getCaret();
      if (c instanceof ConfigurableCaret) {
        ((ConfigurableCaret)c).setRoundedSelectionEdges(rounded);
        if (c.getDot()!=c.getMark()) { // e.g., there's is a selection
          repaint();
        }
      }
      firePropertyChange(ROUNDED_SELECTION_PROPERTY, !rounded,
                      rounded);
View Full Code Here


    public int getCurrentOffset() {
        JEditorPane ep = contextDispatcher.getCurrentEditor();
        if (ep == null) {
            return -1;
        }
        Caret caret = ep.getCaret();
        if (caret == null) {
            return -1;
        }
        return caret.getDot();
    }
View Full Code Here

            // Obtain the offset where to jump
            pos = Utilities.getRowStartFromLineOffset(doc, line);
        }

        if (pos != -1) {
            Caret caret = pane.getCaret();
            if (caret instanceof BaseCaret) { // support extended scroll mode
                BaseCaret bCaret = (BaseCaret)caret;
                bCaret.setDot(pos, bCaret, EditorUI.SCROLL_FIND);
            }
            else {
                caret.setDot(pos);
            }
        }
    }
View Full Code Here

        if (doc == null) {
            return false;
        }
        try {
            Caret caret = target.getCaret();
            int p0 = Math.min(caret.getDot(), caret.getMark());
            int p1 = Math.max(caret.getDot(), caret.getMark());
            doc.remove(p0, p1 - p0);
            int start = caret.getDot();
            doc.insertString(start, getText(), null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
View Full Code Here

    }

    // If the user wants to overwrite text...
    if (textMode==OVERWRITE_MODE && !"\n".equals(text)) {

      Caret caret = getCaret();
      int caretPos = caret.getDot();
      Document doc = getDocument();
      Element map = doc.getDefaultRootElement();
      int curLine = map.getElementIndex(caretPos);
      int lastLine = map.getElementCount() - 1;

      try {

        // If we're not at the end of a line, select the characters
        // that will be overwritten (otherwise JTextArea will simply
        // insert in front of them).
        int curLineEnd = getLineEndOffset(curLine);
        if (caretPos==caret.getMark() && caretPos!=curLineEnd) {
          if (curLine==lastLine)
            caretPos = Math.min(caretPos+text.length(), curLineEnd);
          else
            caretPos = Math.min(caretPos+text.length(), curLineEnd-1);
          caret.moveDot(caretPos);//moveCaretPosition(caretPos);
        }

      } catch (BadLocationException ble) { // Never happens
        UIManager.getLookAndFeel().provideErrorFeedback(this);
        ble.printStackTrace();
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

            if (getEditor(e).isEditable()) {
                return;
            }

            JEditorPane editor = getEditor(e);
            Caret caret = editor.getCaret();
            HTMLDocument doc = getHTMLDocument(editor);

            Element link = getNextLinkElement(doc, caret.getDot(), isForward());
            if (link != null) {
                moveHighlight(editor,
                              link.getStartOffset(), link.getEndOffset());
            }
        }
View Full Code Here

        installDefaults();
        LookAndFeel.installProperty(component, StringConstants.OPAQUE_PROPERTY,
                                    Boolean.TRUE);

        if (Utilities.isUIResource(component.getCaret())) {
            Caret caret = createCaret();
            component.setCaret(caret);
            caret.setBlinkRate(UIManager.getInt(getPropertyPrefix()
                                                  + ".caretBlinkRate"));
        }

        if (Utilities.isUIResource(component.getHighlighter())) {
            component.setHighlighter(createHighlighter());
View Full Code Here

        final Document doc = document;
       
        readLock(doc);
        try {
            Highlighter highlighter = component.getHighlighter();
            Caret caret = component.getCaret();
            if (component.isOpaque()) {
                paintBackground(g);
            }
            if (highlighter != null) {
                highlighter.paint(g);
            }
            Rectangle visibleRect = getVisibleEditorRect();
            if (visibleRect != null) {
                getRootView().setSize(visibleRect.width, visibleRect.height);
                getRootView().paint(g, visibleRect);
            }
            caret.paint(g);
        } finally {
            readUnlock(doc);
        }
    }
View Full Code Here

    public Dimension getMinimumSize(final JComponent c) {
        if (!(c instanceof JTextComponent)) {
            throw new IllegalArgumentException(Messages.getString("swing.77")); //$NON-NLS-1$
        }
        Dimension dim = super.getMinimumSize(c);
        Caret caret = ((JTextComponent)c).getCaret();
        if (caret != null && caret instanceof DefaultCaret) {
            dim.width += ((DefaultCaret)caret).width;
        }
        return dim;
    }
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.