Package javax.swing.text

Examples of javax.swing.text.DefaultStyledDocument


        boolean oldVisible = dialog.isVisible();
        JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
        int oldPosition = verticalScrollBar.getValue();
        int oldCaretPosition = textPane.getCaretPosition();

        StyledDocument document = new DefaultStyledDocument();
        SimpleAttributeSet attributeSet = new SimpleAttributeSet();
        StyleConstants.setBold(attributeSet, true);
        StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_JUSTIFIED);
        try {
            document.insertString(document.getLength(), text, attributeSet);
        }
        catch (BadLocationException e) {
            // Normally cannot happen.
            textPane.setText(text);
        }
View Full Code Here


    if (syntaxHighlighting) {
      try {
        return new ParserDocument(parser.getSyntaxKeyWords());
      }
      catch (Throwable e) {
        return new DefaultStyledDocument();
      }
    }
    else {
      return new DefaultStyledDocument();
    }
  }
View Full Code Here

  public MapTextPane(MapFrame p) {
    super();
    parentDlg = p;
      
    // Make one of each kind of document.
    doc = new DefaultStyledDocument();
        setDocument(doc)
       
        class KeyStrokeListener implements KeyListener
            public void keyPressed(KeyEvent e){ 
                switch(e.getKeyCode()){ 
View Full Code Here

   * Instantiates a new cPS text pane.
   */
  public CPSTextPane() {
    super();
    // Make one of each kind of document.
    doc = new DefaultStyledDocument();
        setDocument(doc)
       
        class KeyStrokeListener implements KeyListener
            public void keyPressed(KeyEvent e){ 
                switch(e.getKeyCode()){ 
View Full Code Here

            assertEquals(0, attr.getAttributeCount());
        }
    }

    public void testTranslateHTMLToCSSStyledDocument() throws Exception {
        StyledDocument doc = new DefaultStyledDocument();
        doc.insertString(0, "line1\nline2", null);

        MutableAttributeSet mas = new SimpleAttributeSet();
        mas.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
        mas.addAttribute(HTML.Attribute.TEXT, "black");
        doc.setParagraphAttributes(0, 1, mas, false);

        AbstractElement branch =
            (AbstractElement)doc.getDefaultRootElement().getElement(0);
        assertEquals("paragraph", branch.getName());
        assertTrue(branch instanceof BranchElement);
        assertSame(BranchElement.class, branch.getClass());

View Full Code Here

    public void testReplaceSelectionWithAttributes() {
        if (true) {
            throw new UnsupportedOperationException("Not implemented");
        }
        AbstractDocument doc = new DefaultStyledDocument();
        SimpleAttributeSet as1 = new SimpleAttributeSet();
        as1.addAttribute("key1", "value1");
        SimpleAttributeSet as2 = new SimpleAttributeSet();
        as2.addAttribute("key2", "value2");
        try {
            doc.insertString(0, "testReplaceSelection", as1);
            doc.insertString(4, "INSERT", as2);
        } catch (final BadLocationException e) {
            assertFalse("unexpected exception :" + e.getMessage(), true);
        }
        //temporarily commented-out: HTMLEditorKit not implemented
        //jep.setEditorKit(new RTFEditorKit());
        jep.setEditorKit(new StyledEditorKit());
        jep.setDocument(doc);
        jep.setSelectionStart(6);
        jep.setSelectionEnd(7);
        jep.replaceSelection("YYY");
        for (int i = 0; i < doc.getLength(); i++) {
            AttributeSet as = getAttributeSetByIndex(doc, i);
            if (i > 3 && i < 12) {
                assertEquals(as2, as);
            } else {
                assertEquals(as1, as);
View Full Code Here

        assertSame(paragraph, view.getElement());
        assertNotSame(paragraph.getAttributes(), view.getAttributes());
    }

    public void testInlineViewUponStyledDocument() throws BadLocationException {
        final StyledDocument styledDoc = new DefaultStyledDocument();
        styledDoc.insertString(0, "a simple paragraph", null);
        inline = styledDoc.getCharacterElement(1);
        testExceptionalCase(new ClassCastCase() {
            public void exceptionalAction() throws Exception {
                new InlineView(inline);
            }

            public String expectedExceptionMessage() {
                return styledDoc.getClass().getName();
            }
        });
    }
View Full Code Here

    public void testWrite() throws Exception {
        StringWriter writer = new StringWriter();
        final String content = "Hello, World!";
        final int start = 1;
        final int end = 4;
        DefaultStyledDocument doc = new DefaultStyledDocument();
        doc.insertString(0, content, null);

        editorKit.write(writer, doc, start, end);
        String output = writer.toString();
        assertTrue(output.indexOf("<html>") != -1);
        if (isHarmony()) {
            assertFalse(output.indexOf(content) != -1);
            assertTrue(output.indexOf(content.substring(start, end)) != -1);
        }

        writer = new StringWriter();
        doc = (HTMLDocument)editorKit.createDefaultDocument();
        doc.insertString(0, content, null);
        editorKit.write(writer, doc, start, end);
        output = writer.toString();
        assertTrue(output.indexOf("<html>") != -1);
        assertFalse(output.indexOf(content) != -1);
        assertTrue(output.indexOf(content.substring(start, end)) != -1);
View Full Code Here

    frameParent = frame;
    this.isExitButton = isExitButton;

    getContentPane().setLayout(new BorderLayout());
    StyleContext m_context;
    DefaultStyledDocument m_doc;
    RTFEditorKit m_kit;
    m_monitor = new JTextPane();
    /*
     *  m_kit = new RTFEditorKit();
     *  m_monitor.setEditorKit(m_kit);
View Full Code Here

                              String type,
                              String encoding) throws IOException {

        try {
            RTFEditorKit rek = new RTFEditorKit();
            DefaultStyledDocument doc = new DefaultStyledDocument();
            rek.read(stream, doc, 0);
            String text = doc.getText(0, doc.getLength());
            return new StringReader(text);
        } catch (BadLocationException e) {
            throw new IOException(e.getMessage());
        } finally {
            stream.close();
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.