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()));