Skip to content

Commit 724bdeb

Browse files
committed
Enable more table styles and scale bar style
1 parent 19ed657 commit 724bdeb

5 files changed

Lines changed: 129 additions & 3 deletions

File tree

src/main/groovy/geoscript/carto/TableItem.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class TableItem extends Item {
7575
this
7676
}
7777

78-
private class RowStyle {
78+
class RowStyle {
7979
Color backGroundColor = Color.WHITE
8080
Color textColor = Color.BLACK
8181
Font font = new Font("Arial", Font.PLAIN, 12)

src/main/groovy/geoscript/carto/io/JsonCartoReader.groovy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,18 @@ class JsonCartoReader implements CartoReader {
204204
if (item.fillColor) {
205205
scaleBarItem.fillColor(new Color(item.fillColor).asColor())
206206
}
207+
if (item.barStrokeColor) {
208+
scaleBarItem.barStrokeColor(new Color(item.barStrokeColor).asColor())
209+
}
207210
if (item.font) {
208211
scaleBarItem.font(getFont(item.font))
209212
}
213+
if (item.textColor) {
214+
scaleBarItem.textColor(new Color(item.textColor).asColor())
215+
}
216+
if (item.barStrokeWidth) {
217+
scaleBarItem.barStrokeWidth(item.barStrokeWidth as float)
218+
}
210219
if (item.strokeWidth) {
211220
scaleBarItem.strokeWidth(item.strokeWidth as float)
212221
}
@@ -235,6 +244,15 @@ class JsonCartoReader implements CartoReader {
235244
item.rows.each { Map row ->
236245
tableItem.row(row)
237246
}
247+
if (item.columnRowStyle) {
248+
setRowStyle(tableItem.columnRowStyle, item.columnRowStyle)
249+
}
250+
if (item.evenRowStyle) {
251+
setRowStyle(tableItem.evenRowStyle, item.evenRowStyle)
252+
}
253+
if (item.oddRowStyle) {
254+
setRowStyle(tableItem.oddRowStyle, item.oddRowStyle)
255+
}
238256
cartoBuilder.table(tableItem)
239257
} else if (itemType.equalsIgnoreCase("legend")) {
240258
LegendItem legendItem = new LegendItem(item.x, item.y, item.width, item.height)
@@ -287,4 +305,19 @@ class JsonCartoReader implements CartoReader {
287305
new Font(name, style, size)
288306
}
289307

308+
private void setRowStyle(TableItem.RowStyle rowStyle, Map item) {
309+
if (item.backgroundColor) {
310+
rowStyle.backGroundColor = new Color(item.backgroundColor).asColor()
311+
}
312+
if (item.font) {
313+
rowStyle.font = getFont(item.font as Map)
314+
}
315+
if (item.textColor) {
316+
rowStyle.textColor = new Color(item.textColor).asColor()
317+
}
318+
if (item.strokeColor) {
319+
rowStyle.strokeColor = new Color(item.strokeColor).asColor()
320+
}
321+
}
322+
290323
}

src/main/groovy/geoscript/carto/io/XmlCartoReader.groovy

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class XmlCartoReader implements CartoReader {
120120
} else if (itemType.equalsIgnoreCase("northArrow")) {
121121
NorthArrowItem northArrowItem = new NorthArrowItem(getInt(item.x.text()), getInt(item.y.text()), getInt(item.width.text()), getInt(item.height.text()))
122122
if (!item.style.isEmpty()) {
123-
northArrowItem.style(NorthArrowStyle.valueOf(item.style.text().toUpperCase()))
123+
northArrowItem.style(NorthArrowStyle.valueOf(item.style.text().trim()))
124124
}
125125
if (!item.fillColor1.isEmpty()) {
126126
northArrowItem.fillColor1(getColor(item.fillColor1.text()))
@@ -204,12 +204,21 @@ class XmlCartoReader implements CartoReader {
204204
if (!item.fillColor.isEmpty()) {
205205
scaleBarItem.fillColor(getColor(item.fillColor.text()))
206206
}
207+
if (!item.barStrokeColor.isEmpty()) {
208+
scaleBarItem.barStrokeColor(getColor(item.barStrokeColor.text()))
209+
}
207210
if (!item.font.isEmpty()) {
208211
scaleBarItem.font(getFont(item.font))
209212
}
213+
if (!item.textColor.isEmpty()) {
214+
scaleBarItem.textColor(getColor(item.textColor.text()))
215+
}
210216
if (!item.strokeWidth.isEmpty()) {
211217
scaleBarItem.strokeWidth(getFloat(item.strokeWidth.text()))
212218
}
219+
if (!item.barStrokeWidth.isEmpty()) {
220+
scaleBarItem.barStrokeWidth(getFloat(item.barStrokeWidth.text()))
221+
}
213222
if (!item.border.isEmpty()) {
214223
scaleBarItem.border(getInt(item.border.text()))
215224
}
@@ -237,6 +246,15 @@ class XmlCartoReader implements CartoReader {
237246
rowResult.children().each { row[it.name()] = it.text() }
238247
tableItem.row(row)
239248
}
249+
if (item.columnRowStyle) {
250+
setRowStyle(tableItem.columnRowStyle, item.columnRowStyle)
251+
}
252+
if (item.evenRowStyle) {
253+
setRowStyle(tableItem.evenRowStyle, item.evenRowStyle)
254+
}
255+
if (item.oddRowStyle) {
256+
setRowStyle(tableItem.oddRowStyle, item.oddRowStyle)
257+
}
240258
cartoBuilder.table(tableItem)
241259
} else if (itemType.equalsIgnoreCase("legend")) {
242260
LegendItem legendItem = new LegendItem(getInt(item.x.text()), getInt(item.y.text()), getInt(item.width.text()), getInt(item.height.text()))
@@ -318,4 +336,19 @@ class XmlCartoReader implements CartoReader {
318336
VerticalAlign.valueOf(str.toUpperCase())
319337
}
320338

339+
private void setRowStyle(TableItem.RowStyle rowStyle, GPathResult item) {
340+
if (!item.backgroundColor.isEmpty()) {
341+
rowStyle.backGroundColor = new Color(item.backgroundColor.text()).asColor()
342+
}
343+
if (!item.font.isEmpty()) {
344+
rowStyle.font = getFont(item.font)
345+
}
346+
if (!item.textColor.isEmpty()) {
347+
rowStyle.textColor = new Color(item.textColor.text()).asColor()
348+
}
349+
if (!item.strokeColor.isEmpty()) {
350+
rowStyle.strokeColor = new Color(item.strokeColor.text()).asColor()
351+
}
352+
}
353+
321354
}

src/test/groovy/geoscript/carto/io/JsonCartoReaderTest.groovy

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,37 @@ class JsonCartoReaderTest {
189189
{"ID": 1, "Name": "One"},
190190
{"ID": 2, "Name": "Two"},
191191
{"ID": 3, "Name": "Three"}
192-
]
192+
],
193+
"columnRowStyle": {
194+
"backgroundColor": "#008B8B",
195+
"font": {
196+
"name": "Arial",
197+
"style": "bold",
198+
"size": 12
199+
},
200+
"textColor": "white",
201+
"strokeColor": "#008B8B"
202+
},
203+
"evenRowStyle": {
204+
"backgroundColor": "FloralWhite",
205+
"font": {
206+
"name": "Arial",
207+
"style": "plain",
208+
"size": 12
209+
},
210+
"textColor": "Black",
211+
"strokeColor": "Black"
212+
},
213+
"oddRowStyle": {
214+
"backgroundColor": "#FAF0E6",
215+
"font": {
216+
"name": "Arial",
217+
"style": "plain",
218+
"size": 12
219+
},
220+
"textColor": "Black",
221+
"strokeColor": "Black"
222+
}
193223
},
194224
{
195225
"x": 640,

src/test/groovy/geoscript/carto/io/XmlCartoReaderTest.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,36 @@ class XmlCartoReaderTest {
203203
<row><ID>2</ID><Name>Two</Name></row>
204204
<row><ID>3</ID><Name>Three</Name></row>
205205
</rows>
206+
<columnRowStyle>
207+
<backgroundColor>#008B8B</backgroundColor>
208+
<font>
209+
<name>Arial</name>
210+
<style>Bold</style>
211+
<size>12</size>
212+
</font>
213+
<textColor>white</textColor>
214+
<strokeColor>#008B8B</strokeColor>
215+
</columnRowStyle>
216+
<evenRowStyle>
217+
<backgroundColor>FloralWhite</backgroundColor>
218+
<font>
219+
<name>Arial</name>
220+
<style>plain</style>
221+
<size>12</size>
222+
</font>
223+
<textColor>Black</textColor>
224+
<strokeColor>Black</strokeColor>
225+
</evenRowStyle>
226+
<oddRowStyle>
227+
<backgroundColor>#FAF0E6</backgroundColor>
228+
<font>
229+
<name>Arial</name>
230+
<style>plain</style>
231+
<size>12</size>
232+
</font>
233+
<textColor>Black</textColor>
234+
<strokeColor>Black</strokeColor>
235+
</oddRowStyle>
206236
</item>
207237
<item>
208238
<x>640</x>

0 commit comments

Comments
 (0)