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