Package org.zkoss.poi.hssf.usermodel

Examples of org.zkoss.poi.hssf.usermodel.HSSFPalette


      argb = getRgbWithTint(argb, color.getTint());
    }
    return   "#"+ toHex(argb[0])+ toHex(argb[1])+ toHex(argb[2]);
  }
  private static String indexToHSSFRGB(HSSFWorkbook book, int index) {
    HSSFPalette palette = book.getCustomPalette();
    HSSFColor color = null;
    if (palette != null) {
      color = palette.getColor(index);
    }
    short[] triplet = null;
    if (color != null)
      triplet =  color.getTriplet();
    else {
View Full Code Here


  }
  private static String tripletToHTML(short[] triplet) {
    return triplet == null ? null : "#"+ toHex(triplet[0])+ toHex(triplet[1])+ toHex(triplet[2]);
  }
  public static short rgbToIndex(Book book, String color) {
    HSSFPalette palette = ((HSSFWorkbook)book).getCustomPalette();
    short red = Short.parseShort(color.substring(1,3), 16); //red
    short green = Short.parseShort(color.substring(3,5), 16); //green
    short blue = Short.parseShort(color.substring(5), 16); //blue
    byte r = (byte)Math.abs((byte)red);
    byte g = (byte)Math.abs((byte)green);
    byte b = (byte)Math.abs((byte)blue);
   
    HSSFColor pcolor = palette.findColor(r, g, b);
    if (pcolor != null) { //find default palette
      return pcolor.getIndex();
    } else {
      final Hashtable<short[], HSSFColor> colors = HSSFColor.getRgbHash();
      HSSFColor tcolor = colors.get(new short[] {red, green, blue});
      if (tcolor != null)
        return tcolor.getIndex();
      else {
        try {
          HSSFColor ncolor = palette.addColor(r, g, b);
          return ncolor.getIndex();
        } catch (RuntimeException ex) {
          //return similar color if can't add new color to palette
          /*
           * TODO: find a better solution for fix this issue
           *
           * While there is no space for adding a color into palette
           * return similar color cause return inexact color
           */
          return palette.findSimilarColor(red, green, blue).getIndex();
        }
       
      }
    }
  }
View Full Code Here

    byte g = triplet[1];
    byte b = triplet[2];
    short red = (short) (r & 0xff);
    short green = (short) (g & 0xff);
    short blue = (short) (b & 0xff);
    HSSFPalette palette = book.getCustomPalette();
    HSSFColor pcolor = palette != null ? palette.findColor(r, g, b) : null;
    if (pcolor != null) { //find default palette
      return pcolor;
    } else {
      final Hashtable<short[], HSSFColor> colors = HSSFColor.getRgbHash();
      HSSFColor tcolor = colors.get(new short[] {red, green, blue});
      if (tcolor != null)
        return tcolor;
      else {
        try {
          HSSFColor ncolor = palette.addColor(r, g, b);
          return ncolor;
        } catch (RuntimeException ex) {
          //try to create a fullcolor if not a built in palette color
          FullColorExt fullColor = new FullColorExt(red, green, blue);
          return new HSSFColorExt(fullColor);
View Full Code Here

    }
  }
 
  private static Color getHSSFFontColor(HSSFWorkbook book, HSSFFont font) {
    final short index = font.getColor() == Font.COLOR_NORMAL ? HSSFColor.AUTOMATIC.index : font.getColor();
    HSSFPalette palette = book.getCustomPalette();
    if (palette != null) {
      return palette.getColor(index);
    }
    Map<Integer, HSSFColor> indexHash = (Map<Integer, HSSFColor>) HSSFColor.getIndexHash();
    return indexHash.get(Integer.valueOf(index));
  }
View Full Code Here

TOP

Related Classes of org.zkoss.poi.hssf.usermodel.HSSFPalette

Copyright © 2018 www.massapicom. 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.