001 /*
002 * $Id: ImageParameters.java,v 1.10 2012/02/19 17:35:36 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.chooser;
032
033
034 import edu.wisc.ssec.mcidasv.ResourceManager;
035
036 import java.awt.BorderLayout;
037 import java.awt.Dimension;
038
039 import java.awt.event.ActionListener;
040 import java.awt.event.ActionEvent;
041 import java.awt.event.KeyAdapter;
042 import java.awt.event.KeyEvent;
043 import java.awt.event.KeyListener;
044 import java.awt.event.ItemListener;
045 import java.awt.event.ItemEvent;
046
047 import java.util.ArrayList;
048 import java.util.List;
049 import java.util.StringTokenizer;
050
051 import javax.swing.*;
052
053 import org.w3c.dom.Document;
054 import org.w3c.dom.Element;
055 import org.w3c.dom.Node;
056 import org.w3c.dom.NodeList;
057
058 import ucar.unidata.data.imagery.AddeImageDescriptor;
059 import ucar.unidata.ui.XmlTree;
060 import ucar.unidata.ui.imagery.ImageSelector;
061
062 import ucar.unidata.util.GuiUtils;
063 import ucar.unidata.util.Misc;
064 import ucar.unidata.util.NamedThing;
065 import ucar.unidata.util.PreferenceList;
066
067 import ucar.unidata.xml.XmlResourceCollection;
068 import ucar.unidata.xml.XmlUtil;
069
070
071 public class ImageParameters extends NamedThing {
072
073 private static final String TAG_FOLDER = "folder";
074 private static final String TAG_SAVESET = "set";
075 private static final String ATTR_NAME = "name";
076 private static final String ATTR_URL = "url";
077
078 private static final String[] ATTRS = { "user", "proj", "pos",
079 "satband", "band", "id", "key", "latlon", "linele", "loc",
080 "mag", "num", "place", "size" , "spac", "unit", "nav",
081 "center", "uleft", "lleft", "uright", "lright", "descriptor",
082 "group"
083 };
084
085 private String server;
086 private List properties;
087 private List values;
088
089 private String user;
090 private String proj;
091 private String pos;
092 private String satband;
093 private String band;
094 private String id;
095 private String key;
096 private String latlon;
097 private String linele;
098 private String loc;
099 private String mag;
100 private String num;
101 private String place;
102 private String size;
103 private String spac;
104 private String unit;
105 private String nav;
106 private String center;
107 private String uleft;
108 private String lleft;
109 private String uright;
110 private String lright;
111 private String descriptor;
112 private String group;
113
114
115 public ImageParameters(String url) {
116 List props = new ArrayList();
117 List vals = new ArrayList();
118 parametersBreakdown(url, props, vals);
119 this.properties = props;
120 this.values = vals;
121 setValues(props, vals);
122 }
123
124 public ImageParameters(List props, List vals) {
125 this.properties = props;
126 this.values = vals;
127 setValues(props, vals);
128 }
129
130 public List getProperties() {
131 return this.properties;
132 }
133
134 public List getValues() {
135 return this.values;
136 }
137
138 public String getServer() {
139 return this.server;
140 }
141
142 private void setValues(List props, List vals) {
143 int len = props.size();
144 if (len < 1) return;
145 for (int i=0; i<len; i++) {
146 String prop = (String)props.get(i);
147 if (!isKeyword(prop)) break;
148 String val = (String)vals.get(i);
149 if (prop.equals("user")) {
150 user = val;
151 break;
152 }
153 if (prop.equals("proj")) {
154 proj = val;
155 break;
156 }
157 if (prop.equals("pos")) {
158 pos = val;
159 break;
160 }
161 if (prop.equals("satband")) {
162 satband = val;
163 break;
164 }
165 if (prop.equals("band")) {
166 band = val;
167 break;
168 }
169 if (prop.equals("id")) {
170 id = val;
171 break;
172 }
173 if (prop.equals("key")) {
174 key = val;
175 break;
176 }
177 if (prop.equals("latlon")) {
178 latlon = val;
179 break;
180 }
181 if (prop.equals("linele")) {
182 linele = val;
183 break;
184 }
185 if (prop.equals("loc")) {
186 loc = val;
187 break;
188 }
189 if (prop.equals("mag")) {
190 mag = val;
191 break;
192 }
193 if (prop.equals("num")) {
194 num = val;
195 break;
196 }
197 if (prop.equals("place")) {
198 place = val;
199 break;
200 }
201 if (prop.equals("size")) {
202 size = val;
203 break;
204 }
205 if (prop.equals("spac")) {
206 spac = val;
207 break;
208 }
209 if (prop.equals("unit")) {
210 unit = val;
211 break;
212 }
213 if (prop.equals("nav")) {
214 nav = val;
215 break;
216 }
217 if (prop.equals("center")) {
218 center = val;
219 break;
220 }
221 if (prop.equals("uleft")) {
222 uleft = val;
223 break;
224 }
225 if (prop.equals("lleft")) {
226 lleft = val;
227 break;
228 }
229 if (prop.equals("uright")) {
230 uright = val;
231 break;
232 }
233 if (prop.equals("lright")) {
234 lright = val;
235 break;
236 }
237 if (prop.equals("descriptor")) {
238 descriptor = val;
239 break;
240 }
241 if (prop.equals("group")) {
242 group = val;
243 break;
244 }
245 }
246 }
247
248 private boolean isKeyword(String prop) {
249 for (int i=0; i<ATTRS.length; i++) {
250 if (prop.equals(ATTRS[i])) return true;
251 }
252 return false;
253 }
254
255 public String getUser() {
256 return user;
257 }
258
259 public String getProj() {
260 return proj;
261 }
262
263 public String getPos() {
264 return pos;
265 }
266
267 public String getSatband() {
268 return satband;
269 }
270
271 public String getBand() {
272 return band;
273 }
274
275 public String getId() {
276 return id;
277 }
278
279 public String getKey() {
280 return key;
281 }
282
283 public String getLatlon() {
284 return latlon;
285 }
286
287 public String getLinele() {
288 return linele;
289 }
290
291 public String getLoc() {
292 return loc;
293 }
294
295 public String getMag() {
296 return mag;
297 }
298
299 public String getNum() {
300 return num;
301 }
302
303 public String getPlace() {
304 return place;
305 }
306
307 public String getSize() {
308 return size;
309 }
310
311 public String getSpac() {
312 return spac;
313 }
314
315 public String getUnit() {
316 return unit;
317 }
318
319 public String getNav() {
320 return nav;
321 }
322
323 public String getCenter() {
324 return center;
325 }
326
327 public String getUleft() {
328 return uleft;
329 }
330
331 public String getLleft() {
332 return lleft;
333 }
334
335 public String getUright() {
336 return uright;
337 }
338
339 public String getLright() {
340 return lright;
341 }
342
343 public String getDescriptor() {
344 return descriptor;
345 }
346
347 public String getGroup() {
348 return group;
349 }
350
351 private void parametersBreakdown(String url, List props, List vals) {
352 //System.out.println("url=" + url);
353 String prop;
354 String val;
355 //StringTokenizer tok = new StringTokenizer(url, "&");
356 StringTokenizer tok = new StringTokenizer(url, "/");
357 tok.nextToken();
358 this.server = tok.nextToken();
359 //System.out.println("server=" + server);
360 tok = new StringTokenizer(url, "&");
361 String remnant = tok.nextToken();
362 while (tok.hasMoreElements()) {
363 remnant = tok.nextToken();
364 StringTokenizer tok2 = new StringTokenizer(remnant, "=");
365 if (tok2.countTokens() >= 2) {
366 props.add(tok2.nextToken());
367 vals.add(tok2.nextToken());
368 }
369 }
370 /*
371 for (int i=0; i<props.size(); i++) {
372 System.out.println(props.get(i) + "=" + vals.get(i));
373 }
374 */
375 }
376 }