Examples of Caret


Examples of javax.swing.text.Caret

    public Dimension getMinimumSize(final JComponent c) {
        if (!(c instanceof JTextComponent)) {
            throw new IllegalArgumentException("not text component");
        }
        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

Examples of javax.swing.text.Caret

        if (!(c instanceof JTextComponent)) {
            throw new IllegalArgumentException("not text component");
        }
        Dimension dim = super.getPreferredSize(c);

        Caret caret = ((JTextComponent)c).getCaret();
        if (caret != null && caret instanceof DefaultCaret) {
            dim.width += ((DefaultCaret)caret).width;
        }
        return dim;
    }
View Full Code Here

Examples of javax.swing.text.Caret

    private void updateTextActions(JTextComponent text) {
        if (text.getDocument() instanceof StyledDocument) {
            StyledDocument document = (StyledDocument) text.getDocument();
            boolean editable = text.isEditable();
           
            Caret caret = text.getCaret();
            int dot = caret.getDot();
            dot = dot > 0 ? dot - 1 : dot;
            Element elem = document.getCharacterElement(dot);
            AttributeSet set = elem.getAttributes();
           
            setBoldEnabled(editable);
View Full Code Here

Examples of javax.swing.text.Caret

  class LeftAction extends AbstractAction {

    public void actionPerformed(ActionEvent e) {
      if (isVisible()) {
        JTextComponent comp = ac.getTextComponent();
        Caret c = comp.getCaret();
        int dot = c.getDot();
        if (dot > 0) {
          c.setDot(--dot);
          // Ensure moving left hasn't moved us up a line, thus
          // hiding the popup window.
          if (comp.isVisible()) {
            if (lastLine!=-1) {
              doAutocomplete();
View Full Code Here

Examples of javax.swing.text.Caret

  class RightAction extends AbstractAction {

    public void actionPerformed(ActionEvent e) {
      if (isVisible()) {
        JTextComponent comp = ac.getTextComponent();
        Caret c = comp.getCaret();
        int dot = c.getDot();
        if (dot < comp.getDocument().getLength()) {
          c.setDot(++dot);
          // Ensure moving right hasn't moved us up a line, thus
          // hiding the popup window.
          if (comp.isVisible()) {
            if (lastLine!=-1) {
              doAutocomplete();
View Full Code Here

Examples of javax.swing.text.Caret

    //System.out.println("ENTRE: " + c.getReplacementText());
   
    JTextComponent textComp = getTextComponent();
    String alreadyEntered = c.getAlreadyEntered(textComp);
    hidePopupWindow();
    Caret caret = textComp.getCaret();

    int dot = caret.getDot();
    int len = alreadyEntered.length();
    int start = dot-len;
    String replacement = getReplacementText(c, textComp.getDocument(),
                        start, len);

    caret.setDot(start);
    caret.moveDot(dot);
    textComp.replaceSelection(replacement);
    /*
    Document doc = textComp.getDocument();
try {
    if (doc instanceof AbstractDocument) {
View Full Code Here

Examples of javax.swing.text.Caret

            }

            c.setMargin(margin);
        }

        Caret caret = c.getCaret();

        if (caret instanceof UIResource) {
            Object o = style.get(context, prefix + ".caretBlinkRate");

            if (o != null && o instanceof Integer) {
                Integer rate = (Integer) o;

                caret.setBlinkRate(rate.intValue());
            }
        }
    }
View Full Code Here

Examples of javax.swing.text.Caret

    return execute(new GuiQuery<JTextComponent>() {
      protected JTextComponent executeInEDT() {
        Component focusOwner = focusOwner();
        if (!(focusOwner instanceof JTextComponent)) return null;
        JTextComponent textComponent = (JTextComponent)focusOwner;
        Caret caret = textComponent.getCaret();
        if (caret == null || !caret.isVisible()) return null;
        caret.setVisible(false);
        return textComponent;
      }
    });
  }
View Full Code Here

Examples of javax.swing.text.Caret

  @RunsInEDT
  private static void showCaretOf(final JTextComponent textComponent) {
    execute(new GuiTask() {
      protected void executeInEDT() {
        Caret caret = textComponent.getCaret();
        if (caret != null) caret.setVisible(true);
      }
    });
  }
View Full Code Here

Examples of javax.swing.text.Caret

    }

    // 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
TOP
Copyright © 2018 www.massapi.com. 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.