/** * Retrieves the color at a given index * * @param index the palette index, between 0x8 to 0x40 inclusive * @return the color, or null if the index is not populated */ public HSSFColor getColor(int index) { return getColor((short)index); }
@Override public HSSFColor getTopBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getTopBorderColor() ); }
@Override public HSSFColor getLeftBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getLeftBorderColor() ); }
/** * get the color value for the font */ public HSSFColor getHSSFColor(HSSFWorkbook wb) { HSSFPalette pallette = wb.getCustomPalette(); return pallette.getColor( getColor() ); }
public HSSFColor getFontColor() { return workbook.getCustomPalette().getColor( getFontColorIndex() ); }
@Override public HSSFColor getBottomBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getBottomBorderColor() ); }
@Override public HSSFColor getDiagonalBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getDiagonalBorderColor() ); }
@Override public HSSFColor getRightBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getRightBorderColor() ); }
public HSSFColor getFillBackgroundColorColor() { return workbook.getCustomPalette().getColor(getFillBackgroundColor()); }
public HSSFColor getFillForegroundColorColor() { return workbook.getCustomPalette().getColor(getFillForegroundColor()); }
public HSSFColor setColor(HSSFWorkbook workbook, byte r,byte g, byte b){ HSSFPalette palette = workbook.getCustomPalette(); HSSFColor hssfColor = null; try { hssfColor= palette.findColor(r, g, b); if (hssfColor == null ){ palette.setColorAtIndex(HSSFColor.LAVENDER.index, r, g,b); hssfColor = palette.getColor(HSSFColor.LAVENDER.index); } } catch (Exception e) { logger.error(e); } return hssfColor; }
@Override public HSSFColor getFillBackgroundColorColor() { HSSFPalette pallette = new HSSFPalette( _workbook.getCustomPalette() ); return pallette.getColor( getFillBackgroundColor() ); }
@Override public HSSFColor getFillForegroundColorColor() { HSSFPalette pallette = new HSSFPalette( _workbook.getCustomPalette() ); return pallette.getColor( getFillForegroundColor() ); }
/** * Adds a new color into an empty color slot. * @param red The red component * @param green The green component * @param blue The blue component * * @return The new custom color. * * @throws RuntimeException if there are more more free color indexes. */ public HSSFColor addColor( byte red, byte green, byte blue ) { byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); short i; for (i = PaletteRecord.FIRST_COLOR_INDEX; i < PaletteRecord.STANDARD_PALETTE_SIZE + PaletteRecord.FIRST_COLOR_INDEX; b = _palette.getColor(++i)) { if (b == null) { setColorAtIndex( i, red, green, blue ); return getColor(i); } } throw new RuntimeException("Could not find free color index"); }
/** * Finds the closest matching color in the custom palette. The * method for finding the distance between the colors is fairly * primative. * * @param red The red component of the color to match. * @param green The green component of the color to match. * @param blue The blue component of the color to match. * @return The closest color or null if there are no custom * colors currently defined. */ public HSSFColor findSimilarColor(int red, int green, int blue) { HSSFColor result = null; int minColorDistance = Integer.MAX_VALUE; byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null; b = _palette.getColor(++i)) { int colorDistance = Math.abs(red - unsignedInt(b[0])) + Math.abs(green - unsignedInt(b[1])) + Math.abs(blue - unsignedInt(b[2])); if (colorDistance < minColorDistance) { minColorDistance = colorDistance; result = getColor(i); } } return result; }
private HSSFColor buildHSSFColor(HSSFWorkbook wb,String colorStr){ String[] color=colorStr.split(","); HSSFPalette palette=wb.getCustomPalette(); byte r=BigInteger.valueOf(Integer.valueOf(color[0])).byteValue(); byte g=BigInteger.valueOf(Integer.valueOf(color[1])).byteValue(); byte b=BigInteger.valueOf(Integer.valueOf(color[2])).byteValue(); HSSFColor targetColor=palette.findColor(r,g,b); if(targetColor==null){ palette.setColorAtIndex(HSSFColorPredefined.LAVENDER.getIndex(), r, g,b); targetColor=palette.getColor(HSSFColorPredefined.LAVENDER.getIndex()); } return targetColor; }
private void styleColor(Formatter out, String attr, short index) { HSSFColor color = colors.getColor(index); if (index == hssfAuto.getIndex() || color == null) { out.format(" /* %s: index = %d */%n", attr, index); } else { short[] rgb = color.getTriplet(); out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2], index); } }
@Override public HSSFColor getLeftBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getLeftBorderColor() ); }
@Override public HSSFColor getRightBorderColorColor() { return workbook.getCustomPalette().getColor( borderFormatting.getRightBorderColor() ); }
public HSSFColor getFillForegroundColorColor() { HSSFPalette pallette = new HSSFPalette( _workbook.getCustomPalette() ); return pallette.getColor( getFillForegroundColor() ); }