Package javax.swing.text

Examples of javax.swing.text.DefaultStyledDocument


   *
   * @param h
   */
  private void testExcellentBreakable(TestHarness h)
  {
    DefaultStyledDocument doc = new DefaultStyledDocument();
    Element el = doc.new BranchElement(null, null);
    TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
    // Create one row and fill it with one oversized testview.
    TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
    fv.replace(0, 0, new View[]{row});
View Full Code Here


   *
   * @param h
   */
  private void testForceBreakable(TestHarness h)
  {
    DefaultStyledDocument doc = new DefaultStyledDocument();
    Element el = doc.new BranchElement(null, null);
    TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
    // Create one row and fill it with one oversized testview.
    TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
    fv.replace(0, 0, new View[]{row});
View Full Code Here

   * a single child element (0, 21).
   */
  void testInsertEqualAttributes(TestHarness harness)
  {
    harness.checkPoint("insertEqualAttributes");
    DefaultStyledDocument doc = new DefaultStyledDocument();
    prepareDocument(doc);
    SimpleAttributeSet atts = new SimpleAttributeSet();

    // Insert 5 characters at pos 5.
    try
      {
        doc.insertString(5, "12345", atts);
      }
    catch (BadLocationException ex)
      {
        harness.debug(ex);
      }

    // Now we should have the following child elements below the single
    // root and single paragraph: (0, 5) (5, 10) (10, 21)
    Element root = doc.getDefaultRootElement();
    harness.check(root.getStartOffset(), 0);
    harness.check(root.getEndOffset(), 21);
    harness.check(root.getElementCount(), 1);

    Element par = root.getElement(0);
View Full Code Here

   * @param harness the test harness to use
   */
  void testInsertModifiedAttributes(TestHarness harness)
  {
    harness.checkPoint("insertModifiedAttributes");
    DefaultStyledDocument doc = new DefaultStyledDocument();
    prepareDocument(doc);
    SimpleAttributeSet atts = new SimpleAttributeSet();

    // Insert 5 (different from the rest) characters at pos 5.
    StyleConstants.setForeground(atts, Color.RED);
    try
      {
        doc.insertString(5, "12345", atts);
      }
    catch (BadLocationException ex)
      {
        harness.debug(ex);
      }

    // Now we should have the following child elements below the single
    // root and single paragraph: (0, 5) (5, 10) (10, 21)
    Element root = doc.getDefaultRootElement();
    harness.check(root.getStartOffset(), 0);
    harness.check(root.getEndOffset(), 21);
    harness.check(root.getElementCount(), 1);

    Element par = root.getElement(0);
View Full Code Here

   * element that has the same spans.
   */
  void testInsertNewline(TestHarness harness)
  {
    harness.checkPoint("insertNewline");
    DefaultStyledDocument doc = new DefaultStyledDocument();
    prepareDocument(doc);
    SimpleAttributeSet atts = new SimpleAttributeSet();

    // Insert 5 (different from the rest) characters at pos 5.
    try
      {
        doc.insertString(5, "abcde\nfghij", atts);
      }
    catch (BadLocationException ex)
      {
        harness.debug(ex);
      }

    // Now we should have two paragraphs (0, 11)(11, 27)
    Element root = doc.getDefaultRootElement();
    harness.check(root.getStartOffset(), 0);
    harness.check(root.getEndOffset(), 27);
    harness.check(root.getElementCount(), 2);

    Element par1 = root.getElement(0);
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    protected Document createDefaultDocument() {
        return new DefaultStyledDocument();
    }
View Full Code Here

    public void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context)
            throws IOException, SAXException, TikaException {
        try {
            DefaultStyledDocument sd = new DefaultStyledDocument();
            new RTFEditorKit().read(stream, sd, 0);

            XHTMLContentHandler xhtml =
                new XHTMLContentHandler(handler, metadata);
            xhtml.startDocument();
            xhtml.element("p", sd.getText(0, sd.getLength()));
            xhtml.endDocument();
        } catch (BadLocationException e) {
            throw new TikaException("Error parsing an RTF document", e);
        }
    }
View Full Code Here

  /**
   * @return A styled document that can be used to format a MWPane.
   */
  public static StyledDocument createDocument() {
    initializeStyles();
    StyledDocument document = new DefaultStyledDocument(styleContext);
    return document;
  }
View Full Code Here

        FileWriter writer = null;
        try {
            reader = new FileReader(filename);
            writer = new FileWriter(tempFile);

            DefaultStyledDocument doc = new DefaultStyledDocument();

            new RTFEditorKit().read(reader, doc, 0);

            writer.write(doc.getText(0, doc.getLength()));
        }
        catch (BadLocationException ble) {
            log.fatal("parse() failed with BadLocationException", ble);
        }
        catch (IOException ioe) {
View Full Code Here

          Point pt = new Point(ev.getX(), ev.getY());
          int pos = editor.viewToModel(pt);
          if (pos >= 0) {
            Document eDoc = editor.getDocument();
            if (eDoc instanceof DefaultStyledDocument) {
              DefaultStyledDocument hdoc =
                (DefaultStyledDocument) eDoc;
              Element e = hdoc.getCharacterElement(pos);
              AttributeSet a = e.getAttributes();
              AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A);
              String href = null;
              if (tagA!=null){
                  href = (String)tagA.getAttribute(HTML.Attribute.HREF);
View Full Code Here

TOP

Related Classes of javax.swing.text.DefaultStyledDocument

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.