-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle indexed and rgb colors (#6824)
- Loading branch information
1 parent
61e507d
commit 6551f2e
Showing
3 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...low/src/test/java/com/vaadin/flow/component/spreadsheet/tests/XSSFColorConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* This program is available under Vaadin Commercial License and Service Terms. | ||
* | ||
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full | ||
* license. | ||
*/ | ||
package com.vaadin.flow.component.spreadsheet.tests; | ||
|
||
import org.apache.poi.ss.usermodel.ComparisonOperator; | ||
import org.apache.poi.ss.usermodel.ConditionalFormattingRule; | ||
import org.apache.poi.ss.usermodel.IndexedColors; | ||
import org.apache.poi.xssf.usermodel.XSSFColor; | ||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.component.spreadsheet.Spreadsheet; | ||
import com.vaadin.flow.component.spreadsheet.XSSFColorConverter; | ||
|
||
public class XSSFColorConverterTest { | ||
|
||
private Spreadsheet spreadsheet; | ||
private XSSFColorConverter converter; | ||
|
||
@Before | ||
public void setUp() { | ||
spreadsheet = new Spreadsheet(); | ||
converter = new XSSFColorConverter( | ||
(XSSFWorkbook) spreadsheet.getWorkbook()); | ||
} | ||
|
||
@Test | ||
public void getFontColorCSS_withIndexedColor() { | ||
var rule = createRule(); | ||
var font = rule.createFontFormatting(); | ||
font.setFontColorIndex(IndexedColors.RED.index); | ||
|
||
var cssColor = converter.getFontColorCSS(rule); | ||
|
||
Assert.assertEquals("rgba(255, 0, 0, 1.0);", cssColor); | ||
} | ||
|
||
@Test | ||
public void getFontColorCSS_withRgbColor() { | ||
var rule = createRule(); | ||
var font = rule.createFontFormatting(); | ||
var color = new XSSFColor( | ||
new byte[] { (byte) 255, (byte) 128, (byte) 64 }); | ||
font.setFontColor(color); | ||
|
||
var cssColor = converter.getFontColorCSS(rule); | ||
|
||
Assert.assertEquals("rgba(255, 128, 64, 1.0);", cssColor); | ||
} | ||
|
||
@Test | ||
public void getBackgroundColorCSS_withIndexedColor() { | ||
var rule = createRule(); | ||
var pattern = rule.createPatternFormatting(); | ||
pattern.setFillBackgroundColor(IndexedColors.RED.index); | ||
|
||
var cssColor = converter.getBackgroundColorCSS(rule); | ||
|
||
Assert.assertEquals("rgba(255, 0, 0, 1.0);", cssColor); | ||
} | ||
|
||
@Test | ||
public void getBackgroundColorCSS_withRgbColor() { | ||
var rule = createRule(); | ||
var pattern = rule.createPatternFormatting(); | ||
var color = new XSSFColor( | ||
new byte[] { (byte) 255, (byte) 128, (byte) 64 }); | ||
pattern.setFillBackgroundColor(color); | ||
|
||
var cssColor = converter.getBackgroundColorCSS(rule); | ||
|
||
Assert.assertEquals("rgba(255, 128, 64, 1.0);", cssColor); | ||
} | ||
|
||
private ConditionalFormattingRule createRule() { | ||
var conditionalFormatting = spreadsheet.getActiveSheet() | ||
.getSheetConditionalFormatting(); | ||
return conditionalFormatting | ||
.createConditionalFormattingRule(ComparisonOperator.LT, "0"); | ||
} | ||
} |