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

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

Probably should test before checking in...

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 fnames=fieldnames(kmlref);
104
105% loop through each parameter in the input list (comparing to the reference
106% object in case property types have been changed)
107
108 for i=1:2:length(varargin)
109 if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
110 if isa(varargin{i+1},class(kmlref.(varargin{i})))
111 kml.(varargin{i})=varargin{i+1};
112 else
113 if ~isempty(inputname(i+1))
114 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
115 inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
116 else
117 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
118 i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
119 end
120 end
121 else
122 warning('Property ''%s'' for class ''%s'' does not exist.',...
123 varargin{i},class(kmlref));
124 end
125 end
126
127 end
128
129% write the object
130
131 function []=kml_write(kml,fid,indent)
132
133 if ~exist('fid','var') || isempty(fid)
134 fid=1;
135 end
136 if ~exist('indent','var') || isempty(indent)
137 indent='';
138 end
139
140% loop over the styles
141
142 for i=1:numel(kml)
143 if ~isempty(kml(i).id)
144 fprintf(fid,'%s<Style id="%s">\n',indent,kml(i).id);
145 else
146 fprintf(fid,'%s<Style>\n',indent);
147 end
148 kml_write@kml_styleselector(kml(i),fid,indent);
149% if isa(kml(i).icon,'kml_iconstyle')
150% kml_write(kml(i).icon,fid,[indent ' ']);
151% else
152% warning('kml(%d).icon is a ''%s'' class object, not ''%s''.',...
153% i,class(kml(i).icon),'kml_iconstyle');
154% end
155% if isa(kml(i).label,'kml_labelstyle')
156% kml_write(kml(i).label,fid,[indent ' ']);
157% else
158% warning('kml(%d).label is a ''%s'' class object, not ''%s''.',...
159% i,class(kml(i).label),'kml_labelstyle');
160% end
161 if isa(kml(i).line,'kml_linestyle')
162 kml_write(kml(i).line,fid,[indent ' ']);
163 else
164 warning('kml(%d).line is a ''%s'' class object, not ''%s''.',...
165 i,class(kml(i).line),'kml_linestyle');
166 end
167 if isa(kml(i).poly,'kml_polystyle')
168 kml_write(kml(i).poly,fid,[indent ' ']);
169 else
170 warning('kml(%d).poly is a ''%s'' class object, not ''%s''.',...
171 i,class(kml(i).poly),'kml_polystyle');
172 end
173% if isa(kml(i).balloon,'kml_balloonstyle')
174% kml_write(kml(i).balloon,fid,[indent ' ']);
175% else
176% warning('kml(%d).balloon is a ''%s'' class object, not ''%s''.',...
177% i,class(kml(i).balloon),'kml_balloonstyle');
178% end
179% if isa(kml(i).list,'kml_liststyle')
180% kml_write(kml(i).list,fid,[indent ' ']);
181% else
182% warning('kml(%d).list is a ''%s'' class object, not ''%s''.',...
183% i,class(kml(i).list),'kml_liststyle');
184% end
185 fprintf(fid,'%s</Style>\n',indent);
186 end
187
188 end
189
190 end
191
192end
193
Note: See TracBrowser for help on using the repository browser.