source: issm/trunk/src/m/kml/kml_style.m@ 6455

Last change on this file since 6455 was 6455, checked in by jschierm, 14 years ago

Addition of set methods to all the kml classes.

File size: 7.4 KB
Line 
1%
2% definition for the kml_style sub (derived) class.
3%
4% [kml]=kml_style(varargin)
5%
6% where the optional varargin and defaults are:
7% id (char, style id, '')
8% icon (char, icon style, '')
9% label (char, label style, '')
10% line (char, line style, '')
11% poly (char, poly style, '')
12% balloon (char, balloon style, '')
13% list (char, list style, '')
14%
15% note that zero arguments constructs a default instance; one
16% argument of the class copies the instance; and two or more
17% arguments constructs a new instance from the arguments.
18%
19classdef kml_style < kml_styleselector
20 properties
21% icon =kml_iconstyle.empty();
22% label =kml_labelstyle.empty();
23 icon =[];
24 label =[];
25 line =kml_linestyle.empty();
26 poly =kml_polystyle.empty();
27% balloon =kml_balloonstyle.empty();
28% list =kml_liststyle.empty();
29 balloon =[];
30 list =[];
31 end
32
33 methods
34 function [kml]=kml_style(varargin)
35
36 kml=kml@kml_styleselector(varargin{:});
37
38 switch nargin
39
40% create a default object
41
42 case 0
43
44% copy the object or create the object from the input
45
46 otherwise
47 if (nargin == 1) && isa(varargin{1},class(kml))
48 kml=varargin{1};
49
50 else
51 fnames=fieldnames(kml);
52
53 for i=length(fieldnames(kml_styleselector()))+1:min(nargin,length(fnames))
54 if isa(varargin{i},class(kml.(fnames{i})))
55 if ~isempty(varargin{i})
56 kml.(fnames{i})=varargin{i};
57 end
58 else
59 if ~isempty(inputname(i))
60 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
61 inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
62 else
63 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
64 i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
65 end
66 end
67 end
68 end
69
70 end
71
72 end
73
74% display the object
75
76 function []=disp(kml)
77
78 for i=1:numel(kml)
79 disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
80 class(kml),inputname(1),string_dim(kml,i)));
81 disp@kml_styleselector(kml(i));
82 disp(sprintf(' icon: %s %s' ,string_size(kml(i).icon),...
83 class(kml(i).icon)));
84 disp(sprintf(' label: %s %s' ,string_size(kml(i).label),...
85 class(kml(i).label)));
86 disp(sprintf(' line: %s %s' ,string_size(kml(i).line),...
87 class(kml(i).line)));
88 disp(sprintf(' poly: %s %s' ,string_size(kml(i).poly),...
89 class(kml(i).poly)));
90 disp(sprintf(' balloon: %s %s' ,string_size(kml(i).balloon),...
91 class(kml(i).balloon)));
92 disp(sprintf(' list: %s %s\n' ,string_size(kml(i).list),...
93 class(kml(i).list)));
94 end
95
96 end
97
98% set the properties of the object
99
100 function [kml]=set(kml,varargin)
101
102 kmlref=feval(class(kml));
103
104% loop through each parameter in the input list (comparing to the reference
105% object in case property types have been changed)
106
107 for i=1:2:length(varargin)
108 if isfield(kmlref,varargin{i})
109 if isa(varargin{i+1},class(kmlref.(varargin{i})))
110 kml.(varargin{i})=varargin{i+1};
111 else
112 if ~isempty(inputname(i+1))
113 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
114 inputname(i+1),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
115 else
116 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
117 i+1 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
118 end
119 end
120 else
121 warning('Property ''%s'' for class ''%s'' does not exist.',...
122 varargin{i},class(kmlref));
123 end
124 end
125
126 end
127
128% write the object
129
130 function []=kml_write(kml,fid,indent)
131
132 if ~exist('fid','var') || isempty(fid)
133 fid=1;
134 end
135 if ~exist('indent','var') || isempty(indent)
136 indent='';
137 end
138
139% loop over the styles
140
141 for i=1:numel(kml)
142 if ~isempty(kml(i).id)
143 fprintf(fid,'%s<Style id="%s">\n',indent,kml(i).id);
144 else
145 fprintf(fid,'%s<Style>\n',indent);
146 end
147 kml_write@kml_styleselector(kml(i),fid,indent);
148% if isa(kml(i).icon,'kml_iconstyle')
149% kml_write(kml(i).icon,fid,[indent ' ']);
150% else
151% warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
152% i,class(kml(i).icon),'kml_iconstyle');
153% end
154% if isa(kml(i).label,'kml_labelstyle')
155% kml_write(kml(i).label,fid,[indent ' ']);
156% else
157% warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
158% i,class(kml(i).label),'kml_labelstyle');
159% end
160 if isa(kml(i).line,'kml_linestyle')
161 kml_write(kml(i).line,fid,[indent ' ']);
162 else
163 warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
164 i,class(kml(i).line),'kml_linestyle');
165 end
166 if isa(kml(i).poly,'kml_polystyle')
167 kml_write(kml(i).poly,fid,[indent ' ']);
168 else
169 warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
170 i,class(kml(i).poly),'kml_polystyle');
171 end
172% if isa(kml(i).balloon,'kml_balloonstyle')
173% kml_write(kml(i).balloon,fid,[indent ' ']);
174% else
175% warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
176% i,class(kml(i).balloon),'kml_balloonstyle');
177% end
178% if isa(kml(i).list,'kml_liststyle')
179% kml_write(kml(i).list,fid,[indent ' ']);
180% else
181% warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
182% i,class(kml(i).list),'kml_liststyle');
183% end
184 fprintf(fid,'%s</Style>\n',indent);
185 end
186
187 end
188
189 end
190
191end
192
Note: See TracBrowser for help on using the repository browser.