Package javax.swing.text

Examples of javax.swing.text.Style


     *
     * @return the style.
     */
    public Style getStyle( String token) {
        if ( token != null) {
            Style result = (Style)styles.get( token);
           
            if ( result == null) {
                result = new NamedStyle();
                styles.put( token, result);
            }
View Full Code Here


   * @param styleDescription
   *            which style to use (may not be normal)
   * @return the colored style
   */
  private Style getStyle(final Color desiredColor, final String styleDescription) {
    final Style s = textPane.getStyle(styleDescription);
    StyleConstants.setForeground(s, desiredColor);
    return s;
  }
View Full Code Here

                        {
                            // no need to change the foreground color
                        }
                    }

                    Style style = null;
                    switch (responseLevel)
                    {
                        case 3 :
                            style = statsDoc.getStyle("Redirect");
                            break;
View Full Code Here

        stats.setBackground(getBackground());

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

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

        style = doc.addStyle("ClientError", null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
View Full Code Here

                        {
                            // no need to change the foreground color
                        }
                    }

                    Style style = null;
                    switch (responseLevel)
                    {
                        case 3 :
                            style = statsDoc.getStyle("Redirect");
                            break;
View Full Code Here

        stats.setBackground(getBackground());

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

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

        style = doc.addStyle("ClientError", null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
View Full Code Here

            }
        });
    }

    public void testGetStyle() {
        Style style;
        style = textPane.getStyle(StyleContext.DEFAULT_STYLE);
        assertEquals(StyleContext.DEFAULT_STYLE, style.getName());
        assertSame(textPane.getStyledDocument().getStyle(StyleContext.DEFAULT_STYLE), textPane
                .getStyle(StyleContext.DEFAULT_STYLE));
        textPane.addStyle("child", style);
        style = textPane.getStyle("child");
        assertEquals("child", style.getName());
        assertEquals(StyleContext.DEFAULT_STYLE, ((Style) style.getResolveParent()).getName());
        assertSame(textPane.getStyledDocument().getStyle("child"), textPane.getStyle("child"));
    }
View Full Code Here

        assertNotSame(child, anotherStyle);
        assertNotNull(anotherStyle);
    }

    public void testRemoveStyle() {
        Style parent = textPane.addStyle("parent", null);
        Style child = textPane.addStyle("child", parent);
        textPane.removeStyle("parent");
        assertNull(textPane.getStyle("parent"));
        assertEquals(2, child.getAttributeCount());
        assertNotNull(child.getResolveParent());
        assertNull(child.getAttribute("resolver"));
    }
View Full Code Here

        assertNull(child.getAttribute("resolver"));
    }

    public void testGetLogicalStyle() throws BadLocationException {
        textPane.getStyledDocument().insertString(11, "bold", attrs);
        Style style = textPane.addStyle("bold", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        textPane.setCaretPosition(1);
        style.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        textPane.setLogicalStyle(style);
        style = textPane.getLogicalStyle();
        textPane.setCaretPosition(3);
        assertSame(style, textPane.getLogicalStyle());
        assertTrue(((Boolean) style.getAttribute(StyleConstants.Bold)).booleanValue());
        attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        textPane.setParagraphAttributes(attrs, true);
        assertNull(textPane.getLogicalStyle());
    }
View Full Code Here

        StyleConstants.setItalic(attrs, true);
        textPane.getStyledDocument().insertString(4, "italic\n", attrs);
        StyleConstants.setItalic(attrs, false);
        StyleConstants.setBold(attrs, true);
        // Add style
        Style style = textPane.addStyle("bold", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        // Set style
        textPane.setCaretPosition(1);
        style.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        assertFalse(StyleConstants.isBold(textPane.getParagraphAttributes()));
        textPane.setLogicalStyle(style);
        style = textPane.getLogicalStyle();
        textPane.setCaretPosition(3);
        assertSame(style, textPane.getLogicalStyle());
        assertTrue(((Boolean) style.getAttribute(StyleConstants.Bold)).booleanValue());
        assertTrue(StyleConstants.isBold(textPane.getParagraphAttributes()));
        assertTrue(StyleConstants.isBold(getCharacterAttributes(1)));
        // Set paragraph attributes
        attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        textPane.setParagraphAttributes(attrs, true);
        assertNull(textPane.getLogicalStyle());
        // Set another style
        textPane.getStyledDocument().setCharacterAttributes(1, 1, attrs, true);
        assertFalse(StyleConstants.isUnderline(textPane.getParagraphAttributes()));
        assertFalse(StyleConstants.isUnderline(getCharacterAttributes(1)));
        style = textPane.addStyle("underline", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        style.addAttribute(StyleConstants.Underline, Boolean.TRUE);
        textPane.setLogicalStyle(style);
        assertNotNull(textPane.getLogicalStyle());
        assertEquals("underline", textPane.getLogicalStyle().getAttribute(
                StyleConstants.NameAttribute));
        assertTrue(StyleConstants.isUnderline(textPane.getParagraphAttributes()));
View Full Code Here

TOP

Related Classes of javax.swing.text.Style

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.