Package javax.swing.text

Examples of javax.swing.text.Document


            assertFalse("Unexpected exception :", true);
        }
        assertEquals("text/rtf", jep.getContentType());
        String docContent = null;
        try {
            Document doc = jep.getDocument();
            docContent = doc.getText(0, doc.getLength());
        } catch (BadLocationException e) {
            assertFalse("Unexpected exception :", true);
        }
        assertEquals("blablabla\n", docContent);
    }
View Full Code Here


    public void read(final InputStream stream, final Object type) throws IOException {
        if (type instanceof String) {
            setContentType((String) type);
        }
        try {
            Document doc = getDocument();
            doc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, Boolean.TRUE);
            editorKit.read(new InputStreamReader(stream), doc, 0);
        } catch (BadLocationException e) {
        }
    }
View Full Code Here

            new DefaultEditorKit.BeepAction().actionPerformed(null);
            return;
        }
        int start = getSelectionStart();
        int end = getSelectionEnd();
        Document doc = getDocument();
        try {
            if (start != end) {
                doc.remove(start, end - start);
            }
            //May be these attributes placed in Document ????
            AttributeSet as = (editorKit instanceof StyledEditorKit) ? ((StyledEditorKit) editorKit)
                    .getInputAttributes()
                    : null;
            if (s != null) {
                doc.insertString(start, s, as);
            }
        } catch (BadLocationException e) {
        }
    }
View Full Code Here

        } catch (BadLocationException e) {
        }
    }

    public void scrollToReference(final String ref) {
         Document doc = getDocument();
        if (ref == null || !(doc instanceof HTMLDocument)) {
            return;
        }
        HTMLDocument.Iterator it = ((HTMLDocument)doc).getIterator(HTML.Tag.A);
        int offset = 0;
View Full Code Here

            throw new IOException(Messages.getString("swing.03","Page")); //$NON-NLS-1$ //$NON-NLS-2$
        }

        String url = page.toString();
        String baseUrl = getBaseURL(url);
        Document oldDoc = getDocument();
        if (baseUrl != null
            && oldDoc != null
            && baseUrl.equals(oldDoc
                .getProperty(Document.StreamDescriptionProperty))) {

            scrollToReference(page.getRef());
            return;
        }
        InputStream stream = getStream(page);
        if (stream == null) {
            return;
        }
        Document newDoc = editorKit.createDefaultDocument();
        // Perhaps, it is reasonable only for HTMLDocument...
        if (newDoc instanceof HTMLDocument) {
            newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
            newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
                               new Boolean(false));
            try {
                ((HTMLDocument)newDoc).setBase(new URL(baseUrl));
            } catch (IOException e) {
            }
View Full Code Here

    public IntegerField(double value, int columns) {
        super(columns);
        format.setParseIntegerOnly(true);

        Document doc = new FormattedDocument(format);
        setDocument(doc);
        doc.addDocumentListener(new DocumentListener() {
                public void insertUpdate(DocumentEvent e) {
                    IntegerField.this.getValue();
                }

                public void removeUpdate(DocumentEvent e) {
View Full Code Here

      }
      b.append(')');

      try
      {
        final Document document = functionTextArea.getDocument();
        final int selectionStart = functionTextArea.getSelectionStart();
        document.remove(selectionStart, functionTextArea.getSelectionEnd() - selectionStart);
        document.insertString(functionTextArea.getCaretPosition(), b.toString(), null);
      }
      catch (BadLocationException e1)
      {
        e1.printStackTrace();
      }
View Full Code Here

     */
    public void propertyChange(final PropertyChangeEvent evt)
    {
      if (FormValidator.DOCUMENT_PROPERTY_NAME.equals(evt.getPropertyName()))
      {
        final Document olddoc = (Document) evt.getOldValue();
        olddoc.removeDocumentListener(this);
        final Document newdoc = (Document) evt.getOldValue();
        newdoc.addDocumentListener(this);
      }
    }
View Full Code Here

  public Object convert(final ReportElement source, final Object value)
  {
    try
    {
      final Document doc = RichTextConverterUtilities.parseDocument(editorKit, value);
      if (doc == null)
      {
        return value;
      }

      final Element element = process(doc.getDefaultRootElement());
      return RichTextConverterUtilities.convertToBand(StyleKey.getDefinedStyleKeys(), source, element);
    }
    catch (Exception e)
    {
      return value;
View Full Code Here

    }

    final InputStream inputStream = RichTextConverterUtilities.convertToStream(value);
    if (inputStream != null)
    {
      final Document doc = editorKit.createDefaultDocument();
      editorKit.read(inputStream, doc, 0);
      return doc;
    }

    final Reader reader = RichTextConverterUtilities.convertToReader(value);
    if (reader != null)
    {
      final Document doc = editorKit.createDefaultDocument();
      editorKit.read(reader, doc, 0);
      return doc;
    }

    return null;
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.