当前位置: 首页>>代码示例>>Java>>正文


Java Font.getColor方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.Font.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java Font.getColor方法的具体用法?Java Font.getColor怎么用?Java Font.getColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.Font的用法示例。


在下文中一共展示了Font.getColor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: correctFontColorIfBackground

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
@Override
public Font correctFontColorIfBackground(FontManager fm, Workbook wb, BirtStyle birtStyle, Font font) {
	HSSFPalette palette = ((HSSFWorkbook)wb).getCustomPalette();		
	
	CSSValue bgColour = birtStyle.getProperty( StyleConstants.STYLE_BACKGROUND_COLOR );
	int bgRgb[] = parseColour( bgColour == null ? null : bgColour.getCssText(), "white" );

	short fgRgb[] = HSSFColor.BLACK.triplet;
	if( ( font != null ) && ( font.getColor() != Short.MAX_VALUE ) ) {
		fgRgb = palette.getColor(font.getColor()).getTriplet();
	}
	if( ( fgRgb[0] == 255 ) && ( fgRgb[1] == 255 ) && ( fgRgb[2] == 255 ) ) {
		fgRgb[0]=fgRgb[1]=fgRgb[2]=0;
	} else if( ( fgRgb[0] == 0 ) && ( fgRgb[1] == 0 ) && ( fgRgb[2] == 0 ) ) {
		fgRgb[0]=fgRgb[1]=fgRgb[2]=255;
	}

	if( ( bgRgb[ 0 ] == fgRgb[ 0 ] ) && ( bgRgb[ 1 ] == fgRgb[ 1 ] ) && ( bgRgb[ 2 ] == fgRgb[ 2 ] ) ) {
		
		IStyle addedStyle = new AreaStyle( fm.getCssEngine() );
		addedStyle.setColor( contrastColour( bgRgb ) );
		
		return fm.getFontWithExtraStyle( font, addedStyle );
	} else {
		return font;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:28,代码来源:StyleManagerHUtils.java

示例2: findFont

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
private static Font findFont(Workbook workbook, Font font)
{
   int numFonts = workbook.getNumberOfFonts();
   for (short i = 0; i < numFonts; i++)
   {
      Font f = workbook.getFontAt(i);
      if (f.getBoldweight() == font.getBoldweight() &&
          f.getItalic() == font.getItalic() &&
          f.getColor() == font.getColor() &&
          f.getFontHeight() == font.getFontHeight() &&
          f.getUnderline() == font.getUnderline() &&
          f.getFontName().equals(font.getFontName()) &&
          f.getTypeOffset() == font.getTypeOffset()
         )
      {
         if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
             ((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
         {
            if (DEBUG)
               System.err.println("    Found existing, matching Font!");
            return f;
         }
      }
   }
   if (DEBUG)
      System.err.println("    Did NOT find existing, matching Font!");
   return null;
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:29,代码来源:RichTextStringUtil.java

示例3: poiStyle2Netxilia

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
public static Styles poiStyle2Netxilia(CellStyle poiStyle, Font font, HSSFPalette palette,
		NetxiliaStyleResolver styleResolver) {
	List<Style> entries = new ArrayList<Style>();

	if (!poiStyle.getWrapText()) {
		entries.add(DefaultStyle.nowrap.getStyle());
	}
	// font
	if (font.getItalic()) {
		entries.add(DefaultStyle.italic.getStyle());
	}
	if (font.getStrikeout()) {
		entries.add(DefaultStyle.strikeout.getStyle());
	}
	if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
		entries.add(DefaultStyle.bold.getStyle());
	}
	if (font.getUnderline() != Font.U_NONE) {
		entries.add(DefaultStyle.underline.getStyle());
	}
	// borders
	if (poiStyle.getBorderBottom() != CellStyle.BORDER_NONE) {
		entries.add(DefaultStyle.borderBottom.getStyle());
	}
	if (poiStyle.getBorderLeft() != CellStyle.BORDER_NONE) {
		entries.add(DefaultStyle.borderLeft.getStyle());
	}
	if (poiStyle.getBorderTop() != CellStyle.BORDER_NONE) {
		entries.add(DefaultStyle.borderTop.getStyle());
	}
	if (poiStyle.getBorderRight() != CellStyle.BORDER_NONE) {
		entries.add(DefaultStyle.borderRight.getStyle());
	}
	// align
	switch (poiStyle.getAlignment()) {
	case CellStyle.ALIGN_LEFT:
		entries.add(DefaultStyle.alignLeft.getStyle());
		break;
	case CellStyle.ALIGN_RIGHT:
		entries.add(DefaultStyle.alignRight.getStyle());
		break;
	case CellStyle.ALIGN_CENTER:
		entries.add(DefaultStyle.alignCenter.getStyle());
		break;
	case CellStyle.ALIGN_JUSTIFY:
		entries.add(DefaultStyle.alignJustify.getStyle());
		break;
	}
	if (font != null && font.getColor() != 0) {
		HSSFColor poiForeground = palette.getColor(font.getColor());
		if (poiForeground != null && poiForeground != HSSFColor.AUTOMATIC.getInstance()) {
			Style foregroundDef = styleResolver.approximateForeground(poiForeground.getTriplet()[0],
					poiForeground.getTriplet()[1], poiForeground.getTriplet()[2]);
			if (foregroundDef != null) {
				entries.add(foregroundDef);
			}
		}
	}

	if (poiStyle.getFillForegroundColor() != 0) {
		HSSFColor poiBackground = palette.getColor(poiStyle.getFillForegroundColor());
		if (poiBackground != null && poiBackground != HSSFColor.AUTOMATIC.getInstance()) {
			Style backgroundDef = styleResolver.approximateBackground(poiBackground.getTriplet()[0],
					poiBackground.getTriplet()[1], poiBackground.getTriplet()[2]);
			if (backgroundDef != null) {
				entries.add(backgroundDef);
			}
		}
	}
	return entries.size() > 0 ? Styles.styles(entries) : null;
}
 
开发者ID:netxilia,项目名称:netxilia,代码行数:72,代码来源:PoiUtils.java

示例4: findCellStyle

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
 * Find a <code>CellStyle</code> with all the same attributes as the given
 * <code>CellStyle</code> but with the given font index.
 * @param workbook The <code>Workbook</code>.
 * @param cellStyle The <code>CellStyle</code> to find.
 * @param font The <code>Font</code> to find.
 * @return The <code>CellStyle</code> from the <code>Workbook</code> if
 *    found, or <code>null</code> if not found.
 */
private static CellStyle findCellStyle(Workbook workbook, CellStyle cellStyle, Font font)
{
   int numCellStyles = workbook.getNumCellStyles();
   for (short i = 0; i < numCellStyles; i++)
   {
      CellStyle cs = workbook.getCellStyleAt(i);
      Font f = workbook.getFontAt(cs.getFontIndex());
      if (cs.getFillForegroundColor() == cellStyle.getFillForegroundColor() &&
          cs.getFillBackgroundColor() == cellStyle.getFillBackgroundColor() &&
          cs.getDataFormat() == cellStyle.getDataFormat() &&
          cs.getAlignment() == cellStyle.getAlignment() &&
          cs.getBorderBottom() == cellStyle.getBorderBottom() &&
          cs.getBorderLeft() == cellStyle.getBorderLeft() &&
          cs.getBorderRight() == cellStyle.getBorderRight() &&
          cs.getBorderTop() == cellStyle.getBorderTop() &&
          cs.getFillPattern() == cellStyle.getFillPattern() &&
          cs.getWrapText() == cellStyle.getWrapText() &&
          cs.getRotation() == cellStyle.getRotation() &&
          cs.getBottomBorderColor() == cellStyle.getBottomBorderColor() &&
          cs.getTopBorderColor() == cellStyle.getTopBorderColor() &&
          cs.getLeftBorderColor() == cellStyle.getLeftBorderColor() &&
          cs.getRightBorderColor() == cellStyle.getRightBorderColor() &&
          cs.getVerticalAlignment() == cellStyle.getVerticalAlignment() &&
          cs.getIndention() == cellStyle.getIndention() &&
          cs.getLocked() == cellStyle.getLocked() &&
          cs.getHidden() == cellStyle.getHidden() &&
          f.getBoldweight() == font.getBoldweight() &&
          f.getItalic() == font.getItalic() &&
          f.getColor() == font.getColor() &&
          f.getFontHeight() == font.getFontHeight() &&
          f.getUnderline() == font.getUnderline() &&
          f.getFontName().equals(font.getFontName()) &&
          f.getTypeOffset() == font.getTypeOffset()
         )
      {
         if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
             ((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
         {
            if (DEBUG)
               System.err.println("    Found existing, matching CellStyle with the Font!");
            return cs;
         }
      }
   }
   if (DEBUG)
      System.err.println("    Did NOT find existing, matching CellStyle with the Font!");
   return null;
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:58,代码来源:RichTextStringUtil.java

示例5: decorateComponent

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
public static void decorateComponent(Cell cell, JComponent renderingComponent, JComponent defaultRenderer) {
    CellStyle style = cell.getCellStyle();

    // Background neither the index or the color works for XSSF cells
    Color backgroundColor = CellUtils.poiToAwtColor(style.getFillBackgroundColorColor());
    if (backgroundColor != null) {
        renderingComponent.setBackground(backgroundColor);
    } else {
        renderingComponent.setBackground(defaultRenderer.getBackground());
    }

    // Font and forground
    short fontIndex = style.getFontIndex();
    if (fontIndex > 0) {
        Font xlsFont = cell.getSheet().getWorkbook().getFontAt(fontIndex);
        java.awt.Font font = java.awt.Font.decode(xlsFont.getFontName());
        font = font.deriveFont((float) xlsFont.getFontHeightInPoints());
        font = font.deriveFont(java.awt.Font.PLAIN);
        if (xlsFont.getItalic()) {
            font = font.deriveFont(java.awt.Font.ITALIC);
        }
        if (xlsFont.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
            font = font.deriveFont(java.awt.Font.BOLD);
        }
        if (xlsFont.getUnderline() > Font.U_NONE) {
            // no underline in fonts
        }
        short fontColorIndex = xlsFont.getColor();
        Color fontColor = CellUtils.shortToColor(fontColorIndex);
        if (fontColor != null) {
            renderingComponent.setForeground(fontColor);
        } else {
            renderingComponent.setForeground(defaultRenderer.getForeground());
        }
        renderingComponent.setFont(font);
    } else {
        renderingComponent.setForeground(defaultRenderer.getForeground());
        renderingComponent.setFont(defaultRenderer.getFont());
    }

    // Borders
    // At the moment done in renderer but should be done with a JLayer to paint over the grid
    renderingComponent.setBorder(new CellBorder(cell));

    if (cell.getCellComment() != null) {
        renderingComponent.setToolTipText(cell.getCellComment().getString().getString());
    }
}
 
开发者ID:foxerfly,项目名称:Joeffice,代码行数:49,代码来源:CellRenderer.java

示例6: get

import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
@Override
public Object get(Column column, Cell cell, Font font) {
	if (font instanceof XSSFFont) {
		return ((XSSFFont) font).getXSSFColor();
	} else {
		Workbook book = cell.getSheet().getWorkbook();
		short color = font.getColor();
		return PoiExcelColorVisitor.getHssfColor(book, color);
	}
}
 
开发者ID:hishidama,项目名称:embulk-parser-poi_excel,代码行数:11,代码来源:PoiExcelCellFontVisitor.java


注:本文中的org.apache.poi.ss.usermodel.Font.getColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。