Package javax.swing.text

Examples of javax.swing.text.Document


        if ( this.isVisible() ) {
            backward = this.backwordRadioButton.isSelected();
        }

        int startPosition = this.textComponent.getCaretPosition();
        Document doc = this.textComponent.getDocument();
        int len = doc.getLength();

        String content = "";
        try {
            if (backward) {
                content = doc.getText(0, startPosition > 1 ? startPosition - 1 : 0);
                startPosition = 0;
            } else if ( this.isVisible() && this.entireScopeRadioButton.isSelected() ) {
                content = doc.getText(0, len);
                startPosition = 0;
            } else {
                content = doc.getText(startPosition, len - startPosition);
            }
        } catch (BadLocationException e) {
            e.printStackTrace();
            return false;
        }
View Full Code Here


   
    URLSelection getIndicatedURL(Point pt, JEditorPane editor) {
  int pos = editor.viewToModel(pt);
  if (pos >= 0) {
      try {
    Document doc = editor.getDocument();
    int docLength = doc.getLength();
   
    int wordStart = 0;
   
    int startOffset = pos;
    int relativePosition;
    boolean startFound = false;
   
    while ( ! startFound ) {
        startOffset = startOffset - lineLength;
        relativePosition = lineLength;
       
        if (startOffset < 0) {
      relativePosition = relativePosition + startOffset;
      startOffset = 0;
        }
       
        String possibleText = doc.getText(startOffset, relativePosition);
        char[] charArray = possibleText.toCharArray();
        for (int i = relativePosition - 1; (! startFound && i >= 0 ) ; i--) { 
      if (Character.isWhitespace(charArray[i]) || charArray[i] == '(' || charArray[i] == ')' || charArray[i] == '<' || charArray[i] == '>') {
          startFound = true;
          wordStart = startOffset + i + 1;
      }
        }
       
        if (startOffset == 0)
      startFound = true;
    }
   
    int wordEnd = docLength - 1;
    startOffset = pos - 1 - lineLength;
    int length = lineLength;
    boolean endFound = false;
   
    while ( ! endFound ) {
        startOffset = startOffset + lineLength;
       
        if (startOffset + lineLength > docLength) {
      length = docLength - startOffset;
        }
       
        String possibleText = doc.getText(startOffset, length);
        char[] charArray = possibleText.toCharArray();
        for (int i = 0; (! endFound && i < length ) ; i++) { 
      if (Character.isWhitespace(charArray[i]) || charArray[i] == '(' || charArray[i] == ')' || charArray[i] == '<' || charArray[i] == '>') {
          endFound = true;
          wordEnd = startOffset + i - 1;
      }
        }
       
        if (startOffset + length >= docLength)
      endFound = true;
    }
   
    int wordLength = wordEnd - wordStart + 1;
    if (wordLength > 3) {
        String word = doc.getText(wordStart, wordLength);
        if (word.indexOf("://") != -1) {
      try {
          URL urlSelected = new URL(word);
         
          return new URLSelection(editor, urlSelected, wordStart, wordEnd);
View Full Code Here

   * Insert a header.
   *
   * @param header
   */
  protected void insertHeader(final String header) {
    final Document doc = textPane.getDocument();
    try {
      if (header.length() > 0) {
        doc.insertString(doc.getLength(), "<" + header + "> ",
            textPane.getStyle("header"));
      }
    } catch (final BadLocationException e) {
      logger.error("Couldn't insert initial text.", e);
    }
View Full Code Here

   * Insert time stamp.
   *
   * @param header time stamp
   */
  protected void insertTimestamp(final String header) {
    final Document doc = textPane.getDocument();
    try {
      if (header.length() > 0) {
        doc.insertString(doc.getLength(), header,
            textPane.getStyle("timestamp"));
      }
    } catch (final BadLocationException e) {
      logger.error("Couldn't insert initial text.", e);
    }
View Full Code Here

   * @param type
   */
  protected void insertText(final String text, final NotificationType type) {
    final Color color = type.getColor();
    final String styleDescription = type.getStyleDescription();
    final Document doc = textPane.getDocument();

    try {
      final FormatTextParser parser =  new FormatTextParser() {
        @Override
        public void normalText(final String txt) throws BadLocationException {
          doc.insertString(doc.getLength(), txt, getStyle(color,styleDescription));
        }

        @Override
        public void colorText(final String txt) throws BadLocationException {
          doc.insertString(doc.getLength(), txt, textPane.getStyle("bold"));
        }
      };
      parser.format(text);
    } catch (final Exception e) {
      // BadLocationException
View Full Code Here

  /**
   * Start a new line.
   */
  protected void insertNewline() {
    final Document doc = textPane.getDocument();
    try {
      doc.insertString(doc.getLength(), "\r\n", getStyle(Color.black, "normal"));
    } catch (final BadLocationException e) {
      logger.error("Couldn't insert initial text.", e);
    }
  }
View Full Code Here

    PpiComboBox() {
        setEditable(true);
        addActionListener(this);

        JTextComponent text = getTextComponent();
        Document doc = text.getDocument();
        doc.addDocumentListener(this);

        Font font = (new JTextField()).getFont();
        setFont(font);
        text.setFont(font);
       
View Full Code Here

    private Listener listener;

    ScaleTextField() {
        setInputVerifier(new NumberVerifier());
        Document doc = getDocument();
        doc.addDocumentListener(this);
        setFixedSize();
        setHorizontalAlignment(RIGHT);
        addFocusListener(FocusSelector);
        registerKeyboardActions();
    }
View Full Code Here

    private Listener listener;
    private NumberFormat format;

    DimensionTextField() {
        setInputVerifier(new NumberVerifier());
        Document doc = getDocument();
        doc.addDocumentListener(this);
        format = InchFormat;
        setFixedSize();
        setHorizontalAlignment(RIGHT);
        addFocusListener(FocusSelector);
        registerKeyboardActions();
View Full Code Here

        setRows(clipRowCount(getRows()));
    }

    @Override
    public void setDocument(Document doc) {
        Document document = getDocument();
        if (document != null && _listener != null) {
            document.removeDocumentListener(_listener);
        }
        super.setDocument(doc);
        if (doc != null) {
            if (_listener == null) {
                _listener = new ResizingDocumentListener();
View Full Code Here

TOP

Related Classes of javax.swing.text.Document

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.