package org.limewire.ui.swing.components; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JPanel; import net.miginfocom.swing.MigLayout; /** * A simple component that can be used to inset a text label with an arbitrary number of components. * * <p>Components are loaded in order in the places of the string marked by {c}. * * <p>Example String: * <p>"the label generated by this string will be {c} embedded with its first component at the point with the symbol" * * TODO: THIS IS NOT YET FULLY TRANSLATION SAFE!! * * Obvious limitation is components use tag {c} and their order, if translated, can not be changed * from this. In future, if needed, this could be extended to use {cX} where X is the component number. * This would be much more translation friendly but currently this component is only used for 2 bt settings. */ public class EmbeddedComponentLabel extends JPanel { public EmbeddedComponentLabel(String message, Component... components) { super(new MigLayout("insets 0, gap 0")); setOpaque(false); String[] labelParts = message.split("\\{c\\}"); int i = 0; for ( String part : labelParts ) { add(new JLabel(part)); if (i < components.length && components[i] != null) { add(components[i]); i++; } } } }