Package javax.swing.text

Examples of javax.swing.text.StyledDocument


        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);
            e.printStackTrace();
View Full Code Here


        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);
            e.printStackTrace();
        }
View Full Code Here

        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);
            e.printStackTrace();
View Full Code Here

        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

        stats = new JTextPane();
        stats.setEditable(false);
        stats.setBackground(backGround);

        // Add styles to use for different types of status messages
        StyledDocument doc = (StyledDocument) stats.getDocument();

        Style style = doc.addStyle(STYLE_REDIRECT, null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle(STYLE_CLIENT_ERROR, null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);

        style = doc.addStyle(STYLE_SERVER_ERROR, null);
        StyleConstants.setForeground(style, SERVER_ERROR_COLOR);

        paneRaw = GuiUtils.makeScrollPane(stats);
        paneRaw.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
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

        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

        stats = new JTextPane();
        stats.setEditable(false);
        stats.setBackground(backGround);

        // Add styles to use for different types of status messages
        StyledDocument doc = (StyledDocument) stats.getDocument();

        Style style = doc.addStyle(STYLE_REDIRECT, null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle(STYLE_CLIENT_ERROR, null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);

        style = doc.addStyle(STYLE_SERVER_ERROR, null);
        StyleConstants.setForeground(style, SERVER_ERROR_COLOR);

        paneRaw = GuiUtils.makeScrollPane(stats);
        paneRaw.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
View Full Code Here

      String text;
     
      // Find editor
      DataObject dObj = DataObject.find(file);
      LineCookie cLine = null;
      StyledDocument currentDocument = null;
      if (null != dObj) {
    EditorCookie cEditor = dObj.getCookie(EditorCookie.class);
    cLine = dObj.getCookie(LineCookie.class);
    currentDocument = cEditor.getDocument();
    // Get text
    if (null != currentDocument) {
        text = currentDocument.getText(0, currentDocument.getLength());
    } else {
        text = getContent(file);
    }
      } else {
    text = getContent(file);
View Full Code Here

       
        setStyle();
    }

    private void setStyle() {
        StyledDocument doc = this.area.getStyledDocument();
        Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
        switch (type) {
    case ERROR:
      style = doc.addStyle("error",defaultStyle);
      StyleConstants.setForeground(style,Color.RED);
      break;
    case NORMAL:
      style = doc.addStyle("normal",defaultStyle);
      StyleConstants.setForeground(style,Color.BLACK);
      break;
    case CONSOLE:
      style = doc.addStyle("console",defaultStyle);
      StyleConstants.setForeground(style,Color.BLUE);
      break;
    default:
      break;
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.StyledDocument

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.