Example usage for javax.swing.text StyleConstants ComponentElementName

List of usage examples for javax.swing.text StyleConstants ComponentElementName

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants ComponentElementName.

Prototype

String ComponentElementName

To view the source code for javax.swing.text StyleConstants ComponentElementName.

Click Source Link

Document

Name of elements used to represent components.

Usage

From source file:Main.java

public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new WrapLabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return new ParagraphView(elem);
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new BoxView(elem, View.Y_AXIS);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }/*from www. j a  va 2s.c o m*/
    }
    return new LabelView(elem);
}

From source file:Main.java

@Override
public View create(Element elem) {
    View result = null;/*  ww  w.j  a  v a2s. com*/
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            result = new MyLabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            result = new ParagraphView(elem);
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            result = new BoxView(elem, View.Y_AXIS);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            result = new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            result = new IconView(elem);
        } else {
            result = new LabelView(elem);
        }
    } else {
        result = super.create(elem);
    }
    return result;
}

From source file:Main.java

public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new MyLabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return new ParagraphView(elem);
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new BoxView(elem, View.Y_AXIS);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }//w w  w. ja va  2s . co m
    }
    return new LabelView(elem);
}

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.
 *///from  w w w.  j  ava  2 s.co  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);
        }
    }
}