Search in sources :

Example 1 with CTColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTColor in project poi by apache.

the class ThemesTable method getThemeColor.

/**
     * Convert a theme "index" (as used by fonts etc) into a color.
     * @param idx A theme "index"
     * @return The mapped XSSFColor, or null if not mapped.
     */
public XSSFColor getThemeColor(int idx) {
    // Theme color references are NOT positional indices into the color scheme,
    // i.e. these keys are NOT the same as the order in which theme colors appear
    // in theme1.xml. They are keys to a mapped color.
    CTColorScheme colorScheme = theme.getTheme().getThemeElements().getClrScheme();
    CTColor ctColor;
    switch(ThemeElement.byId(idx)) {
        case LT1:
            ctColor = colorScheme.getLt1();
            break;
        case DK1:
            ctColor = colorScheme.getDk1();
            break;
        case LT2:
            ctColor = colorScheme.getLt2();
            break;
        case DK2:
            ctColor = colorScheme.getDk2();
            break;
        case ACCENT1:
            ctColor = colorScheme.getAccent1();
            break;
        case ACCENT2:
            ctColor = colorScheme.getAccent2();
            break;
        case ACCENT3:
            ctColor = colorScheme.getAccent3();
            break;
        case ACCENT4:
            ctColor = colorScheme.getAccent4();
            break;
        case ACCENT5:
            ctColor = colorScheme.getAccent5();
            break;
        case ACCENT6:
            ctColor = colorScheme.getAccent6();
            break;
        case HLINK:
            ctColor = colorScheme.getHlink();
            break;
        case FOLHLINK:
            ctColor = colorScheme.getFolHlink();
            break;
        default:
            return null;
    }
    byte[] rgb = null;
    if (ctColor.isSetSrgbClr()) {
        // Color is a regular one
        rgb = ctColor.getSrgbClr().getVal();
    } else if (ctColor.isSetSysClr()) {
        // Color is a tint of white or black
        rgb = ctColor.getSysClr().getLastClr();
    } else {
        return null;
    }
    return new XSSFColor(rgb, colorMap);
}
Also used : XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) CTColorScheme(org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor)

Example 2 with CTColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTColor in project poi by apache.

the class SXSSFSheet method setTabColor.

/**
     * Set background color of the sheet tab
     *
     * @param colorIndex  the indexed color to set, must be a constant from {@link IndexedColors}
     */
public void setTabColor(int colorIndex) {
    CTWorksheet ct = _sh.getCTWorksheet();
    CTSheetPr pr = ct.getSheetPr();
    if (pr == null)
        pr = ct.addNewSheetPr();
    CTColor color = CTColor.Factory.newInstance();
    color.setIndexed(colorIndex);
    pr.setTabColor(color);
}
Also used : CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTSheetPr(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 3 with CTColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTColor in project poi by apache.

the class XSSFBorderFormatting method setVerticalBorderColor.

public void setVerticalBorderColor(short color) {
    CTColor ctColor = CTColor.Factory.newInstance();
    ctColor.setIndexed(color);
    setVerticalBorderColor(ctColor);
}
Also used : CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 4 with CTColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTColor in project poi by apache.

the class XSSFBorderFormatting method setBottomBorderColor.

@Override
public void setBottomBorderColor(short color) {
    CTColor ctColor = CTColor.Factory.newInstance();
    ctColor.setIndexed(color);
    setBottomBorderColor(ctColor);
}
Also used : CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 5 with CTColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTColor in project poi by apache.

the class XSSFBorderFormatting method setLeftBorderColor.

@Override
public void setLeftBorderColor(short color) {
    CTColor ctColor = CTColor.Factory.newInstance();
    ctColor.setIndexed(color);
    setLeftBorderColor(ctColor);
}
Also used : CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Aggregations

CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)27 Test (org.junit.Test)12 CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)10 CTPatternFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)6 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)5 Color (java.awt.Color)4 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)4 CTHslColor (org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor)4 CTSystemColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor)4 CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)4 PresetColor (org.apache.poi.sl.usermodel.PresetColor)3 XmlObject (org.apache.xmlbeans.XmlObject)2 CTColorScheme (org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme)2 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)2 CTColor (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor)2 CTRPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr)2 FileOutputStream (java.io.FileOutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1