List of usage examples for javax.swing.text.html StyleSheet getStyle
public Style getStyle(String nm)
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Adds a custom component at the end of the conversation. * * @param component the component to add at the end of the conversation. *///w w w . j ava 2 s. c o m public void addComponent(ChatConversationComponent component) { synchronized (scrollToBottomRunnable) { StyleSheet styleSheet = document.getStyleSheet(); Style style = styleSheet.addStyle(StyleConstants.ComponentElementName, styleSheet.getStyle("body")); // The image must first be wrapped in a style style.addAttribute(AbstractDocument.ElementNameAttribute, StyleConstants.ComponentElementName); TransparentPanel wrapPanel = new TransparentPanel(new BorderLayout()); wrapPanel.add(component, BorderLayout.NORTH); style.addAttribute(StyleConstants.ComponentAttribute, wrapPanel); style.addAttribute(Attribute.ID, ChatHtmlUtils.MESSAGE_TEXT_ID); SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); style.addAttribute(ChatHtmlUtils.DATE_ATTRIBUTE, sdf.format(component.getDate())); scrollToBottomIsPending = true; // We need to reinitialize the last message ID, because we don't // want components to be taken into account. lastMessageUID = null; // Insert the component style at the end of the text try { document.insertString(document.getLength(), "ignored text", style); } catch (BadLocationException e) { logger.error("Insert in the HTMLDocument failed.", e); } } }