Package org.apache.poi.hssf.util

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


     * @return  The closest color or null if there are no custom
     *          colors currently defined.
     */
    public HSSFColor findSimilarColor(byte red, byte green, byte 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))
        {
View Full Code Here


                // TODO: change to constant when upgrade to new HSSF
                // solid w/foreground, bg doesn't matter
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("shade = 1");
                }
                HSSFColor color = (HSSFColor)colorhash.get(getBackgroundColor().toString());
                if (color == null) {
                    getLogger().debug("s1 BG couldn't find color for " + getBackgroundColor().toString());
                    color = new HSSFColor.WHITE();
                }
                style.setFillForegroundColor(color.getIndex());
                color = (HSSFColor)colorhash.get(getPatternColor().toString());
                if (color == null) {
          if (getLogger().isDebugEnabled()) {
              getLogger().debug("s1 PC couldn't find color for " + getPatternColor().toString());
          }
                    color = new HSSFColor.BLACK();
                }
                style.setFillBackgroundColor(color.getIndex());
            } else {
                HSSFColor color = (HSSFColor)colorhash.get(getBackgroundColor().toString());
                if (color == null) {
          if (getLogger().isDebugEnabled()) {
              getLogger().debug("BG couldn't find color for " + getBackgroundColor().toString());
          }
                    color = new HSSFColor.BLACK();
                }
                style.setFillBackgroundColor(color.getIndex());
                color = (HSSFColor)colorhash.get(getPatternColor().toString());
                if (color == null) {
          if (getLogger().isDebugEnabled()) {
              getLogger().debug("PC couldn't find color for " + getPatternColor().toString());
          }
                    color = new HSSFColor.WHITE();
                }
                style.setFillForegroundColor(color.getIndex());
            }
            style.setWrapText(getWrapText());
            style.setLocked(true);

            String format = null;
View Full Code Here

        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

        return CellStyle.VERTICAL_TOP;
    }
  }

  private short getColor(final HSSFWorkbook workbook, final Color color) {
    HSSFColor c = this.getHSSFColor(workbook, color);
    if (c == null) {
      return HSSFColor.BLACK.index;
    }
    return c.getIndex();
  }
View Full Code Here

    }
    return c.getIndex();
  }

  private short getBackgroundColor(final HSSFWorkbook workbook, final Color color) {
    HSSFColor c = this.getHSSFColor(workbook, color);
    if (c == null) {
      return HSSFColor.WHITE.index;
    }
    return c.getIndex();
  }
View Full Code Here

    byte red = (byte) color.getRed();
    byte green = (byte) color.getGreen();
    byte blue = (byte) color.getBlue();
    HSSFPalette palette = workbook.getCustomPalette();

    HSSFColor c = palette.findSimilarColor(red, green, blue);
    if (c == null) {
      try {
        c = palette.addColor(red, green, blue);
      } catch (RuntimeException e) {
        c = palette.findSimilarColor(red, green, blue);
View Full Code Here

        fis = new FileInputStream(temp);
        book = new HSSFWorkbook(fis);
        fis.close();
       
        palette = book.getCustomPalette();
        HSSFColor color = palette.getColor(HSSFColor.CORAL.index)//unmodified
        assertNotNull("Unexpected null in custom palette (unmodified index)", color);
        short[] expectedRGB = HSSFColor.CORAL.triplet;
        short[] actualRGB = color.getTriplet();
        String msg = "Expected palette position to remain unmodified";
        assertEquals(msg, expectedRGB[0], actualRGB[0]);
        assertEquals(msg, expectedRGB[1], actualRGB[1]);
        assertEquals(msg, expectedRGB[2], actualRGB[2]);
       
        color = palette.getColor((short) 0x12);
        assertNotNull("Unexpected null in custom palette (modified)", color);
        actualRGB = color.getTriplet();
        msg = "Expected palette modification to be preserved across save";
        assertEquals(msg, (short) 101, actualRGB[0]);
        assertEquals(msg, (short) 230, actualRGB[1]);
        assertEquals(msg, (short) 100, actualRGB[2]);
    }
View Full Code Here

        Map colors = HSSFColor.getIndexHash();
        Iterator it = colors.keySet().iterator();
        while (it.hasNext())
        {
            Number index = (Number) it.next();
            HSSFColor expectedColor = (HSSFColor) colors.get(index);
            HSSFColor paletteColor = hssfPalette.getColor(index.shortValue());
            c.compare(expectedColor, paletteColor);
        }
    }
View Full Code Here

    public void testAddColor() throws Exception
    {
        try
        {
            HSSFColor hssfColor = hssfPalette.addColor((byte)10,(byte)10,(byte)10);
            fail();
        }
        catch ( RuntimeException e )
        {
            // Failing because by default there are no colours left in the palette.
View Full Code Here

        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

TOP

Related Classes of org.apache.poi.hssf.util.HSSFColor

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.