Package org.apache.poi.hssf.util

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


    /** This method retrieves the AWT Color representation from the colour hash table
     *
     */
    private final Color getAWTColor(int index, Color deflt) {
      HSSFColor clr = (HSSFColor)colors.get(new Integer(index));
      if (clr == null) return deflt;
      return getAWTColor(clr);
    }
View Full Code Here


            if (getShade() == 1) {
                // TODO: change to constant when upgrade to new HSSF
                // solid w/foreground, bg doesn't matter
                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) {
                    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) {               
                    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) {
                    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

      if(styleMap.containsKey("border-top-style")){
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-top-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-top-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setTopBorderColor(index);
            }else{
              style.setTopBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderTop(HSSFCellStyle.BORDER_NONE);
      }
      if(styleMap.containsKey("border-bottom-style")){
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-bottom-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-bottom-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setBottomBorderColor(index);
            }else{
              style.setBottomBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
      }
      if(styleMap.containsKey("border-left-style")){
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-left-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-left-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setLeftBorderColor(index);
            }else{
              style.setLeftBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
      }     
      if(styleMap.containsKey("border-right-style")){
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-right-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-right-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setRightBorderColor(index);
            }else{
              style.setRightBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setRightBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }else{
        style.setBorderRight(HSSFCellStyle.BORDER_NONE);
     
     
      if(styleMap.containsKey("border-style")){
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        if(styleMap.containsKey("border-color")){
          ColorModel color = ColorModel.parseRGBString(styleMap.get("border-color"));
          if (color != null) {
            HSSFColor hssfColor = palette.findColor((byte) color.r,
                (byte) color.g, (byte) color.b);
            if (hssfColor == null) {
              short index = styleContainer.getNextColorIndex();
              palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
              style.setTopBorderColor(index);
              style.setBottomBorderColor(index);
              style.setRightBorderColor(index);
              style.setLeftBorderColor(index);
            }else{
              style.setTopBorderColor(hssfColor.getIndex());
              style.setBottomBorderColor(hssfColor.getIndex());
              style.setRightBorderColor(hssfColor.getIndex());
              style.setLeftBorderColor(hssfColor.getIndex());
            }
          }else{
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
            style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
            style.setRightBorderColor(IndexedColors.BLACK.getIndex());
            style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
          }
        }else{
          style.setTopBorderColor(IndexedColors.BLACK.getIndex());
          style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
          style.setRightBorderColor(IndexedColors.BLACK.getIndex());
          style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        }
      }
     
//      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//      style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//      style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//      style.setRightBorderColor(IndexedColors.BLACK.getIndex());
//      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
//      style.setTopBorderColor(IndexedColors.BLACK.getIndex());
     
      // 设置相关值
      // 背景色 background-color
     
     
      if (styleMap.containsKey("background-color")) {
        String colorValue = styleMap.get("background-color");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
            palette.setColorAtIndex(index,(byte) color.r,
                (byte) color.g, (byte) color.b);
            style.setFillForegroundColor(index);
          }else{
            style.setFillForegroundColor(hssfColor.getIndex());
          }
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }
     
      if (td.hasAttr("bgcolor")) {
        String colorValue = td.attr("bgcolor");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
            palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
            style.setFillForegroundColor(index);
          }else{
            style.setFillForegroundColor(hssfColor.getIndex());
          }
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        }
      }

      // 设置字体相关
      // font-family
      if (styleMap.containsKey("font-family")) {
        String font_family = styleMap.get("font-family");
        font.setFontName(font_family);
      }
      // 字体颜色
      if (styleMap.containsKey("color")) {
        String colorValue = styleMap.get("color");
        ColorModel color = ColorModel.parseRGBString(colorValue);
        if (color != null) {
          HSSFColor hssfColor = palette.findColor((byte) color.r,
              (byte) color.g, (byte) color.b);
          if (hssfColor == null) {
            short index = styleContainer.getNextColorIndex();
            palette.setColorAtIndex(index,(byte) color.r,
                  (byte) color.g, (byte) color.b);
            font.setColor(index);
          }else{
            font.setColor(hssfColor.getIndex());
          }
        }
      }
      // 字体大小
      if (styleMap.containsKey("font-size")) {
View Full Code Here

        styleColor(out, "border-top-color", cs.getTopBorderColor());
        styleColor(out, "border-bottom-color", cs.getBottomBorderColor());
    }

    private void styleColor(Formatter out, String attr, short index) {
        HSSFColor color = colors.getColor(index);
        if (index == HSSF_AUTO.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);
        }
    }
View Full Code Here

        styleColor(out, "border-top-color", cs.getTopBorderColor());
        styleColor(out, "border-bottom-color", cs.getBottomBorderColor());
    }

    private void styleColor(Formatter out, String attr, short index) {
        HSSFColor color = colors.getColor(index);
        if (index == HSSF_AUTO.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);
        }
    }
View Full Code Here

      css(td,"border-top-style","dotted");
      break;
    }

    short colorIndex = 0;
    HSSFColor color = null;
    colorIndex = style.getTopBorderColor();
    color = palette.getColor(colorIndex);
    if(color!=null){
//    if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
      short[] rgb = color.getTriplet();
      css(td,"border-top-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
    }
   
    switch(style.getBorderBottom()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-bottom-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-bottom-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-bottom-style","dotted");
      break;
    }
   
    colorIndex = style.getBottomBorderColor();
    color = palette.getColor(colorIndex);
    if(color!=null){
//    if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
      short[] rgb = color.getTriplet();
      css(td,"border-bottom-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
    }

   
    switch(style.getBorderLeft()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-left-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-left-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-left-style","dotted");
      break;
    }
   
    colorIndex = style.getLeftBorderColor();
    color = palette.getColor(colorIndex);
    if(color!=null){
//    if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
      short[] rgb = color.getTriplet();
      css(td,"border-left-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
    }
   
    switch(style.getBorderRight()){
    case CellStyle.BORDER_THICK:
    case CellStyle.BORDER_MEDIUM:
    case CellStyle.BORDER_THIN:
      css(td,"border-right-style","solid");
      break;
    case CellStyle.BORDER_DASH_DOT:
    case CellStyle.BORDER_DASH_DOT_DOT:
    case CellStyle.BORDER_DASHED:
      css(td,"border-right-style","dashed");
      break;
    case CellStyle.BORDER_DOTTED:
    case CellStyle.BORDER_DOUBLE:
    case CellStyle.BORDER_HAIR:
    case CellStyle.BORDER_MEDIUM_DASH_DOT:
    case CellStyle.BORDER_MEDIUM_DASH_DOT_DOT:
    case CellStyle.BORDER_MEDIUM_DASHED:
    case CellStyle.BORDER_SLANTED_DASH_DOT:
      css(td,"border-right-style","dotted");
      break;
    }
   
    colorIndex = style.getRightBorderColor();
    color = palette.getColor(colorIndex);
    if(color!=null){
//    if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
      short[] rgb = color.getTriplet();
      css(td,"border-right-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
    }
   

    colorIndex = style.getFillForegroundColor();
    color = palette.getColor(colorIndex);
//    if(color!=null){
    if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
      short[] rgb = color.getTriplet();
      css(td,"background-color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
    }
   
   
    HSSFFont font = style.getFont(book);
    if(font!=null){
      css(td,"font-family",font.getFontName());
      colorIndex = font.getColor();
      color = palette.getColor(colorIndex);
      if(color!=null){
//      if(colorIndex!=HSSF_AUTO.getIndex()&&color!=null){
        short[] rgb = color.getTriplet();
        css(td,"color",String.format("#%02x%02x%02x", rgb[0],rgb[1],rgb[2]));
      }
      css(td,"font-size",String.format("%dpx",pointsToPixels(font.getFontHeightInPoints())));
     
      // 20111024 对于
View Full Code Here

            if(xlsColor.isSetRgb()) {
                CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
                clr.setVal(xlsColor.getRgb());
            }
            else if(xlsColor.isSetIndexed()) {
                HSSFColor indexed = HSSFColor.getIndexHash().get((int) xlsColor.getIndexed());
                if (indexed != null) {
                    byte[] rgb = new byte[3];
                    rgb[0] = (byte) indexed.getTriplet()[0];
                    rgb[1] = (byte) indexed.getTriplet()[1];
                    rgb[2] = (byte) indexed.getTriplet()[2];
                    CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
                    clr.setVal(rgb);
                }
            }
        }
View Full Code Here

        //writing to disk; reading in and verifying palette
        book = HSSFTestDataSamples.writeOutAndReadBack(book);

        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<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
        Iterator<Integer> it = colors.keySet().iterator();
        while (it.hasNext())
        {
            Number index = it.next();
            HSSFColor expectedColor = colors.get(index);
            HSSFColor paletteColor = _hssfPalette.getColor(index.shortValue());
            c.compare(expectedColor, paletteColor);
        }
    }
View Full Code Here

        Map colors = HSSFColor.getIndexHash();
        Iterator indexes = colors.keySet().iterator();
        while (indexes.hasNext())
        {
            Integer index = (Integer) indexes.next();
            HSSFColor c = (HSSFColor) colors.get(index);
            short[] rgbTriplet = c.getTriplet();
            byte[] paletteTriplet = palette.getColor(index.shortValue());
            String msg = "Expected HSSFColor constant to match PaletteRecord at index 0x"
                + Integer.toHexString(c.getIndex());
            assertEquals(msg, rgbTriplet[0], paletteTriplet[0] & 0xff);
            assertEquals(msg, rgbTriplet[1], paletteTriplet[1] & 0xff);
            assertEquals(msg, rgbTriplet[2], paletteTriplet[2] & 0xff);
        }
    }
View Full Code Here

TOP

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

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.