Example usage for java.awt.font TextAttribute UNDERLINE_ON

List of usage examples for java.awt.font TextAttribute UNDERLINE_ON

Introduction

In this page you can find the example usage for java.awt.font TextAttribute UNDERLINE_ON.

Prototype

Integer UNDERLINE_ON

To view the source code for java.awt.font TextAttribute UNDERLINE_ON.

Click Source Link

Document

Standard underline.

Usage

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 * Returns a java.awt.Font instance by converting a JRFont instance.
 * Mostly used in combination with third-party visualization packages such as JFreeChart (for chart themes).
 * Unless the font parameter is null, this method always returns a non-null AWT font, regardless whether it was
 * found in the font extensions or not. This is because we do need a font to draw with and there is no point
 * in raising a font missing exception here, as it is not JasperReports who does the drawing. 
 *//*ww w  .  ja v  a 2 s.c  o  m*/
public static Font getAwtFont(JRFont font, Locale locale) {
    if (font == null) {
        return null;
    }

    // ignoring missing font as explained in the Javadoc
    Font awtFont = getAwtFontFromBundles(font.getFontName(),
            ((font.isBold() ? Font.BOLD : Font.PLAIN) | (font.isItalic() ? Font.ITALIC : Font.PLAIN)),
            font.getFontSize(), locale, true);

    if (awtFont == null) {
        awtFont = new Font(getAttributesWithoutAwtFont(new HashMap<Attribute, Object>(), font));
    } else {
        // add underline and strikethrough attributes since these are set at
        // style/font level
        Map<Attribute, Object> attributes = new HashMap<Attribute, Object>();
        if (font.isUnderline()) {
            attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        }
        if (font.isStrikeThrough()) {
            attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
        }

        if (!attributes.isEmpty()) {
            awtFont = awtFont.deriveFont(attributes);
        }
    }

    return awtFont;
}

From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java

@Override
protected Map<Attribute, Object> getAttributes(AttributeSet attrSet) {
    Map<Attribute, Object> attrMap = new HashMap<Attribute, Object>();
    if (attrSet.isDefined(StyleConstants.FontFamily)) {
        attrMap.put(TextAttribute.FAMILY, StyleConstants.getFontFamily(attrSet));
    }/*from ww w .j av a 2s. c om*/

    if (attrSet.isDefined(StyleConstants.Bold)) {
        attrMap.put(TextAttribute.WEIGHT,
                StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Italic)) {
        attrMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE
                : TextAttribute.POSTURE_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Underline)) {
        attrMap.put(TextAttribute.UNDERLINE,
                StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.StrikeThrough)) {
        attrMap.put(TextAttribute.STRIKETHROUGH,
                StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.FontSize)) {
        attrMap.put(TextAttribute.SIZE, StyleConstants.getFontSize(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Foreground)) {
        attrMap.put(TextAttribute.FOREGROUND, StyleConstants.getForeground(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Background)) {
        attrMap.put(TextAttribute.BACKGROUND, StyleConstants.getBackground(attrSet));
    }

    //FIXME: why StyleConstants.isSuperscript(attrSet) does return false
    if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    }

    if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
    }

    return attrMap;
}

From source file:net.sf.jasperreports.engine.util.JRStyledTextParser.java

/**
 *
 *///from  ww  w  .  j  a v  a  2 s  .  co  m
private void parseStyle(JRStyledText styledText, Node parentNode) throws SAXException {
    NodeList nodeList = parentNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.TEXT_NODE) {
            styledText.append(node.getNodeValue());
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_style.equals(node.getNodeName())) {
            NamedNodeMap nodeAttrs = node.getAttributes();

            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();

            if (nodeAttrs.getNamedItem(ATTRIBUTE_fontName) != null) {
                styleAttrs.put(TextAttribute.FAMILY, nodeAttrs.getNamedItem(ATTRIBUTE_fontName).getNodeValue());
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_isBold) != null) {
                styleAttrs.put(TextAttribute.WEIGHT,
                        Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isBold).getNodeValue())
                                ? TextAttribute.WEIGHT_BOLD
                                : TextAttribute.WEIGHT_REGULAR);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_isItalic) != null) {
                styleAttrs.put(TextAttribute.POSTURE,
                        Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isItalic).getNodeValue())
                                ? TextAttribute.POSTURE_OBLIQUE
                                : TextAttribute.POSTURE_REGULAR);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline) != null) {
                styleAttrs.put(TextAttribute.UNDERLINE,
                        Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isUnderline).getNodeValue())
                                ? TextAttribute.UNDERLINE_ON
                                : null);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough) != null) {
                styleAttrs.put(TextAttribute.STRIKETHROUGH,
                        Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isStrikeThrough).getNodeValue())
                                ? TextAttribute.STRIKETHROUGH_ON
                                : null);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null) {
                styleAttrs.put(TextAttribute.SIZE,
                        Float.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue()));
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName) != null) {
                styleAttrs.put(JRTextAttribute.PDF_FONT_NAME,
                        nodeAttrs.getNamedItem(ATTRIBUTE_pdfFontName).getNodeValue());
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding) != null) {
                styleAttrs.put(JRTextAttribute.PDF_ENCODING,
                        nodeAttrs.getNamedItem(ATTRIBUTE_pdfEncoding).getNodeValue());
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded) != null) {
                styleAttrs.put(JRTextAttribute.IS_PDF_EMBEDDED,
                        Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_isPdfEmbedded).getNodeValue()));
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_forecolor) != null) {
                Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_forecolor).getNodeValue(),
                        Color.black);
                styleAttrs.put(TextAttribute.FOREGROUND, color);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_backcolor) != null) {
                Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_backcolor).getNodeValue(),
                        Color.black);
                styleAttrs.put(TextAttribute.BACKGROUND, color);
            }

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_bold.equalsIgnoreCase(node.getNodeName())) {
            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();
            styleAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE
                && NODE_italic.equalsIgnoreCase(node.getNodeName())) {
            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();
            styleAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE
                && NODE_underline.equalsIgnoreCase(node.getNodeName())) {
            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();
            styleAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sup.equalsIgnoreCase(node.getNodeName())) {
            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();
            styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_sub.equalsIgnoreCase(node.getNodeName())) {
            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();
            styleAttrs.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_font.equalsIgnoreCase(node.getNodeName())) {
            NamedNodeMap nodeAttrs = node.getAttributes();

            Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();

            if (nodeAttrs.getNamedItem(ATTRIBUTE_size) != null) {
                styleAttrs.put(TextAttribute.SIZE,
                        Float.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_size).getNodeValue()));
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_color) != null) {
                Color color = JRColorUtil.getColor(nodeAttrs.getNamedItem(ATTRIBUTE_color).getNodeValue(),
                        Color.black);
                styleAttrs.put(TextAttribute.FOREGROUND, color);
            }

            if (nodeAttrs.getNamedItem(ATTRIBUTE_fontFace) != null) {
                String fontFaces = nodeAttrs.getNamedItem(ATTRIBUTE_fontFace).getNodeValue();

                StringTokenizer t = new StringTokenizer(fontFaces, ",");
                while (t.hasMoreTokens()) {
                    String face = t.nextToken().trim();
                    if (AVAILABLE_FONT_FACE_NAMES.contains(face)) {
                        styleAttrs.put(TextAttribute.FAMILY, face);
                        break;
                    }
                }
            }

            int startIndex = styledText.length();

            parseStyle(styledText, node);

            styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));

        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_br.equalsIgnoreCase(node.getNodeName())) {
            styledText.append("\n");

            int startIndex = styledText.length();
            resizeRuns(styledText.getRuns(), startIndex, 1);

            parseStyle(styledText, node);
            styledText.addRun(
                    new JRStyledText.Run(new HashMap<Attribute, Object>(), startIndex, styledText.length()));

            if (startIndex < styledText.length()) {
                styledText.append("\n");
                resizeRuns(styledText.getRuns(), startIndex, 1);
            }
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_li.equalsIgnoreCase(node.getNodeName())) {
            String tmpText = styledText.getText();
            if (tmpText.length() > 0 && !tmpText.endsWith("\n")) {
                styledText.append("\n");
            }
            styledText.append(" \u2022 ");

            int startIndex = styledText.length();
            resizeRuns(styledText.getRuns(), startIndex, 1);
            parseStyle(styledText, node);
            styledText.addRun(
                    new JRStyledText.Run(new HashMap<Attribute, Object>(), startIndex, styledText.length()));

            // if the text in the next node does not start with a '\n', or 
            // if the next node is not a <li /> one, we have to append a new line
            Node nextNode = node.getNextSibling();
            String textContent = getFirstTextOccurence(nextNode);
            if (nextNode != null && !((nextNode.getNodeType() == Node.ELEMENT_NODE
                    && NODE_li.equalsIgnoreCase(nextNode.getNodeName())
                    || (textContent != null && textContent.startsWith("\n"))))) {
                styledText.append("\n");
                resizeRuns(styledText.getRuns(), startIndex, 1);
            }
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_a.equalsIgnoreCase(node.getNodeName())) {
            if (hyperlink == null) {
                NamedNodeMap nodeAttrs = node.getAttributes();

                Map<Attribute, Object> styleAttrs = new HashMap<Attribute, Object>();

                hyperlink = new JRBasePrintHyperlink();
                hyperlink.setHyperlinkType(HyperlinkTypeEnum.REFERENCE);
                styleAttrs.put(JRTextAttribute.HYPERLINK, hyperlink);

                if (nodeAttrs.getNamedItem(ATTRIBUTE_href) != null) {
                    hyperlink.setHyperlinkReference(nodeAttrs.getNamedItem(ATTRIBUTE_href).getNodeValue());
                }

                if (nodeAttrs.getNamedItem(ATTRIBUTE_type) != null) {
                    hyperlink.setLinkType(nodeAttrs.getNamedItem(ATTRIBUTE_type).getNodeValue());
                }

                if (nodeAttrs.getNamedItem(ATTRIBUTE_target) != null) {
                    hyperlink.setLinkTarget(nodeAttrs.getNamedItem(ATTRIBUTE_target).getNodeValue());
                }

                int startIndex = styledText.length();

                parseStyle(styledText, node);

                styledText.addRun(new JRStyledText.Run(styleAttrs, startIndex, styledText.length()));

                hyperlink = null;
            } else {
                throw new SAXException("Hyperlink <a> tags cannot be nested.");
            }
        } else if (node.getNodeType() == Node.ELEMENT_NODE && NODE_param.equalsIgnoreCase(node.getNodeName())) {
            if (hyperlink == null) {
                throw new SAXException("Hyperlink <param> tags must appear inside an <a> tag only.");
            } else {
                NamedNodeMap nodeAttrs = node.getAttributes();

                JRPrintHyperlinkParameter parameter = new JRPrintHyperlinkParameter();

                if (nodeAttrs.getNamedItem(ATTRIBUTE_name) != null) {
                    parameter.setName(nodeAttrs.getNamedItem(ATTRIBUTE_name).getNodeValue());
                }

                if (nodeAttrs.getNamedItem(ATTRIBUTE_valueClass) != null) {
                    parameter.setValueClass(nodeAttrs.getNamedItem(ATTRIBUTE_valueClass).getNodeValue());
                }

                String strValue = node.getTextContent();
                if (strValue != null) {
                    Object value = JRValueStringUtils.deserialize(parameter.getValueClass(), strValue);
                    parameter.setValue(value);
                }

                hyperlink.addHyperlinkParameter(parameter);
            }
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = "<" + node.getNodeName() + ">";
            throw new SAXException("Tag " + nodeName + " is not a valid styled text tag.");
        }
    }
}

From source file:net.sf.jasperreports.engine.fonts.FontUtil.java

/**
 * Returns a java.awt.Font instance by converting a JRFont instance.
 * Mostly used in combination with third-party visualization packages such as JFreeChart (for chart themes).
 * Unless the font parameter is null, this method always returns a non-null AWT font, regardless whether it was
 * found in the font extensions or not. This is because we do need a font to draw with and there is no point
 * in raising a font missing exception here, as it is not JasperReports who does the drawing. 
 *///from   w  w w  .  j av a  2 s.  c o m
public Font getAwtFont(JRFont font, Locale locale) {
    if (font == null) {
        return null;
    }

    // ignoring missing font as explained in the Javadoc
    Font awtFont = getAwtFontFromBundles(font.getFontName(),
            ((font.isBold() ? Font.BOLD : Font.PLAIN) | (font.isItalic() ? Font.ITALIC : Font.PLAIN)),
            font.getFontsize(), locale, true);

    if (awtFont == null) {
        awtFont = new Font(getAttributesWithoutAwtFont(new HashMap<Attribute, Object>(), font));
    } else {
        // add underline and strikethrough attributes since these are set at
        // style/font level
        Map<Attribute, Object> attributes = new HashMap<Attribute, Object>();
        if (font.isUnderline()) {
            attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        }
        if (font.isStrikeThrough()) {
            attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
        }

        if (!attributes.isEmpty()) {
            awtFont = awtFont.deriveFont(attributes);
        }
    }

    return awtFont;
}

From source file:lucee.runtime.img.Image.java

public void drawString(String text, int x, int y, Struct attr) throws PageException {

    if (attr != null && attr.size() > 0) {

        // font/*w w  w  . ja v  a2 s  .  c  o m*/
        String font = StringUtil.toLowerCase(Caster.toString(attr.get("font", ""))).trim();
        if (!StringUtil.isEmpty(font)) {
            font = FontUtil.getFont(font).getFontName();
        } else
            font = "Serif";

        // alpha
        //float alpha=Caster.toFloatValue(attr.get("alpha",null),1F);

        // size
        int size = Caster.toIntValue(attr.get("size", Constants.INTEGER_10));

        // style
        int style = Font.PLAIN;
        String strStyle = StringUtil.toLowerCase(Caster.toString(attr.get("style", "")));
        strStyle = StringUtil.removeWhiteSpace(strStyle);
        if (!StringUtil.isEmpty(strStyle)) {
            if ("plain".equals(strStyle))
                style = Font.PLAIN;
            else if ("bold".equals(strStyle))
                style = Font.BOLD;
            else if ("italic".equals(strStyle))
                style = Font.ITALIC;
            else if ("bolditalic".equals(strStyle))
                style = Font.BOLD + Font.ITALIC;
            else if ("bold,italic".equals(strStyle))
                style = Font.BOLD + Font.ITALIC;
            else if ("italicbold".equals(strStyle))
                style = Font.BOLD + Font.ITALIC;
            else if ("italic,bold".equals(strStyle))
                style = Font.BOLD + Font.ITALIC;
            else
                throw new ExpressionException("key style of argument attributeCollection has an invalid value ["
                        + strStyle + "], valid values are [plain,bold,italic,bolditalic]");
        }

        // strikethrough
        boolean strikethrough = Caster.toBooleanValue(attr.get("strikethrough", Boolean.FALSE));

        // underline
        boolean underline = Caster.toBooleanValue(attr.get("underline", Boolean.FALSE));

        AttributedString as = new AttributedString(text);
        as.addAttribute(TextAttribute.FONT, new Font(font, style, size));
        if (strikethrough)
            as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
        if (underline)
            as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        Graphics2D g = getGraphics();
        //if(alpha!=1D) setAlpha(g,alpha);

        g.drawString(as.getIterator(), x, y);
    } else
        getGraphics().drawString(text, x, y);

}

From source file:net.sf.jasperreports.engine.export.JRXhtmlExporter.java

/**
 *
 *//*from   www  .j  a va 2  s .  co m*/
protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip,
        Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor,
        Color backcolor) throws IOException {
    boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT));
    boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE));

    String fontFamilyAttr = (String) attributes.get(TextAttribute.FAMILY);//FIXMENOW reuse this font lookup code everywhere
    String fontFamily = fontFamilyAttr;

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamilyAttr, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont == null) {
            HtmlResourceHandler fontHandler = getExporterOutput().getFontHandler() == null ? getFontHandler()
                    : getExporterOutput().getFontHandler();
            HtmlResourceHandler resourceHandler = getExporterOutput().getResourceHandler() == null
                    ? getResourceHandler()
                    : getExporterOutput().getResourceHandler();
            if (fontHandler != null && resourceHandler != null) {
                HtmlFont htmlFont = HtmlFont.getInstance(locale, fontInfo, isBold, isItalic);

                if (htmlFont != null) {
                    if (!fontsToProcess.containsKey(htmlFont.getId())) {
                        fontsToProcess.put(htmlFont.getId(), htmlFont);

                        HtmlFontUtil.handleFont(resourceHandler, htmlFont);
                    }

                    fontFamily = htmlFont.getId();
                }
            }
        } else {
            fontFamily = exportFont;
        }
    }

    boolean localHyperlink = false;
    JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK);
    if (!hyperlinkStarted && hyperlink != null) {
        startHyperlink(hyperlink);
        localHyperlink = true;
    }

    writer.write("<span style=\"font-family: ");
    writer.write(fontFamily);
    writer.write("; ");

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);
    if (!hyperlinkStarted || !Color.black.equals(forecolor)) {
        writer.write("color: ");
        writer.write(JRColorUtil.getCssColor(forecolor));
        writer.write("; ");
    }

    Color runBackcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (runBackcolor != null && !runBackcolor.equals(backcolor)) {
        writer.write("background-color: ");
        writer.write(JRColorUtil.getCssColor(runBackcolor));
        writer.write("; ");
    }

    writer.write("font-size: ");
    writer.write(toSizeUnit((Float) attributes.get(TextAttribute.SIZE)));
    writer.write(";");

    switch (lineSpacing) {
    case SINGLE:
    default: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1; *line-height: normal;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case ONE_AND_HALF: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1.5;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case DOUBLE: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 2.0;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case PROPORTIONAL: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize.floatValue() + ";");
        }
        break;
    }
    case AT_LEAST:
    case FIXED: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize.floatValue() + "px;");
        }
        break;
    }
    }

    /*
    if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT))
    {
       writer.write(" text-align: ");
       writer.write(horizontalAlignment);
       writer.write(";");
    }
    */

    if (isBold) {
        writer.write(" font-weight: bold;");
    }
    if (isItalic) {
        writer.write(" font-style: italic;");
    }
    if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) {
        writer.write(" text-decoration: underline;");
    }
    if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) {
        writer.write(" text-decoration: line-through;");
    }

    if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: super;");
    } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: sub;");
    }

    writer.write("\"");

    if (tooltip != null) {
        writer.write(" title=\"");
        writer.write(JRStringUtil.xmlEncode(tooltip));
        writer.write("\"");
    }

    writer.write(">");

    writer.write(JRStringUtil.htmlEncode(text));

    writer.write("</span>");

    if (localHyperlink) {
        endHyperlink();
    }
}

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

private Font parseFont(String fontSpecs) {
    // split attribute value to get font name and carachteristics
    // bold, italic, underline, and strikeout.
    // Size and Unit (Point, Pixel, Millimeter, Inch)
    String[] fontSpecsArray = fontSpecs.split(",");
    int fontStyle = Font.PLAIN;
    boolean isUnderline = false;
    boolean isStrikeout = false;
    // TODO: manage unit
    String unit;/*  ww  w  . j  av  a2s . c o  m*/
    // font name
    String fontName = "Droid Sans"; //fontSpecsArray[0];
    int size = Integer.valueOf(fontSpecsArray[1]);
    //        size = (int)Math.round(size * Toolkit.getDefaultToolkit().getScreenResolution() / 72.0);
    if (fontSpecsArray.length > 5) {
        // her we have a full description
        // bold
        if (Boolean.valueOf(fontSpecsArray[2])) {
            fontStyle += Font.BOLD;
        }
        // italic
        if (Boolean.valueOf(fontSpecsArray[3])) {
            fontStyle += Font.ITALIC;
        }
        // underline
        isUnderline = Boolean.valueOf(fontSpecsArray[4]);
        // strikeout
        isStrikeout = Boolean.valueOf(fontSpecsArray[5]);
        // unit
        unit = fontSpecsArray[6];
    } else {
        // unit
        unit = fontSpecsArray[2];
    }
    Font font = new Font(fontName, fontStyle, size);
    Map attributes = font.getAttributes();
    if (isStrikeout) {
        attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    }
    if (isUnderline) {
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    }
    return new Font(attributes);
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Initializes the GUI.//from w  w w  .  j av a2 s . com
 *
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initGUI() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    // add attribute name
    panelAttName = new JPanel();
    panelAttName.setLayout(new BoxLayout(panelAttName, BoxLayout.PAGE_AXIS));
    panelAttName.setOpaque(false);
    // this border is to visualize that the name column can be enlarged/shrinked
    panelAttName.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.LIGHT_GRAY));

    labelAttHeader = new JLabel(LABEL_DOTS);
    labelAttHeader.setFont(labelAttHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelAttHeader.setForeground(Color.GRAY);
    panelAttName.add(labelAttHeader);

    labelAttName = new JLabel(LABEL_DOTS);
    labelAttName.setFont(labelAttName.getFont().deriveFont(Font.BOLD, FONT_SIZE_LABEL_VALUE));
    labelAttName.setMinimumSize(DIMENSION_LABEL_ATTRIBUTE);
    labelAttName.setPreferredSize(DIMENSION_LABEL_ATTRIBUTE);
    panelAttName.add(labelAttName);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(3, 20, 3, 10);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0.0;
    gbc.weighty = 1.0;
    gbc.gridheight = 2;
    add(panelAttName, gbc);

    // create value type name and bring it to a nice to read format (aka uppercase first letter
    // and replace '_' with ' '
    gbc.gridx += 1;
    gbc.insets = new Insets(5, 15, 5, 10);
    labelAttType = new JLabel(LABEL_DOTS);
    labelAttType.setMinimumSize(DIMENSION_LABEL_TYPE);
    labelAttType.setPreferredSize(DIMENSION_LABEL_TYPE);
    add(labelAttType, gbc);

    // missings panel
    JPanel panelStatsMissing = new JPanel();
    panelStatsMissing.setLayout(new BoxLayout(panelStatsMissing, BoxLayout.PAGE_AXIS));
    panelStatsMissing.setOpaque(false);

    labelStatsMissing = new JLabel(LABEL_DOTS);
    labelStatsMissing.setMinimumSize(DIMENSION_LABEL_MISSINGS);
    labelStatsMissing.setPreferredSize(DIMENSION_LABEL_MISSINGS);
    panelStatsMissing.add(labelStatsMissing);

    gbc.gridx += 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 0.0;
    add(panelStatsMissing, gbc);

    // chart panel(s) (only visible when enlarged)
    JPanel chartPanel = new JPanel(new BorderLayout());
    chartPanel.setBackground(COLOR_TRANSPARENT);
    chartPanel.setOpaque(false);
    listOfChartPanels.add(chartPanel);
    updateVisibilityOfChartPanels();

    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;
    gbc.insets = new Insets(0, 10, 0, 10);
    for (JPanel panel : listOfChartPanels) {
        gbc.gridx += 1;
        add(panel, gbc);
    }

    // (hidden) construction panel
    String constructionLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.construction.label");
    panelStatsConstruction = new JPanel();
    panelStatsConstruction.setLayout(new BoxLayout(panelStatsConstruction, BoxLayout.PAGE_AXIS));
    panelStatsConstruction.setOpaque(false);
    panelStatsConstruction.setVisible(false);

    JLabel labelConstructionHeader = new JLabel(constructionLabel);
    labelConstructionHeader.setFont(labelConstructionHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelConstructionHeader.setForeground(Color.GRAY);
    panelStatsConstruction.add(labelConstructionHeader);

    labelStatsConstruction = new JLabel(LABEL_DOTS);
    labelStatsConstruction.setFont(labelStatsConstruction.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    labelStatsConstruction.setMinimumSize(DIMENSION_LABEL_CONSTRUCTION);
    labelStatsConstruction.setPreferredSize(DIMENSION_LABEL_CONSTRUCTION);
    panelStatsConstruction.add(labelStatsConstruction);

    gbc.gridx += 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 0.0;
    add(panelStatsConstruction, gbc);

    // statistics panel, contains different statistics panels for numerical/nominal/date_time on
    // a card layout
    // needed to switch between for model swapping
    cardStatsPanel = new JPanel();
    cardStatsPanel.setOpaque(false);
    cardLayout = new CardLayout();
    cardStatsPanel.setLayout(cardLayout);

    // numerical version
    JPanel statsNumPanel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints gbcStatPanel = new GridBagConstraints();
    statsNumPanel.setLayout(layout);
    statsNumPanel.setOpaque(false);

    String avgLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.avg.label");
    String devianceLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.variance.label");
    String minLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.min.label");
    String maxLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.max.label");

    // min value panel
    JPanel panelStatsMin = new JPanel();
    panelStatsMin.setLayout(new BoxLayout(panelStatsMin, BoxLayout.PAGE_AXIS));
    panelStatsMin.setOpaque(false);

    JLabel labelMinHeader = new JLabel(minLabel);
    labelMinHeader.setFont(labelMinHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMinHeader.setForeground(Color.GRAY);
    panelStatsMin.add(labelMinHeader);

    labelStatsMin = new JLabel(LABEL_DOTS);
    labelStatsMin.setFont(labelStatsMin.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMin.add(labelStatsMin);

    // max value panel
    JPanel panelStatsMax = new JPanel();
    panelStatsMax.setLayout(new BoxLayout(panelStatsMax, BoxLayout.PAGE_AXIS));
    panelStatsMax.setOpaque(false);

    JLabel labelMaxHeader = new JLabel(maxLabel);
    labelMaxHeader.setFont(labelMaxHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMaxHeader.setForeground(Color.GRAY);
    panelStatsMax.add(labelMaxHeader);

    labelStatsMax = new JLabel(LABEL_DOTS);
    labelStatsMax.setFont(labelStatsMax.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMax.add(labelStatsMax);

    // average value panel
    JPanel panelStatsAvg = new JPanel();
    panelStatsAvg.setLayout(new BoxLayout(panelStatsAvg, BoxLayout.PAGE_AXIS));
    panelStatsAvg.setOpaque(false);

    JLabel labelAvgHeader = new JLabel(avgLabel);
    labelAvgHeader.setFont(labelAvgHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelAvgHeader.setForeground(Color.GRAY);
    panelStatsAvg.add(labelAvgHeader);

    labelStatsAvg = new JLabel(LABEL_DOTS);
    labelStatsAvg.setFont(labelStatsAvg.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsAvg.add(labelStatsAvg);

    // deviance value panel
    JPanel panelStatsDeviance = new JPanel();
    panelStatsDeviance.setLayout(new BoxLayout(panelStatsDeviance, BoxLayout.PAGE_AXIS));
    panelStatsDeviance.setOpaque(false);

    JLabel labelDevianceHeader = new JLabel(devianceLabel);
    labelDevianceHeader.setFont(labelDevianceHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelDevianceHeader.setForeground(Color.GRAY);
    panelStatsDeviance.add(labelDevianceHeader);

    labelStatsDeviation = new JLabel(LABEL_DOTS);
    labelStatsDeviation.setFont(labelStatsDeviation.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsDeviance.add(labelStatsDeviation);

    // add sub panels to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 4);
    panelStatsMin.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsMin, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsMax.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsMax, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsAvg.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsAvg, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsDeviance.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsDeviance, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsNumPanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsNumPanel, CARD_NUMERICAL);

    // nominal version
    JPanel statsNomPanel = new JPanel();
    statsNomPanel.setLayout(layout);
    statsNomPanel.setOpaque(false);
    String leastLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.least.label");
    String mostLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.most.label");
    String valuesLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.values.label");

    // least panel
    JPanel panelStatsLeast = new JPanel();
    panelStatsLeast.setLayout(new BoxLayout(panelStatsLeast, BoxLayout.PAGE_AXIS));
    panelStatsLeast.setOpaque(false);

    JLabel labelLeastHeader = new JLabel(leastLabel);
    labelLeastHeader.setFont(labelLeastHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelLeastHeader.setForeground(Color.GRAY);
    labelLeastHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsLeast.add(labelLeastHeader);

    labelStatsLeast = new JLabel(LABEL_DOTS);
    labelStatsLeast.setFont(labelStatsLeast.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsLeast.add(labelStatsLeast);

    // most panel
    JPanel panelStatsMost = new JPanel();
    panelStatsMost.setLayout(new BoxLayout(panelStatsMost, BoxLayout.PAGE_AXIS));
    panelStatsMost.setOpaque(false);

    JLabel labelMostHeader = new JLabel(mostLabel);
    labelMostHeader.setFont(labelMostHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMostHeader.setForeground(Color.GRAY);
    labelMostHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsMost.add(labelMostHeader);

    labelStatsMost = new JLabel(LABEL_DOTS);
    labelStatsMost.setFont(labelStatsMost.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMost.add(labelStatsMost);

    // values panel
    JPanel panelStatsValues = new JPanel();
    panelStatsValues.setLayout(new BoxLayout(panelStatsValues, BoxLayout.PAGE_AXIS));
    panelStatsValues.setOpaque(false);

    JLabel labelValuesHeader = new JLabel(valuesLabel);
    labelValuesHeader.setFont(labelValuesHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelValuesHeader.setForeground(Color.GRAY);
    labelValuesHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsValues.add(labelValuesHeader);

    labelStatsValues = new JLabel(LABEL_DOTS);
    labelStatsValues.setFont(labelStatsValues.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsValues.add(labelStatsValues);

    detailsButton = new JButton(new ShowNomValueAction(this));
    detailsButton.setVisible(false);
    detailsButton.setOpaque(false);
    detailsButton.setContentAreaFilled(false);
    detailsButton.setBorderPainted(false);
    detailsButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
    detailsButton.setHorizontalAlignment(SwingConstants.LEFT);
    detailsButton.setHorizontalTextPosition(SwingConstants.LEFT);
    detailsButton.setIcon(null);
    Font font = detailsButton.getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    detailsButton.setFont(font.deriveFont(attributes));
    panelStatsValues.add(detailsButton);

    // add sub panel to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 6);
    panelStatsLeast.setPreferredSize(DIMENSION_PANEL_NOMINAL_PREF_SIZE);
    statsNomPanel.add(panelStatsLeast, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsMost.setPreferredSize(DIMENSION_PANEL_NOMINAL_PREF_SIZE);
    statsNomPanel.add(panelStatsMost, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    statsNomPanel.add(panelStatsValues, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsNomPanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsNomPanel, CARD_NOMINAL);

    // date_time version
    JPanel statsDateTimePanel = new JPanel();
    statsDateTimePanel.setLayout(layout);
    statsDateTimePanel.setOpaque(false);

    String durationLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.duration.label");
    String fromLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.from.label");
    String untilLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.until.label");

    // min value panel
    JPanel panelStatsFrom = new JPanel();
    panelStatsFrom.setLayout(new BoxLayout(panelStatsFrom, BoxLayout.PAGE_AXIS));
    panelStatsFrom.setOpaque(false);

    JLabel labelFromHeader = new JLabel(fromLabel);
    labelFromHeader.setFont(labelFromHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelFromHeader.setForeground(Color.GRAY);
    panelStatsFrom.add(labelFromHeader);

    labelStatsFrom = new JLabel(LABEL_DOTS);
    labelStatsFrom.setFont(labelStatsFrom.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsFrom.add(labelStatsFrom);

    // until value panel
    JPanel panelStatsUntil = new JPanel();
    panelStatsUntil.setLayout(new BoxLayout(panelStatsUntil, BoxLayout.PAGE_AXIS));
    panelStatsUntil.setOpaque(false);

    JLabel labelUntilHeader = new JLabel(untilLabel);
    labelUntilHeader.setFont(labelUntilHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelUntilHeader.setForeground(Color.GRAY);
    panelStatsUntil.add(labelUntilHeader);

    labelStatsUntil = new JLabel(LABEL_DOTS);
    labelStatsUntil.setFont(labelStatsUntil.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsUntil.add(labelStatsUntil);

    // duration value panel
    JPanel panelStatsDuration = new JPanel();
    panelStatsDuration.setLayout(new BoxLayout(panelStatsDuration, BoxLayout.PAGE_AXIS));
    panelStatsDuration.setOpaque(false);

    JLabel labelDurationHeader = new JLabel(durationLabel);
    labelDurationHeader.setFont(labelDurationHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelDurationHeader.setForeground(Color.GRAY);
    panelStatsDuration.add(labelDurationHeader);

    labelStatsDuration = new JLabel(LABEL_DOTS);
    labelStatsDuration.setFont(labelStatsDuration.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsDuration.add(labelStatsDuration);

    // add sub panels to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 6);
    panelStatsFrom.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsFrom, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsUntil.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsUntil, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsDuration.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsDuration, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsDateTimePanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsDateTimePanel, CARD_DATE_TIME);

    // add stats panel to main gui
    gbc.gridx += 1;
    gbc.insets = new Insets(5, 10, 5, 10);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.WEST;
    add(cardStatsPanel, gbc);

    // needed so we can draw our own background
    setOpaque(false);

    // handle mouse events for hover effect and enlarging/shrinking
    addMouseListener(enlargeAndHoverAndPopupMouseAdapter);

    // change cursor to indicate this component can be clicked
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java

/**
 *
 *///from w w  w .j a  v  a 2  s  . co  m
protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip,
        Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor,
        Color backcolor) throws IOException {
    boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT));
    boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE));

    String fontFamilyAttr = (String) attributes.get(TextAttribute.FAMILY);
    String fontFamily = fontFamilyAttr;

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamilyAttr, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont == null) {
            HtmlResourceHandler fontHandler = getExporterOutput().getFontHandler() == null ? getFontHandler()
                    : getExporterOutput().getFontHandler();
            HtmlResourceHandler resourceHandler = getExporterOutput().getResourceHandler() == null
                    ? getResourceHandler()
                    : getExporterOutput().getResourceHandler();
            if (fontHandler != null && resourceHandler != null) {
                HtmlFont htmlFont = HtmlFont.getInstance(locale, fontInfo, isBold, isItalic);

                if (htmlFont != null) {
                    if (!fontsToProcess.containsKey(htmlFont.getId())) {
                        fontsToProcess.put(htmlFont.getId(), htmlFont);

                        HtmlFontUtil.handleFont(resourceHandler, htmlFont);
                    }

                    fontFamily = htmlFont.getId();
                }
            }
        } else {
            fontFamily = exportFont;
        }
    }

    boolean localHyperlink = false;
    JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK);
    if (!hyperlinkStarted && hyperlink != null) {
        startHyperlink(hyperlink);
        localHyperlink = true;
    }

    writer.write("<span style=\"font-family: ");
    writer.write(fontFamily);
    writer.write("; ");

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);
    if (!hyperlinkStarted || !Color.black.equals(forecolor)) {
        writer.write("color: ");
        writer.write(JRColorUtil.getCssColor(forecolor));
        writer.write("; ");
    }

    Color runBackcolor = (Color) attributes.get(TextAttribute.BACKGROUND);
    if (runBackcolor != null && !runBackcolor.equals(backcolor)) {
        writer.write("background-color: ");
        writer.write(JRColorUtil.getCssColor(runBackcolor));
        writer.write("; ");
    }

    writer.write("font-size: ");
    writer.write(toSizeUnit((Float) attributes.get(TextAttribute.SIZE)));
    writer.write(";");

    switch (lineSpacing) {
    case SINGLE:
    default: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1; *line-height: normal;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case ONE_AND_HALF: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 1.5;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case DOUBLE: {
        if (lineSpacingFactor == 0) {
            writer.write(" line-height: 2.0;");
        } else {
            writer.write(" line-height: " + lineSpacingFactor + ";");
        }
        break;
    }
    case PROPORTIONAL: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize.floatValue() + ";");
        }
        break;
    }
    case AT_LEAST:
    case FIXED: {
        if (lineSpacingSize != null) {
            writer.write(" line-height: " + lineSpacingSize.floatValue() + "px;");
        }
        break;
    }
    }

    /*
    if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT))
    {
       writer.write(" text-align: ");
       writer.write(horizontalAlignment);
       writer.write(";");
    }
    */

    if (isBold) {
        writer.write(" font-weight: bold;");
    }
    if (isItalic) {
        writer.write(" font-style: italic;");
    }
    if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) {
        writer.write(" text-decoration: underline;");
    }
    if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) {
        writer.write(" text-decoration: line-through;");
    }

    if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: super;");
    } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) {
        writer.write(" vertical-align: sub;");
    }

    writer.write("\"");

    if (tooltip != null) {
        writer.write(" title=\"");
        writer.write(JRStringUtil.xmlEncode(tooltip));
        writer.write("\"");
    }

    writer.write(">");

    writer.write(JRStringUtil.htmlEncode(text));

    writer.write("</span>");

    if (localHyperlink) {
        endHyperlink();
    }
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Updates the charts./*  w  w  w. ja  va2 s .  c  o  m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
    for (int i = 0; i < listOfChartPanels.size(); i++) {
        JPanel panel = listOfChartPanels.get(i);
        panel.removeAll();
        final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) {

            private static final long serialVersionUID = -6953213567063104487L;

            @Override
            public Dimension getPreferredSize() {
                return DIMENSION_CHART_PANEL_ENLARGED;
            }
        };
        chartPanel.setPopupMenu(null);
        chartPanel.setBackground(COLOR_TRANSPARENT);
        chartPanel.setOpaque(false);
        chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        panel.add(chartPanel, BorderLayout.CENTER);

        JPanel openChartPanel = new JPanel(new GridBagLayout());
        openChartPanel.setOpaque(false);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;

        JButton openChartButton = new JButton(OPEN_CHART_ACTION);
        openChartButton.setOpaque(false);
        openChartButton.setContentAreaFilled(false);
        openChartButton.setBorderPainted(false);
        openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
        openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
        openChartButton.setIcon(null);
        Font font = openChartButton.getFont();
        Map attributes = font.getAttributes();
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

        openChartPanel.add(openChartButton, gbc);

        panel.add(openChartPanel, BorderLayout.SOUTH);
        panel.revalidate();
        panel.repaint();
    }
}