Example usage for org.apache.poi.hssf.util HSSFColor getTripletHash

List of usage examples for org.apache.poi.hssf.util HSSFColor getTripletHash

Introduction

In this page you can find the example usage for org.apache.poi.hssf.util HSSFColor getTripletHash.

Prototype

public static Map<String, HSSFColor> getTripletHash() 

Source Link

Document

this function returns all colors in a hastable.

Usage

From source file:com.develog.utils.report.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *///from w w  w  .  j  a v a2 s . c o m
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = null;

    Map triplets = HSSFColor.getTripletHash();
    if (triplets != null) {
        Collection keys = triplets.keySet();
        if (keys != null && keys.size() > 0) {
            Object key = null;
            HSSFColor crtColor = null;
            short[] rgb = null;
            int diff = 0;
            int minDiff = 999;
            for (Iterator it = keys.iterator(); it.hasNext();) {
                key = it.next();

                crtColor = (HSSFColor) triplets.get(key);
                rgb = crtColor.getTriplet();

                diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                        + Math.abs(rgb[2] - awtColor.getBlue());

                if (diff < minDiff) {
                    minDiff = diff;
                    color = crtColor;
                }
            }
        }
    }

    return color;
}

From source file:com.siteview.ecc.report.xls.JRXlsExporter.java

License:Open Source License

/**
 *
 *//*ww  w.  j a  va  2 s. c  o  m*/
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = (HSSFColor) hssfColorsCache.get(awtColor);
    if (color == null) {
        Map triplets = HSSFColor.getTripletHash();
        if (triplets != null) {
            Collection keys = triplets.keySet();
            if (keys != null && keys.size() > 0) {
                Object key = null;
                HSSFColor crtColor = null;
                short[] rgb = null;
                int diff = 0;
                int minDiff = 999;
                for (Iterator it = keys.iterator(); it.hasNext();) {
                    key = it.next();

                    crtColor = (HSSFColor) triplets.get(key);
                    rgb = crtColor.getTriplet();

                    diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                            + Math.abs(rgb[2] - awtColor.getBlue());

                    if (diff < minDiff) {
                        minDiff = diff;
                        color = crtColor;
                    }
                }
            }
        }

        hssfColorsCache.put(awtColor, color);
    }

    return color;
}

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

License:Open Source License

/**
 *
 *///from www.j  ava2  s .c o  m
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = hssfColorsCache.get(awtColor);
    if (color == null) {
        Map<?, ?> triplets = HSSFColor.getTripletHash();
        if (triplets != null) {
            Collection<?> keys = triplets.keySet();
            if (keys != null && keys.size() > 0) {
                Object key = null;
                HSSFColor crtColor = null;
                short[] rgb = null;
                int diff = 0;
                int minDiff = 999;
                for (Iterator<?> it = keys.iterator(); it.hasNext();) {
                    key = it.next();

                    crtColor = (HSSFColor) triplets.get(key);
                    rgb = crtColor.getTriplet();

                    diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                            + Math.abs(rgb[2] - awtColor.getBlue());

                    if (diff < minDiff) {
                        minDiff = diff;
                        color = crtColor;
                    }
                }
            }
        }

        hssfColorsCache.put(awtColor, color);
    }
    return color;
}

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

License:Open Source License

/**
 *
 *//*  w  w  w  .j a  v a2  s  .  c  o  m*/
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = hssfColorsCache.get(awtColor);
    if (color == null) {
        Map<?, ?> triplets = HSSFColor.getTripletHash();
        if (triplets != null) {
            Collection<?> keys = triplets.keySet();
            if (keys != null && keys.size() > 0) {
                Object key = null;
                HSSFColor crtColor = null;
                short[] rgb = null;
                int diff = 0;
                int minDiff = 999;
                for (Iterator<?> it = keys.iterator(); it.hasNext();) {
                    key = it.next();
                    crtColor = (HSSFColor) triplets.get(key);
                    rgb = crtColor.getTriplet();
                    diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                            + Math.abs(rgb[2] - awtColor.getBlue());
                    if (diff < minDiff) {
                        minDiff = diff;
                        color = crtColor;
                    }
                }
            }
        }
        hssfColorsCache.put(awtColor, color);
    }
    return color;
}

From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyles.java

License:Apache License

/**
 * constructor
 */
public EPStyles() {
    super(null);
    colors = HSSFColor.getTripletHash();
}

From source file:ro.nextreports.engine.exporter.util.ExcelColorSupport.java

License:Apache License

/**
 * Find a suitable color for the cell.//  w  w w  .  jav  a2  s.c  om
 * <p/>
 * The algorithm searches all available triplets, weighted by tripletvalue and
 * tripletdifference to the other triplets. The color wins, which has the
 * smallest triplet difference and where all triplets are nearest to the
 * requested color.
 *
 * @param awtColor the awt color that should be transformed into an Excel color.
 * @return the excel color index that is nearest to the supplied color.
 */
public static synchronized short getNearestColor(final Color awtColor) {
    if (triplets == null) {
        triplets = HSSFColor.getTripletHash();
    }

    if (triplets == null || triplets.isEmpty()) {
        System.out.println("Unable to get triplet hashtable");
        return HSSFColor.BLACK.index;
    }

    short color = HSSFColor.BLACK.index;
    double minDiff = Double.MAX_VALUE;

    // get the color without the alpha chanel
    final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue(), null);

    float[] excelHsb = null;
    final Iterator elements = triplets.values().iterator();
    while (elements.hasNext()) {
        final HSSFColor crtColor = (HSSFColor) elements.next();
        final short[] rgb = crtColor.getTriplet();
        excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb);

        final double weight = 3.0d * Math.abs(excelHsb[0] - hsb[0]) + Math.abs(excelHsb[1] - hsb[1])
                + Math.abs(excelHsb[2] - hsb[2]);

        if (weight < minDiff) {
            minDiff = weight;
            if (minDiff == 0) {
                // we found the color ...
                return crtColor.getIndex();
            }
            color = crtColor.getIndex();
        }
    }
    return color;
}