Examples of Caret


Examples of javax.swing.text.Caret

    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

Examples of javax.swing.text.Caret

    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

Examples of javax.swing.text.Caret

    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

Examples of javax.swing.text.Caret

   * @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

Examples of javax.swing.text.Caret

                view.getStartOffset();
          break;
        }
        RSyntaxTextArea target = (RSyntaxTextArea)view.
                          getContainer();
        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

Examples of javax.swing.text.Caret

   * @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 {

      // Remove old highlights
      removeHighlights();

      // 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

Examples of javax.swing.text.Caret

    // 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;
        c.setDot(pos);
        c.moveDot(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);
        }
        c.setDot(regExPos.x);
        c.moveDot(regExPos.y);
        return true;
      }
    }

    // No match.
View Full Code Here

Examples of org.eclipse.swt.widgets.Caret

      setCaretColour();
    }
  }

  private void setCaretColour() {
    Caret caret = control.getCaret();
    Rectangle bounds = caret.getBounds();
    int width = bounds.width;
    int height = bounds.height;
    caret = new Caret(control, SWT.NONE);
    Display display = Display.getCurrent();
    // System.out.printf("caret colour: %s %d %d\n", globalColour("caret"), width, height);
    String caretColourString = bareGlobalColour("caret");
    Color caretColour = ColourUtil.getColour(caretColourString);
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    String backgroundColourString = globalBackground();
    int red = Integer.parseInt(backgroundColourString.substring(1, 3), 16) ^
          Integer.parseInt(caretColourString.substring(1, 3), 16);
    int green = Integer.parseInt(backgroundColourString.substring(3, 5), 16) ^
            Integer.parseInt(caretColourString.substring(3, 5), 16);
    int blue = Integer.parseInt(backgroundColourString.substring(5, 7), 16) ^
            Integer.parseInt(caretColourString.substring(5, 7), 16);
    PaletteData palette = new PaletteData (
      new RGB [] {
        new RGB (0, 0, 0),
        new RGB (red, green, blue),
        new RGB (0xFF, 0xFF, 0xFF),
      });
    ImageData maskData = new ImageData (1, height, 2, palette);
    for (int y=0; y < height; y++)
      maskData.setPixel(0, y, 1);
    Image image = new Image (display, maskData);
    caret.setImage(image);
    control.setCaret(caret);
  }
View Full Code Here

Examples of org.eclipse.swt.widgets.Caret

      toggleOverwriteMode();
    fIsOverwriteModeEnabled= enable;
  }

  private Caret createOverwriteCaret(StyledText styledText) {
    Caret caret= new Caret(styledText, SWT.NULL);
    GC gc= new GC(styledText);
    // XXX this overwrite box is not proportional-font aware
    // take 'a' as a medium sized character
    Point charSize= gc.stringExtent("a"); //$NON-NLS-1$
   
    // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
    caret.setSize(charSize.x, styledText.getLineHeight());
    caret.setFont(styledText.getFont());
   
    gc.dispose();

    return caret;
  }
View Full Code Here

Examples of org.eclipse.swt.widgets.Caret

    return caret;
  }

  private Caret createInsertCaret(StyledText styledText) {
    Caret caret= new Caret(styledText, SWT.NULL);

    // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
    caret.setSize(getCaretWidthPreference(), styledText.getLineHeight());
    caret.setFont(styledText.getFont());
   
    return caret;
  }
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.