Skip to content

Commit e937da7

Browse files
committed
Updated mapping Eiffel to JSON
SpreadSheet.properties done. SpreadSheet.spreadSheetTheme wip.
1 parent d64682c commit e937da7

File tree

8 files changed

+142
-68
lines changed

8 files changed

+142
-68
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,59 @@ feature {NONE} -- JSON To Eiffel
140140
if attached {JSON_OBJECT} json_value (a_json, "iterativeCalculationSettings") as iterativeCalculationSettings then
141141
-- Result.set_iterative_calculation_settings (a_iterative_calculation_settings: [like iterative_calculation_settings] detachable EG_ITERATIVE_CALCULATION_SETTINGS)
142142
end
143-
if attached {JSON_OBJECT} json_value (a_json, "spreadsheetTheme") as spreadsheetTheme then
144-
-- Result.set_spreadsheet_theme (a_theme: [like spreadsheet_theme] detachable EG_SPREADSHEET_THEME)
143+
if attached {JSON_OBJECT} json_value (a_json, "spreadsheetTheme") as l_spreadsheet then
144+
Result.set_spreadsheet_theme (spreadsheet_theme (l_spreadsheet))
145145
end
146146
end
147147

148+
spreadsheet_theme (a_json: JSON_VALUE): EG_SPREADSHEET_THEME
149+
-- Create an object `EG_SPREADSHEET_THEME` from a json representation `a_json`.
150+
do
151+
create Result
152+
if attached string_value_from_json (a_json, "primaryFontFamily") as l_primary_font then
153+
Result.set_primary_font_family (l_primary_font)
154+
end
155+
if attached {JSON_ARRAY} json_value (a_json, "themeColors") as l_theme_colors then
156+
across l_theme_colors as ic loop
157+
Result.force_theme_color (theme_color_pair (ic.item))
158+
end
159+
end
160+
end
161+
162+
theme_color_pair (a_json: JSON_VALUE): EG_THEME_COLOR_PAIR
163+
local
164+
l_tc: EG_THEME_COLOR
165+
do
166+
create Result
167+
if attached string_value_from_json (a_json, "colorType") as l_color_type then
168+
create l_tc
169+
if l_color_type.is_case_insensitive_equal ("TEXT") then
170+
l_tc.set_text
171+
elseif l_color_type.is_case_insensitive_equal ("BACKGROUND") then
172+
l_tc.set_background
173+
elseif l_color_type.is_case_insensitive_equal ("ACCENT1") then
174+
l_tc.set_accent1
175+
elseif l_color_type.is_case_insensitive_equal ("ACCENT2") then
176+
l_tc.set_accent2
177+
elseif l_color_type.is_case_insensitive_equal ("ACCENT3") then
178+
l_tc.set_accent3
179+
elseif l_color_type.is_case_insensitive_equal ("ACCENT4") then
180+
l_tc.set_accent4
181+
elseif l_color_type.is_case_insensitive_equal ("ACCENT5") then
182+
l_tc.set_accent5
183+
elseif l_color_type.is_case_insensitive_equal ("ACCENT6") then
184+
l_tc.set_accent6
185+
elseif l_color_type.is_case_insensitive_equal ("LINK") then
186+
l_tc.set_link
187+
end
188+
Result.set_color_type (l_tc)
189+
end
190+
if attached {JSON_OBJECT} json_value (a_json, "color") as l_color then
191+
Result.set_color (eg_color_style (l_color))
192+
end
193+
194+
end
195+
148196
cell_format (a_json: JSON_OBJECT): EG_CELL_FORMAT
149197
-- Create an object `EG_CELL_FORMAT` from a json representation `a_json`
150198
local
@@ -251,24 +299,16 @@ feature {NONE} -- JSON To Eiffel
251299
-- Create an object `EG_COLOR` from a json rerpesentation `a_json`.
252300
do
253301
create Result
254-
if attached integer_value_from_json (a_json, "red") as l_val then
255-
Result.set_red (l_val)
256-
elseif attached real_value_from_json (a_json, "red") as l_val then
302+
if attached real_value_from_json (a_json, "red") as l_val then
257303
Result.set_red (l_val)
258304
end
259-
if attached integer_value_from_json (a_json, "green") as l_val then
260-
Result.set_green (l_val)
261-
elseif attached real_value_from_json (a_json, "green") as l_val then
305+
if attached real_value_from_json (a_json, "green") as l_val then
262306
Result.set_green (l_val)
263307
end
264-
if attached integer_value_from_json (a_json, "blue") as l_val then
265-
Result.set_blue (l_val)
266-
elseif attached real_value_from_json (a_json, "blue") as l_val then
308+
if attached real_value_from_json (a_json, "blue") as l_val then
267309
Result.set_blue (l_val)
268310
end
269-
if attached integer_value_from_json (a_json, "alpha") as l_val then
270-
Result.set_alpha (l_val)
271-
elseif attached real_value_from_json (a_json, "alpha") as l_val then
311+
if attached real_value_from_json (a_json, "alpha") as l_val then
272312
Result.set_alpha (l_val)
273313
end
274314
end

sheets/src/objects/eg_cell_format.e

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ feature -- Eiffel to JSON
215215
if attached background_color as l_bg then
216216
Result.put (l_bg.to_json, "backgroundColor")
217217
end
218-
if attached background_color_style as l_bgs then
219-
Result.put (l_bgs.to_json, "backgroundColorStyle")
220-
end
221218
if attached borders as lb then
222219
Result.put (lb.to_json, "borders")
223220
end
@@ -239,6 +236,9 @@ feature -- Eiffel to JSON
239236
if attached text_format as l_tf then
240237
Result.put (l_tf.to_json, "textFormat")
241238
end
239+
if attached background_color_style as l_bgs then
240+
Result.put (l_bgs.to_json, "backgroundColorStyle")
241+
end
242242
if attached hyperlink_display_type as l_hyper then
243243
Result.put (l_hyper.to_json, "hyperlinkDisplayType")
244244
end

sheets/src/objects/eg_color.e

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note
88
"green": number,
99
"blue": number,
1010
"alpha": number
11-
}
11+
}
1212
1313
]"
1414
date: "$Date$"
@@ -76,7 +76,7 @@ feature -- Eiffel to JSON
7676
create Result.make_with_capacity (4)
7777
Result.put (create {JSON_NUMBER}.make_real (red), "red")
7878
Result.put (create {JSON_NUMBER}.make_real (green), "green")
79-
Result.put (create {JSON_NUMBER}.make_real (green), "blue")
79+
Result.put (create {JSON_NUMBER}.make_real (blue), "blue")
8080
Result.put (create {JSON_NUMBER}.make_real (alpha), "alpha")
8181
end
8282

sheets/src/objects/eg_color_style.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ feature -- Eiffel to JSON
5858
do
5959
create Result.make_empty
6060
if attached rgb_color as l_rgb_color then
61-
61+
Result.put (l_rgb_color.to_json, "rgbColor")
6262
end
6363
if attached theme_color as l_theme_color then
6464
Result.put (l_theme_color.to_json, "themeColor")

sheets/src/objects/eg_spreadsheet_theme.e

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,66 @@ note
1818
class
1919
EG_SPREADSHEET_THEME
2020

21-
inherit
22-
23-
ANY
24-
redefine
25-
default_create
26-
end
27-
28-
create
29-
default_create
30-
31-
feature {NONE} --Initialize
32-
33-
default_create
34-
do
35-
create primary_font_family.make_empty
36-
create {ARRAYED_LIST[EG_THEME_COLOR_PAIR]}theme_colors.make (0)
37-
end
38-
3921
feature -- Access
4022

41-
42-
primary_font_family: STRING
23+
primary_font_family: detachable STRING
4324
-- Name of the primary font family.
4425

45-
theme_colors: LIST [EG_THEME_COLOR_PAIR]
26+
theme_colors: detachable LIST [EG_THEME_COLOR_PAIR]
4627
-- The spreadsheet theme color pairs.
4728
-- To update you must provide all theme color pairs.
4829

4930
feature -- Change Element
5031

51-
set_primary_font_family (a_value: STRING)
32+
set_primary_font_family (a_value: like primary_font_family)
5233
do
5334
primary_font_family := a_value
5435
ensure
5536
primary_font_family_set: primary_font_family = a_value
5637
end
5738

5839
force_theme_color (a_color: EG_THEME_COLOR_PAIR)
40+
local
41+
l_theme_colors: like theme_colors
5942
do
60-
theme_colors.force (a_color)
43+
l_theme_colors := theme_colors
44+
if l_theme_colors /= Void then
45+
l_theme_colors.force (a_color)
46+
else
47+
create {ARRAYED_LIST[EG_THEME_COLOR_PAIR]} l_theme_colors.make (2)
48+
l_theme_colors.force (a_color)
49+
end
50+
theme_colors := l_theme_colors
51+
end
52+
53+
set_theme_colors (a_colors: like theme_colors)
54+
-- Set the list `theme_colors` with `a_colors`.
55+
do
56+
theme_colors := a_colors
57+
ensure
58+
theme_colors_set: theme_colors = a_colors
6159
end
6260

6361

6462
feature -- Eiffel to JSON
6563

6664
to_json: JSON_OBJECT
6765
-- Json representation of current object
66+
local
67+
j_array: JSON_ARRAY
6868
do
6969
create Result.make_with_capacity (1)
70-
Result.put (create {JSON_STRING}.make_from_string (primary_font_family), "primaryFontFamily")
70+
if attached primary_font_family as lf then
71+
Result.put (create {JSON_STRING}.make_from_string (lf), "primaryFontFamily")
72+
end
73+
if attached theme_colors as l_colors then
74+
create j_array.make (l_colors.count)
75+
across l_colors as ic loop
76+
j_array.add (ic.item.to_json)
77+
end
78+
Result.put (j_array, "themeColors" )
79+
end
80+
7181
-- theme_colors JSON_ARRAY
7282
end
7383
end

sheets/src/objects/eg_text_format.e

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,37 @@ feature -- Change Element
144144
feature -- Eiffel to JSON
145145

146146
to_json: JSON_OBJECT
147+
-- JSON representation of current object
148+
-- {
149+
-- "foregroundColor": {
150+
-- object (Color)
151+
-- },
152+
-- "foregroundColorStyle": {
153+
-- object (ColorStyle)
154+
-- },
155+
-- "fontFamily": string,
156+
-- "fontSize": integer,
157+
-- "bold": boolean,
158+
-- "italic": boolean,
159+
-- "strikethrough": boolean,
160+
-- "underline": boolean
161+
-- }
162+
147163
do
148164
create Result.make_empty
149-
-- TODO
165+
if attached foreground_color as l_color then
166+
Result.put (l_color.to_json, "foregroundColor")
167+
end
168+
if attached foreground_color_style as l_fg_color then
169+
Result.put (l_fg_color.to_json, "foregroundColorStyle")
170+
end
171+
if attached font_family as l_font_family then
172+
Result.put (create {JSON_STRING}.make_from_string (l_font_family), "fontFamily")
173+
end
174+
Result.put (create {JSON_NUMBER}.make_integer (font_size),"fontSize")
175+
Result.put (create {JSON_BOOLEAN}.make (bold),"bold")
176+
Result.put (create {JSON_BOOLEAN}.make (italic),"italic")
177+
Result.put (create {JSON_BOOLEAN}.make (strikethrough),"strikethrough")
178+
Result.put (create {JSON_BOOLEAN}.make (underline),"underline")
150179
end
151180
end

sheets/src/objects/eg_theme_color.e

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ feature {NONE} -- Initialization
6767
accent6: INTEGER = 9
6868
-- Represents the sixth accent color.
6969

70-
link: INTEGER = 19
70+
link: INTEGER = 10
7171
-- Represents the color to use for hyperlinks.
7272

7373
feature -- Change Elements
@@ -193,7 +193,7 @@ feature -- Status Report
193193
a_value = accent3 or else
194194
a_value = accent4 or else
195195
a_value = accent5 or else
196-
a_value = accent5 or else
196+
a_value = accent6 or else
197197
a_value = link
198198
end
199199

sheets/src/objects/eg_theme_color_pair.e

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,45 @@ note
1616
class
1717
EG_THEME_COLOR_PAIR
1818

19-
inherit
20-
21-
ANY
22-
redefine
23-
default_create
24-
end
25-
26-
create
27-
default_create
28-
29-
feature {NONE} -- Initialization
30-
31-
default_create
32-
do
33-
create color_type
34-
create color
35-
end
3619

3720
feature -- Access
3821

39-
color_type: EG_THEME_COLOR
22+
color_type: detachable EG_THEME_COLOR
4023
-- The type of the spreadsheet theme color.
4124

4225

43-
color: EG_COLOR_STYLE
26+
color: detachable EG_COLOR_STYLE
4427
-- the concrete color corresponding to the theme color type.
4528

4629
feature -- Element Change
4730

4831
set_color_type (a_type: like color_type)
32+
-- Set `color_type` with `a_type`
4933
do
5034
color_type := a_type
35+
ensure
36+
color_type_set: color_type = a_type
5137
end
5238

5339
set_color (a_color: like color)
40+
-- Set `color` with `a_color`
5441
do
55-
color := color
42+
color := a_color
43+
ensure
44+
color_set: color = a_color
5645
end
5746

5847
feature -- Eiffel to JSON
5948

6049
to_json: JSON_OBJECT
6150
do
6251
create Result.make_empty
63-
Result.put (color_type.to_json, "colorType")
52+
if attached color_type as l_type then
53+
Result.put (l_type.to_json, "colorType")
54+
end
55+
if attached color as l_color then
56+
Result.put (l_color.to_json, "color")
57+
end
58+
6459
end
6560
end

0 commit comments

Comments
 (0)