Examples of HSSFColor


Examples of org.apache.poi.hssf.util.HSSFColor

    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.0 * (Math.min
                  (Math.abs(excelHsb[0] - hsb[0]),
                   Math.abs(excelHsb[0] - hsb[0] + 1))) +
              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;
  }
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

  }

  public HSSFColor getColor(final short index)
  {
    final Integer s = IntegerCache.getInteger(index);
    final HSSFColor color = (HSSFColor) indexes.get(s);
    if (color == null)
    {
      throw new IllegalStateException("No such color.");
    }
    return color;
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

      // we ran out of palette... try to get nearest color then
      return StaticExcelColorSupport.getNearestColor(awtColor, usedTripplets);
    }

    final HSSFPalette palette = workbook.getCustomPalette();
    final HSSFColor hssfColor = palette.findColor((byte) awtColor.getRed(),
        (byte) awtColor.getGreen(),
        (byte) awtColor.getBlue());

    if (hssfColor != null && hssfColor.getIndex() < lastUsedColor)
    {
      return hssfColor.getIndex();
    }
    else
    {
      palette.setColorAtIndex(lastUsedColor, (byte) awtColor.getRed(),
          (byte) awtColor.getGreen(),
          (byte) awtColor.getBlue());
      final HSSFColor color = palette.getColor(lastUsedColor);
      usedTripplets.put(color.getHexString(), color);
      return lastUsedColor++;
    }
  }
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

  /**
   *
   */
  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)
            {
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

        textbox.setString( s );
    }

    private HSSFFont matchFont( Font font )
    {
        HSSFColor hssfColor = workbook.getCustomPalette()
                .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
        if (hssfColor == null)
            hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
        boolean bold = (font.getStyle() & Font.BOLD) != 0;
        boolean italic = (font.getStyle() & Font.ITALIC) != 0;
        HSSFFont hssfFont = workbook.findFont(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0,
                    hssfColor.getIndex(),
                    (short)(font.getSize() * 20),
                    font.getName(),
                    italic,
                    false,
                    (short)0,
                    (byte)0);
        if (hssfFont == null)
        {
            hssfFont = workbook.createFont();
            hssfFont.setBoldweight(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0);
            hssfFont.setColor(hssfColor.getIndex());
            hssfFont.setFontHeight((short)(font.getSize() * 20));
            hssfFont.setFontName(font.getName());
            hssfFont.setItalic(italic);
            hssfFont.setStrikeout(false);
            hssfFont.setTypeOffset((short) 0);
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

  
   private byte[] getRGBOrARGB() {
        byte[] rgb = null;

        if (ctColor.isSetIndexed() && ctColor.getIndexed() > 0) {
            HSSFColor indexed = HSSFColor.getIndexHash().get((int) ctColor.getIndexed());
            if (indexed != null) {
               rgb = new byte[3];
               rgb[0] = (byte) indexed.getTriplet()[0];
               rgb[1] = (byte) indexed.getTriplet()[1];
               rgb[2] = (byte) indexed.getTriplet()[2];
               return rgb;
            }
         }
       
         if (!ctColor.isSetRgb()) {
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

        // Font color
        final short colorIndex = font.getColor();
        if (font instanceof HSSFFont) {
            if (colorIndex != HSSFFont.COLOR_NORMAL) {
                final HSSFWorkbook wb = (HSSFWorkbook) workbook;
                HSSFColor color = wb.getCustomPalette().getColor(colorIndex);
                if (color != null) {
                    short[] triplet = color.getTriplet();
                    styleBuilder.foreground(triplet);
                }
            }
        } else if (font instanceof XSSFFont) {
            XSSFFont xssfFont = (XSSFFont) font;

            XSSFColor color = xssfFont.getXSSFColor();
            if (color != null) {
                String argbHex = color.getARGBHex();
                if (argbHex != null) {
                    styleBuilder.foreground(argbHex.substring(2));
                }
            }
        } else {
            throw new IllegalStateException("Unexpected font type: " + (font == null ? "null" : font.getClass()) + ")");
        }

        // Background color
        if (cellStyle.getFillPattern() == 1) {
            Color color = cellStyle.getFillForegroundColorColor();
            if (color instanceof HSSFColor) {
                short[] triplet = ((HSSFColor) color).getTriplet();
                if (triplet != null) {
                    styleBuilder.background(triplet);
                }
            } else if (color instanceof XSSFColor) {
                String argb = ((XSSFColor) color).getARGBHex();
                if (argb != null) {
                    styleBuilder.background(argb.substring(2));
                }
            } else {
                throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
            }
        }

        // alignment
        switch (cellStyle.getAlignment()) {
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

    {
        super.initialize(attributes, parent);
        EPStyle pstyle = (EPStyle) parent;
        if (pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle();
            //style.setFillForegroundColor(
            Workbook workbook = getWorkbook();
            HSSFFont font = workbook.createFont();
            style.setFont(font);
            font.setFontHeightInPoints((short)getUnit());
            //font.setFontName(getFont());
            font.setItalic(getItalic());
            if (getBold()) {
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            } else {
                font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);           
            }
            font.setUnderline((byte)getUnderline());
            font.setStrikeout(getStrikeThrough());

            color = (HSSFColor)colorhash.get(pstyle.getForegroundColor().toString());
            //System.out.println(pstyle.getForegroundColor().toString());
            if (color == null) color = new HSSFColor.BLACK();
            font.setColor(color.getIndex());
            hssfFont = font;
        }
    }   
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

    {
        super.initialize(attributes, parent);
        EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
        if ((pstyle != null) && pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();       
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle()//oops a little confusing
                                                      //below is the style attribute
                                                      //this is an HSSFCellStyle
                                                      //associated with EPStyle
            style.setBorderTop((short)getStyle());

            ColorCode colorCode = getColor();
            if (colorCode != null) {
                color = (HSSFColor)colorhash.get(colorCode.toString());
            }
            if (color == null) color = new HSSFColor.BLACK();


            style.setTopBorderColor(color.getIndex());
        }
       
    }       
View Full Code Here

Examples of org.apache.poi.hssf.util.HSSFColor

    {
        super.initialize(attributes, parent);
        EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
        if ((pstyle != null) &&  pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();       
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle()//oops a little confusing
                                                      //below is the style attribute
                                                      //this is an HSSFCellStyle
                                                      //associated with EPStyle
            style.setBorderLeft((short)getStyle());

            ColorCode colorCode = getColor();
            if (colorCode != null) {
                color = (HSSFColor)colorhash.get(colorCode.toString());
            }
            if (color == null) color = new HSSFColor.BLACK();


            style.setLeftBorderColor(color.getIndex());
        }
       
    }       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.