Example usage for java.awt Color equals

List of usage examples for java.awt Color equals

Introduction

In this page you can find the example usage for java.awt Color equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Determines whether another object is equal to this Color .

Usage

From source file:ro.nextreports.designer.PropertyPanel.java

private Color getUniqueBackground() {
    Color background = null;
    int n = reportGridCells.size();
    for (int i = 0; i < n; i++) {
        BandElement element = reportGridCells.get(i).getValue();
        if (i == 0) {
            background = element.getBackground();
            continue;
        }/*from  ww  w  .  j  a  va 2 s. c  o  m*/
        if (!background.equals(element.getBackground())) {
            return null;
        }
    }

    return background;
}

From source file:ro.nextreports.designer.PropertyPanel.java

private Color getUniqueForeground() {
    Color foreground = null;
    int n = reportGridCells.size();
    for (int i = 0; i < n; i++) {
        BandElement element = reportGridCells.get(i).getValue();
        if (i == 0) {
            foreground = element.getForeground();
            continue;
        }//from   w  w  w .  ja  v  a 2 s  . co m
        if (!foreground.equals(element.getForeground())) {
            return null;
        }
    }

    return foreground;
}

From source file:org.alder.fotobuchconvert.scribus.RtfToScribusConverter.java

void output(XmlBuilder xml, DefaultStyledDocument doc, ScribusWriter scribus) {
    log.debug("Starting conversion of RTF data");
    if (log.isTraceEnabled())
        doc.dump(System.err);/*from  w ww .j a v a2s  .  c  o  m*/

    try {
        Element section = doc.getDefaultRootElement();
        log.trace(section);
        assert section.getName().equals("section");

        final int nj = section.getElementCount();
        for (int j = 0; j < nj; j++) {
            Element paragraph = section.getElement(j);
            log.trace(paragraph);
            assert section.getName().equals("paragraph");

            // boolean firstInPara = true;
            AttributeSet attr = paragraph.getAttributes();
            Integer alignment = (Integer) attr.getAttribute(StyleConstants.Alignment);

            boolean elementsInThisLine = false;
            final int ni = paragraph.getElementCount();
            for (int i = 0; i < ni; i++) {
                Element content = paragraph.getElement(i);
                assert section.getName().equals("content");

                int start = content.getStartOffset();
                int end = content.getEndOffset();

                attr = content.getAttributes();
                Boolean italic = (Boolean) attr.getAttribute(StyleConstants.Italic);
                Boolean bold = (Boolean) attr.getAttribute(StyleConstants.Bold);
                Boolean underline = (Boolean) attr.getAttribute(StyleConstants.Underline);
                String family = (String) attr.getAttribute(StyleConstants.Family);
                Integer fontSize = (Integer) attr.getAttribute(StyleConstants.Size);
                Color color = (Color) attr.getAttribute(StyleConstants.ColorConstants.Foreground);

                String text = doc.getText(start, end - start);

                // if (firstInPara && text.trim().isEmpty() && family ==
                // null
                // && fontSize == null)
                // continue;
                // else
                // firstInPara = false;
                if (i == ni - 1 && text.trim().isEmpty() && text.length() < 3)
                    continue;
                elementsInThisLine = true;

                while (text.endsWith("\n") || text.endsWith("\r"))
                    text = text.substring(0, text.length() - 1);

                log.debug(italic + " " + bold + " " + underline + " " + family + " " + fontSize + " " + color
                        + "\t\"" + text + "\"");

                XmlBuilder el = xml.add(C.EL_ITEXT).set(C.CH, text);

                if (bold == Boolean.TRUE && italic == Boolean.TRUE)
                    el.set(C.FONT, family + " Bold Italic");
                else if (bold == Boolean.TRUE)
                    el.set(C.FONT, family + " Bold");
                else if (italic == Boolean.TRUE)
                    el.set(C.FONT, family + " Italic");
                else
                    el.set(C.FONT, family + " Regular");

                if (fontSize != null)
                    el.set(C.FONTSIZE, fontSize);

                if (color != null && color.equals(Color.BLACK) && scribus != null) {
                    String colname = scribus.colorManager.getColorName(color);
                    el.set(C.FCOLOR, colname);
                }
            }

            if (!elementsInThisLine && j == nj - 1)
                break; // don't convert last line if empty

            XmlBuilder el = xml.add(C.EL_PARA);
            if (alignment != null)
                switch (alignment) {
                case StyleConstants.ALIGN_LEFT:
                    el.set(C.ALIGN, 0);
                    break;
                case StyleConstants.ALIGN_CENTER:
                    el.set(C.ALIGN, 1);
                    break;
                case StyleConstants.ALIGN_RIGHT:
                    el.set(C.ALIGN, 2);
                    break;
                case StyleConstants.ALIGN_JUSTIFIED:
                    el.set(C.ALIGN, 3);
                    break;
                }
        }
    } catch (BadLocationException e) {
        throw new RuntimeException("This error should not occour", e);
    }

}

From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java

/**
 * convenience method for internal use. paints a log item handle
 * visualization./*from   w  w  w .  j  av  a  2 s.  com*/
 * 
 * @param x
 *            horizontal anchor coordinate of the handle
 * @param y
 *            vertical anchor coordinate of the handle
 * @param g
 *            the Graphics object used for painting
 */
protected void paintHighligtedItem(int x, int y, Graphics g, String shape) {
    Color color = g.getColor();
    if (shape.equals(STR_NONE)) {
        return;
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DOT)) {
        if (!color.equals(Color.red))
            g.setColor(Color.red);
        else
            g.setColor(Color.black);
        g.fillOval(x - 3, y - 3, 6, 6);
        g.setColor(color);
        g.fillOval(x - 2, y - 2, 4, 4);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_BOX)) {
        if (!color.equals(Color.black))
            g.setColor(Color.black);
        else
            g.setColor(Color.red);
        g.fillRect(x - 6, y - 6, 12, 12);
        g.setColor(color);
        g.fill3DRect(x - 5, y - 5, 10, 10, false);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_CIRCLE)) {
        if (!color.equals(Color.black))
            g.setColor(Color.black);
        else
            g.setColor(Color.red);
        g.fillOval(x - 6, y - 6, 13, 13);
        g.setColor(color);
        g.fillOval(x - 5, y - 5, 11, 11);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_RHOMBUS)) {
        int rhombX[] = { x, x - 5, x, x + 5 };
        int rhombY[] = { y - 5, y, y + 5, y };
        g.fillPolygon(rhombX, rhombY, 4);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_TRIANGLE)) {
        int triX[] = { x, x - 5, x + 5 };
        int triY[] = { y + 5, y - 5, y - 5 };
        g.fillPolygon(triX, triY, 3);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_ROUND_BOX)) {
        if (!color.equals(Color.black))
            g.setColor(Color.black);
        else
            g.setColor(Color.red);
        g.fillRoundRect(x - 6, y - 6, 13, 13, 2, 2);
        g.setColor(color);
        g.fillRoundRect(x - 5, y - 5, 10, 10, 2, 2);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_BOX)) {
        g.drawRect(x - 5, y - 5, 10, 10);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_CIRCLE)) {
        if (!color.equals(Color.black))
            g.setColor(Color.black);
        else
            g.setColor(Color.red);
        g.fillOval(x - 6, y - 6, 13, 13);
        g.setColor(color);
        g.drawOval(x - 5, y - 5, 11, 11);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_RHOMBUS)) {
        int rhombX[] = { x, x - 5, x, x + 5 };
        int rhombY[] = { y - 5, y, y + 5, y };
        g.drawPolygon(rhombX, rhombY, 4);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_TRIANGLE)) {
        int triX[] = { x, x - 5, x + 5 };
        int triY[] = { y + 5, y - 5, y - 5 };
        g.drawPolygon(triX, triY, 3);
    } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_ROUND_BOX)) {
        g.drawRoundRect(x - 5, y - 5, 10, 10, 2, 2);
    }
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 * @return/*from   ww w .  j a  v a  2s.  com*/
 */
private JPanel createColorCategoriesPanel() {
    JPanel categoryColorsConfigurationPanel = new JPanel(new GridBagLayout());
    categoryColorsConfigurationPanel.setPreferredSize(new Dimension(180, 200));

    GridBagConstraints itemConstraint = new GridBagConstraints();

    JLabel categoryColorsLabel = new ResourceLabel(
            "plotter.configuration_dialog.color_scheme_dialog.category_colors");
    {

        itemConstraint.fill = GridBagConstraints.HORIZONTAL;
        itemConstraint.anchor = GridBagConstraints.WEST;
        itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
        itemConstraint.insets = new Insets(0, 5, 5, 5);
        itemConstraint.weightx = 1.0;

        categoryColorsConfigurationPanel.add(categoryColorsLabel, itemConstraint);
    }

    // add button panel
    {
        JPanel buttonPanel = new JPanel(new GridBagLayout());

        // remove scheme button
        {
            removeCategoryColorButton = new JButton(new ResourceAction(true,
                    "plotter.configuration_dialog.color_scheme_dialog.remove_category_color_button") {

                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    removeSelectedColorAction();
                }

            });

            itemConstraint = new GridBagConstraints();
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
            itemConstraint.fill = GridBagConstraints.NONE;

            buttonPanel.add(removeCategoryColorButton, itemConstraint);
        }

        {
            addCategoryButton = new JButton(new ResourceAction(true,
                    "plotter.configuration_dialog.color_scheme_dialog.add_category_color_button") {

                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    Color oldColor = Color.white;
                    Color newSchemeColor = createColorDialog(oldColor);
                    if (newSchemeColor != null && !newSchemeColor.equals(oldColor)) {
                        addColorAction(newSchemeColor);
                    }
                }

            });

            itemConstraint = new GridBagConstraints();
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
            itemConstraint.fill = GridBagConstraints.NONE;

            buttonPanel.add(addCategoryButton, itemConstraint);

        }

        itemConstraint = new GridBagConstraints();
        itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
        itemConstraint.fill = GridBagConstraints.NONE;
        itemConstraint.anchor = GridBagConstraints.EAST;
        itemConstraint.insets = new Insets(0, 5, 5, 5);

        categoryColorsConfigurationPanel.add(buttonPanel, itemConstraint);
    }

    {

        JPanel categoryListPanel = new JPanel(new GridBagLayout());

        // add list of categorie colors
        {

            colorList = new JList<Color>(nominalColorListModel);
            categoryColorsLabel.setLabelFor(colorList);
            colorList.setCellRenderer(new ColorListCellRenderer());
            colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            MouseAdapter ma = new MouseAdapter() {

                private void myPopupEvent(MouseEvent e) {
                    int x = e.getX();
                    int y = e.getY();
                    JList<?> list = (JList<?>) e.getSource();
                    list.setSelectedIndex(list.locationToIndex(e.getPoint()));
                    Color selectedColor = (Color) list.getSelectedValue();
                    if (selectedColor == null) {
                        return;
                    }

                    removeMenuItem.setEnabled(nominalColorListModel.getSize() > 2);

                    popupMenu.show(list, x, y);
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    if (e.isPopupTrigger()) {
                        myPopupEvent(e);
                    }
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                    if (e.isPopupTrigger()) {
                        myPopupEvent(e);
                    }
                }
            };

            colorList.addMouseListener(ma);
            colorList.addKeyListener(new KeyListener() {

                @Override
                public void keyTyped(KeyEvent e) {
                    return; // Nothing to be done
                }

                @Override
                public void keyReleased(KeyEvent e) {
                    return; // Nothing to be done
                }

                @Override
                public void keyPressed(KeyEvent e) {
                    int key = e.getKeyCode();
                    if (key == KeyEvent.VK_DELETE) {
                        if (nominalColorListModel.getSize() > 2) {
                            removeSelectedColorAction();
                        }
                    }
                    if (key == KeyEvent.VK_F2) {
                        replaceSelectedColorAction();
                    }
                    if (key == KeyEvent.VK_UP && SwingTools.isControlOrMetaDown(e)) {
                        moveSelectedColorUpAction();
                    }
                    if (key == KeyEvent.VK_DOWN && SwingTools.isControlOrMetaDown(e)) {
                        moveSelectedColorDownAction();
                    }
                }
            });

            colorListScrollPane = new JScrollPane(colorList);
            colorListScrollPane.setPreferredSize(new Dimension(170, 200));
            colorListScrollPane.setMaximumSize(new Dimension(170, 200));
            colorListScrollPane.setMinimumSize(new Dimension(170, 180));
            colorListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            colorListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

            itemConstraint = new GridBagConstraints();
            itemConstraint.fill = GridBagConstraints.BOTH;
            itemConstraint.weightx = 0.0;
            itemConstraint.weighty = 0.5;
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;

            categoryListPanel.add(colorListScrollPane, itemConstraint);
        }

        // add up/down button panel
        {

            JPanel upAndDownButtonPanel = new JPanel(new GridBagLayout());

            // add up button
            {
                JButton upButton = new JButton(
                        new ResourceAction(true, "plotter.configuration_dialog.move_color_up") {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                moveSelectedColorUpAction();
                            }
                        });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.weightx = 0;
                itemConstraint.weighty = 0;
                itemConstraint.fill = GridBagConstraints.NONE;
                itemConstraint.insets = new Insets(0, 2, 0, 12);

                upAndDownButtonPanel.add(upButton, itemConstraint);
            }

            // add down button
            {
                JButton downButton = new JButton(
                        new ResourceAction(true, "plotter.configuration_dialog.move_color_down") {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                moveSelectedColorDownAction();
                            }
                        });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.weightx = 0;
                itemConstraint.weighty = 0;
                itemConstraint.fill = GridBagConstraints.NONE;
                itemConstraint.insets = new Insets(0, 2, 0, 12);

                upAndDownButtonPanel.add(downButton, itemConstraint);
            }

            // add spacer panel
            {
                JPanel spacer = new JPanel();

                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.weightx = 0;
                itemConstraint.weighty = 1;
                itemConstraint.fill = GridBagConstraints.VERTICAL;

                upAndDownButtonPanel.add(spacer, itemConstraint);

            }

            itemConstraint = new GridBagConstraints();
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
            itemConstraint.weightx = 1;
            itemConstraint.weighty = 1;
            itemConstraint.fill = GridBagConstraints.VERTICAL;

            categoryListPanel.add(upAndDownButtonPanel, itemConstraint);

        }

        itemConstraint = new GridBagConstraints();
        itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
        itemConstraint.weightx = 1;
        itemConstraint.weighty = 1;
        itemConstraint.fill = GridBagConstraints.BOTH;

        categoryColorsConfigurationPanel.add(categoryListPanel, itemConstraint);
    }

    return categoryColorsConfigurationPanel;
}

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

/**
 *
 *//*from w w  w  .jav  a2  s. c  o  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:net.sf.jasperreports.engine.export.JRHtmlExporter.java

protected boolean appendBorderStyle(JRLineBox box, StringBuffer styleBuffer) {
    boolean addedToStyle = false;

    if (box != null) {
        LineStyleEnum tps = box.getTopPen().getLineStyleValue();
        LineStyleEnum lps = box.getLeftPen().getLineStyleValue();
        LineStyleEnum bps = box.getBottomPen().getLineStyleValue();
        LineStyleEnum rps = box.getRightPen().getLineStyleValue();

        float tpw = box.getTopPen().getLineWidth().floatValue();
        float lpw = box.getLeftPen().getLineWidth().floatValue();
        float bpw = box.getBottomPen().getLineWidth().floatValue();
        float rpw = box.getRightPen().getLineWidth().floatValue();

        if (0f < tpw && tpw < 1f) {
            tpw = 1f;//from  w  ww .  ja v  a  2 s. c om
        }
        if (0f < lpw && lpw < 1f) {
            lpw = 1f;
        }
        if (0f < bpw && bpw < 1f) {
            bpw = 1f;
        }
        if (0f < rpw && rpw < 1f) {
            rpw = 1f;
        }

        Color tpc = box.getTopPen().getLineColor();

        // try to compact all borders into one css property
        if (tps == lps && // same line style
                tps == bps && tps == rps && tpw == lpw && // same line width
                tpw == bpw && tpw == rpw && tpc.equals(box.getLeftPen().getLineColor()) && // same line color
                tpc.equals(box.getBottomPen().getLineColor()) && tpc.equals(box.getRightPen().getLineColor())) {
            addedToStyle |= appendPen(styleBuffer, box.getTopPen(), null);
        } else {
            addedToStyle |= appendPen(styleBuffer, box.getTopPen(), "top");
            addedToStyle |= appendPen(styleBuffer, box.getLeftPen(), "left");
            addedToStyle |= appendPen(styleBuffer, box.getBottomPen(), "bottom");
            addedToStyle |= appendPen(styleBuffer, box.getRightPen(), "right");
        }
    }

    return addedToStyle;
}

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

/**
 *
 *//*  ww w.  ja va  2s. 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:net.sf.jasperreports.engine.export.JRXhtmlExporter.java

protected boolean appendBorderStyle(JRLineBox box, StringBuffer styleBuffer) {
    boolean addedToStyle = false;

    if (box != null) {
        LineStyleEnum tps = box.getTopPen().getLineStyleValue();
        LineStyleEnum lps = box.getLeftPen().getLineStyleValue();
        LineStyleEnum bps = box.getBottomPen().getLineStyleValue();
        LineStyleEnum rps = box.getRightPen().getLineStyleValue();

        float tpw = box.getTopPen().getLineWidth().floatValue();
        float lpw = box.getLeftPen().getLineWidth().floatValue();
        float bpw = box.getBottomPen().getLineWidth().floatValue();
        float rpw = box.getRightPen().getLineWidth().floatValue();

        if (0f < tpw && tpw < 1f) {
            tpw = 1f;//from   w w  w .  j  a  v a2s .  com
        }
        if (0f < lpw && lpw < 1f) {
            lpw = 1f;
        }
        if (0f < bpw && bpw < 1f) {
            bpw = 1f;
        }
        if (0f < rpw && rpw < 1f) {
            rpw = 1f;
        }

        Color tpc = box.getTopPen().getLineColor();

        // try to compact all borders into one css property
        if (tps == lps && // same line style
                tps == bps && tps == rps && tpw == lpw && // same line width
                tpw == bpw && tpw == rpw && tpc.equals(box.getLeftPen().getLineColor()) && // same line color
                tpc.equals(box.getBottomPen().getLineColor()) && tpc.equals(box.getRightPen().getLineColor())) {
            addedToStyle |= appendPen(styleBuffer, box.getTopPen(), null);
        } else {
            addedToStyle |= appendPen(styleBuffer, box.getTopPen(), "top");
            addedToStyle |= appendPen(styleBuffer, box.getLeftPen(), "left");
            addedToStyle |= appendPen(styleBuffer, box.getBottomPen(), "bottom");
            addedToStyle |= appendPen(styleBuffer, box.getRightPen(), "right");
        }

        Integer tp = box.getTopPadding();
        Integer lp = box.getLeftPadding();
        Integer bp = box.getBottomPadding();
        Integer rp = box.getRightPadding();

        // try to compact all paddings into one css property
        if (tp == lp && tp == bp && tp == rp) {
            addedToStyle |= appendPadding(styleBuffer, tp, null);
        } else {
            addedToStyle |= appendPadding(styleBuffer, box.getTopPadding(), "top");
            addedToStyle |= appendPadding(styleBuffer, box.getLeftPadding(), "left");
            addedToStyle |= appendPadding(styleBuffer, box.getBottomPadding(), "bottom");
            addedToStyle |= appendPadding(styleBuffer, box.getRightPadding(), "right");
        }
    }

    return addedToStyle;
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

private void removeSelectedColorAction() {
    Color color = colorList.getSelectedValue();
    if (color != null) {

        // enable save and revert button
        saveButton.setEnabled(true);//w  ww . ja v a2s.  co  m
        revertButton.setEnabled(true);

        // remove element from list
        nominalColorListModel.removeElement(color);

        // remove color from current color scheme
        getCurrentActiveColorScheme().removeColor(ColorRGB.convertColorToColorRGB(color));

        // set gradient start end end color accordingly
        Color oldStartingColor = (Color) gradientStartColorComboBox.getSelectedItem();
        gradientStartColorComboBoxModel.removeElement(color);
        if (!color.equals(oldStartingColor)) {
            gradientStartColorComboBox.setSelectedItem(oldStartingColor);
        }
        gradientStartColorComboBox.setSelectedItem(oldStartingColor);

        Color oldEndingColor = (Color) gradientEndColorComboBox.getSelectedItem();
        gradientEndColorComboBoxModel.removeElement(color);
        if (!color.equals(oldEndingColor)) {
            gradientEndColorComboBox.setSelectedItem(oldEndingColor);
        }

        checkIfButtonsEnabled();

        adaptPreviewPlots();

    }

}