Skip to content

Commit 196bae0

Browse files
VedranVedran
Vedran
authored and
Vedran
committed
row properties
1 parent f8cbbd0 commit 196bae0

13 files changed

+373
-22
lines changed

src/main/java/com/vgv/xls/StyleProperty.java src/main/java/com/vgv/xls/CellProp.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@
2323
*/
2424
package com.vgv.xls;
2525

26+
import java.util.function.Consumer;
2627
import org.apache.poi.ss.usermodel.CellStyle;
2728

2829
/**
29-
* StyleProperty.
30+
* Cell property.
3031
* @author Vedran Grgo Vatavuk (123vgv@gmail.com)
3132
* @version $Id$
3233
* @since 1.0
3334
*/
34-
public interface StyleProperty {
35-
36-
/**
37-
* Attach property to a cell style.
38-
* @param style Cell style
39-
*/
40-
void attachTo(CellStyle style);
35+
public interface CellProp extends Consumer<CellStyle> {
4136
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Vedran Grgo Vatavuk
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.vgv.xls;
25+
26+
import java.util.function.Consumer;
27+
import org.apache.poi.ss.usermodel.Row;
28+
29+
/**
30+
* Row property.
31+
* @author Vedran Vatavuk (123vgv@gmail.com)
32+
* @version $Id$
33+
* @since 1.0
34+
*/
35+
public interface RowProp extends Consumer<Row> {
36+
}

src/main/java/com/vgv/xls/Style.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ public interface Style {
4646
* @param property Property
4747
* @return Style
4848
*/
49-
Style with(StyleProperty property);
49+
Style with(CellProp property);
5050
}

src/main/java/com/vgv/xls/StyleTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final CellStyle attachTo(final Cell cell) {
5353
}
5454

5555
@Override
56-
public final Style with(final StyleProperty property) {
56+
public final Style with(final CellProp property) {
5757
return this.origin.with(property);
5858
}
5959
}

src/main/java/com/vgv/xls/XsStyle.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,35 @@ public final class XsStyle implements Style {
3838
/**
3939
* Array of style properties.
4040
*/
41-
private final Array<StyleProperty> properties;
41+
private final Array<CellProp> properties;
4242

4343
/**
4444
* Ctor.
4545
* @param props Properties
4646
*/
47-
public XsStyle(final StyleProperty... props) {
47+
public XsStyle(final CellProp... props) {
4848
this(new Array<>(props));
4949
}
5050

5151
/**
5252
* Ctor.
5353
* @param props Properties
5454
*/
55-
public XsStyle(final Iterable<StyleProperty> props) {
55+
public XsStyle(final Iterable<CellProp> props) {
5656
this.properties = new Array<>(props);
5757
}
5858

5959
@Override
6060
public CellStyle attachTo(final Cell cell) {
6161
final CellStyle style = cell.getCellStyle();
62-
for (final StyleProperty property : this.properties) {
63-
property.attachTo(style);
62+
for (final CellProp property : this.properties) {
63+
property.accept(style);
6464
}
6565
return style;
6666
}
6767

6868
@Override
69-
public Style with(final StyleProperty element) {
69+
public Style with(final CellProp element) {
7070
return new XsStyle(this.properties.with(element));
7171
}
7272
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Vedran Grgo Vatavuk
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.vgv.xls.props;
25+
26+
import com.vgv.xls.RowProp;
27+
import org.apache.poi.ss.usermodel.Row;
28+
29+
/**
30+
* Row height.
31+
* @author Vedran Vatavuk (123vgv@gmail.com)
32+
* @version $Id$
33+
* @since 1.0
34+
*/
35+
@SuppressWarnings("PMD.AvoidUsingShortType")
36+
public final class Height implements RowProp {
37+
38+
/**
39+
* Height.
40+
*/
41+
private final short value;
42+
43+
/**
44+
* Ctor.
45+
* @param height Height
46+
*/
47+
public Height(final short height) {
48+
this.value = height;
49+
}
50+
51+
@Override
52+
public void accept(final Row row) {
53+
row.setHeight(this.value);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Vedran Grgo Vatavuk
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.vgv.xls.props;
25+
26+
import com.vgv.xls.RowProp;
27+
import org.apache.poi.ss.usermodel.Row;
28+
29+
/**
30+
* Row height in points.
31+
* @author Vedran Vatavuk (123vgv@gmail.com)
32+
* @version $Id$
33+
* @since 1.0
34+
*/
35+
public final class HeightInPoints implements RowProp {
36+
37+
/**
38+
* Height in points.
39+
*/
40+
private final float value;
41+
42+
/**
43+
* Ctor.
44+
* @param points Points
45+
*/
46+
public HeightInPoints(final float points) {
47+
this.value = points;
48+
}
49+
50+
@Override
51+
public void accept(final Row row) {
52+
row.setHeightInPoints(this.value);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Vedran Grgo Vatavuk
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.vgv.xls.props;
25+
26+
import com.vgv.xls.RowProp;
27+
import org.apache.poi.ss.usermodel.Row;
28+
29+
/**
30+
* Row zero height.
31+
* @author Vedran Vatavuk (123vgv@gmail.com)
32+
* @version $Id$
33+
* @since 1.0
34+
*/
35+
public final class ZeroHeight implements RowProp {
36+
37+
/**
38+
* Zero height.
39+
*/
40+
private final boolean value;
41+
42+
/**
43+
* Ctor.
44+
* @param zero Zero
45+
*/
46+
public ZeroHeight(final boolean zero) {
47+
this.value = zero;
48+
}
49+
50+
@Override
51+
public void accept(final Row row) {
52+
row.setZeroHeight(this.value);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Vedran Grgo Vatavuk
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
/**
26+
* Properties.
27+
*
28+
* @author Vedran Vatavuk (123vgv@gmail.com)
29+
* @version $Id$
30+
* @since 1.0
31+
*/
32+
package com.vgv.xls.props;

src/main/java/com/vgv/xls/styles/FillPattern.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
package com.vgv.xls.styles;
2525

26-
import com.vgv.xls.StyleProperty;
26+
import com.vgv.xls.CellProp;
2727
import org.apache.poi.ss.usermodel.CellStyle;
2828
import org.apache.poi.ss.usermodel.FillPatternType;
2929

@@ -34,7 +34,7 @@
3434
* @version $Id$
3535
* @since 1.0
3636
*/
37-
public final class FillPattern implements StyleProperty {
37+
public final class FillPattern implements CellProp {
3838

3939
/**
4040
* Type of fill pattern.
@@ -50,7 +50,7 @@ public FillPattern(final FillPatternType type) {
5050
}
5151

5252
@Override
53-
public void attachTo(final CellStyle style) {
53+
public void accept(final CellStyle style) {
5454
style.setFillPattern(this.pattern);
5555
}
5656
}

src/main/java/com/vgv/xls/styles/ForegroundColor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
package com.vgv.xls.styles;
2525

26-
import com.vgv.xls.StyleProperty;
26+
import com.vgv.xls.CellProp;
2727
import org.apache.poi.ss.usermodel.CellStyle;
2828

2929
/**
@@ -34,7 +34,7 @@
3434
* @since 1.0
3535
*/
3636
@SuppressWarnings("PMD.AvoidUsingShortType")
37-
public final class ForegroundColor implements StyleProperty {
37+
public final class ForegroundColor implements CellProp {
3838

3939
/**
4040
* Color.
@@ -50,7 +50,7 @@ public ForegroundColor(final short rgb) {
5050
}
5151

5252
@Override
53-
public void attachTo(final CellStyle style) {
53+
public void accept(final CellStyle style) {
5454
style.setFillForegroundColor(this.color);
5555
}
5656
}

0 commit comments

Comments
 (0)