Package javax.swing.text

Examples of javax.swing.text.DefaultStyledDocument


    public void testProPertyChange_FontFamilyName() {
        Style style = textPane.getStyle(StyleContext.DEFAULT_STYLE);
        textPane.setFont(font);
        assertFalse(font.getFamily().equals(style.getAttribute(StyleConstants.FontFamily)));
        assertEquals(font.getName(), style.getAttribute(StyleConstants.FontFamily));
        StyledDocument newDoc = new DefaultStyledDocument();
        Style newStyle = newDoc.getStyle(StyleContext.DEFAULT_STYLE);
        textPane.setDocument(newDoc);
        assertFalse(font.getFamily().equals(newStyle.getAttribute(StyleConstants.FontFamily)));
        assertEquals(font.getName(), newStyle.getAttribute(StyleConstants.FontFamily));
    }
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

        writer.incrIndent();
    }

    private void createDocument() throws Exception {
        super.setUp();
        doc = new DefaultStyledDocument();
        MutableAttributeSet boldStyle = new SimpleAttributeSet();
        StyleConstants.setBold(boldStyle, true);
        MutableAttributeSet italicStyle = new SimpleAttributeSet();
        StyleConstants.setItalic(italicStyle, true);
        MutableAttributeSet colorStyle = new SimpleAttributeSet();
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

        assertNull(null);
        assertEquals("TextPaneUI", textPane.getUIClassID());
    }

    public void testSetDocument() {
        StyledDocument doc = new DefaultStyledDocument();
        textPane.setDocument(doc);
        assertSame(doc, textPane.getDocument());
        testExceptionalCase(new IllegalArgumentCase() {
            @Override
            public void exceptionalAction() throws Exception {
View Full Code Here

            }
        });
    }

    public void testSetStyledDocument() {
        StyledDocument doc = new DefaultStyledDocument();
        textPane.setDocument(doc);
        assertSame(doc, textPane.getDocument());
        testExceptionalCase(new IllegalArgumentCase() {
            @Override
            public void exceptionalAction() throws Exception {
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

    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

        getVerticalScrollBar().setUnitIncrement(10);

        initActions();

        DefaultStyledDocument doc = new DefaultStyledDocument();
        doc.setDocumentFilter(new GroovyFilter(doc));
        textEditor.setDocument(doc);

        // add a document listener, to hint whether the line number gutter has to be repainted
        // when the number of lines changes
        doc.addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
            }

            public void removeUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
            }

            public void changedUpdate(DocumentEvent documentEvent) {
                documentChangedSinceLastRepaint = true;
                int width = 3 * Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12);
                numbersPanel.setPreferredSize(new Dimension(width, width));
            }
        });

        // create and add the undo/redo manager
        this.undoManager = new TextUndoManager();
        doc.addUndoableEditListener(undoManager);

        // add the undo actions
        undoManager.addPropertyChangeListener(undoAction);
        undoManager.addPropertyChangeListener(redoAction);

        doc.addDocumentListener(undoAction);
        doc.addDocumentListener(redoAction);

        InputMap im = textEditor.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK, false);
        im.put(ks, StructuredSyntaxResources.UNDO);
        ActionMap am = textEditor.getActionMap();
View Full Code Here

     *
     * @throws javax.swing.text.BadLocationException
     */
    @Test
    public void testGetIndentString() throws BadLocationException {
        DefaultStyledDocument document = new DefaultStyledDocument();
        document.putProperty(Language.class, MarkdownTokenId.language());
        document.insertString(0, "    * list\n", null); // white space
        String result = MarkdownDocUtil.getIndentString(document, 10);
        assertEquals("    ", result);

        document.insertString(0, "  * list\n", null); // tab space
        result = MarkdownDocUtil.getIndentString(document, 7);
        assertEquals("  ", result);

        document.insertString(0, "      * list\n", null); // white space and tab space
        result = MarkdownDocUtil.getIndentString(document, 11);
        assertEquals("      ", result);

        document.insertString(0, "* list\n", null); // no indent
        result = MarkdownDocUtil.getIndentString(document, 6);
        assertEquals("", result);
    }
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.