001 /*
002 * $Id: GeoLatLonSelection.java,v 1.108 2012/02/19 17:35:45 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.data;
032
033 import edu.wisc.ssec.mcidas.AreaDirectory;
034 import edu.wisc.ssec.mcidas.AREAnav;
035
036 import edu.wisc.ssec.mcidasv.Constants;
037
038 import java.awt.Component;
039 import java.awt.Dimension;
040 import java.awt.event.*;
041 import java.awt.Insets;
042 import java.awt.geom.Rectangle2D;
043 import java.rmi.RemoteException;
044 import java.util.ArrayList;
045 import java.util.Enumeration;
046 import java.util.Hashtable;
047 import java.util.List;
048
049 import javax.accessibility.*;
050 import javax.swing.*;
051 import javax.swing.event.*;
052
053 import org.slf4j.Logger;
054 import org.slf4j.LoggerFactory;
055
056 import ucar.unidata.data.DataChoice;
057 import ucar.unidata.data.DataSelection;
058 import ucar.unidata.data.DataSourceImpl;
059 import ucar.unidata.data.DataSelectionComponent;
060 import ucar.unidata.data.GeoLocationInfo;
061 import ucar.unidata.data.GeoSelection;
062 import ucar.unidata.geoloc.LatLonPoint;
063 import ucar.unidata.idv.ui.IdvUIManager;
064 import ucar.unidata.ui.LatLonWidget;
065 import ucar.unidata.util.GuiUtils;
066 import ucar.unidata.util.Misc;
067 import ucar.unidata.util.StringUtil;
068
069 import visad.VisADException;
070 import visad.data.mcidas.AREACoordinateSystem;
071 import visad.georef.*;
072
073
074 public class GeoLatLonSelection extends DataSelectionComponent implements Constants {
075
076 private static final Logger logger = LoggerFactory.getLogger(GeoLatLonSelection.class);
077
078 private GeoLocationInfo geoLocInfo;
079
080 /** The spacing used in the grid layout */
081 protected static final int GRID_SPACING = 3;
082
083 /** Used by derived classes when they do a GuiUtils.doLayout */
084 protected static final Insets GRID_INSETS = new Insets(GRID_SPACING,
085 GRID_SPACING,
086 GRID_SPACING,
087 GRID_SPACING);
088
089 DataChoice dataChoice;
090 MapProjection sampleProjection;
091
092 /** earth coordinates */
093 protected static final String TYPE_LATLON = "Latitude/Longitude";
094
095 /** image */
096 protected static final String TYPE_IMAGE = "Image Coordinates";
097
098 /** area */
099 protected static final String TYPE_AREA = "Area Coordinates";
100
101 /** flag for center */
102 protected static final String PLACE_CENTER = "CENTER";
103
104 /** flag for upper left */
105 protected static final String PLACE_ULEFT = "ULEFT";
106
107 /** Property for image default value lat/lon */
108 protected static final String PROP_LATLON = "LATLON";
109
110 /** Property for image default value line/ele */
111 protected static final String PROP_LINEELE = "LINELE";
112
113 /** Property for image default value loc */
114 protected static final String PROP_LOC = "LOC";
115
116 /** Property for image default value mag */
117 protected static final String PROP_MAG = "MAG";
118 protected static final String PROP_LMAG = "LMAG";
119 protected static final String PROP_EMAG = "EMAG";
120
121 /** Property for image default value place */
122 protected static final String PROP_PLACE = "PLACE";
123
124 /** Property for image default value size */
125 protected static final String PROP_SIZE = "SIZE";
126
127 /** Property for image default value unit */
128 protected static final String PROP_TYPE = "TYPE";
129
130 /** Property for line resolution */
131 protected static final String PROP_LRES = "LRES";
132 protected static final String PROP_PLRES = "PLRES";
133
134 /** Property for element resolution */
135 protected static final String PROP_ERES = "ERES";
136 protected static final String PROP_PERES = "PERES";
137
138 protected static final String PROP_READOUT = "READOUT";
139
140 /** This is the list of properties that are used in the advanced gui */
141 private static final String[] ADVANCED_PROPS = {
142 PROP_TYPE, PROP_PLACE, PROP_LOC, PROP_SIZE, PROP_MAG,
143 PROP_LMAG, PROP_EMAG, PROP_READOUT
144 };
145
146 /** This is the list of labels used for the advanced gui */
147 private static final String[] ADVANCED_LABELS = {
148 "Coordinate Type:", "Placement:", "Location:", " Image Size:",
149 "Magnification:", "", "", "Approx. Area: "
150 };
151
152 private static final String[] readoutLabels = {
153 "Center ",
154 "Upper Left ",
155 "Upper Right",
156 "Lower Left ",
157 "Lower Right"
158 };
159
160 private String kmLbl = " km";
161
162 /** Input for lat/lon center point */
163 protected LatLonWidget latLonWidget = new LatLonWidget();
164
165 /** Widget to hold the number of elements in the advanced */
166 JTextField numElementsFld = new JTextField();
167
168 /** Widget to hold the number of lines in the advanced */
169 JTextField numLinesFld = new JTextField();
170
171 /** Widget for the line center point in the advanced section */
172 JTextField centerLineFld = new JTextField();
173
174 /** Widget for the element center point in the advanced section */
175 JTextField centerElementFld = new JTextField();
176
177 JTextField lineMagFld = new JTextField();
178 JTextField eleMagFld = new JTextField();
179
180 /** Label used for the line center */
181 private JLabel centerLineLbl = new JLabel();
182
183 /** Label used for the element center */
184 private JLabel centerElementLbl = new JLabel();
185
186 /** Label used for the center latitude */
187 private JLabel centerLatLbl = new JLabel();
188
189 /** Label used for the center longitude */
190 private JLabel centerLonLbl = new JLabel();
191
192 /** _more_ */
193 private JToggleButton lockBtn;
194 private JButton fullResBtn;
195
196 private JPanel lMagPanel;
197 private JPanel eMagPanel;
198
199 /** Widget for the line magnfication in the advanced section */
200 protected JSlider lineMagSlider;
201
202 /** Label for the line mag. in the advanced section */
203 JLabel lineMagLbl = new JLabel();
204 JLabel lineResLbl = new JLabel();
205
206 JLabel rawSizeLbl = new JLabel();
207
208 /** Widget for the element magnfication in the advanced section */
209 protected JSlider elementMagSlider;
210
211 /** Label for the element mag. in the advanced section */
212 JLabel elementMagLbl = new JLabel();
213 JLabel elementResLbl = new JLabel();
214
215 /** location panel */
216 protected GuiUtils.CardLayoutPanel locationPanel;
217
218 /** flag for setting properties */
219 private boolean amSettingProperties = false;
220
221 JComboBox coordinateTypeComboBox;
222 JComboBox locationComboBox;
223
224 String[] coordinateTypes = { TYPE_LATLON, TYPE_IMAGE, TYPE_AREA };
225 String[] locations = {"Center", "Upper Left"};
226
227 // static double dNaN = Double.NaN;
228
229 /** the place string */
230 private String defaultType = TYPE_LATLON;
231 private String place;
232 private String defaultPlace = PLACE_CENTER;
233 private int defaultNumLines = 1000;
234 private int defaultNumEles = 1000;
235 private int numLines = defaultNumLines;
236 private int numEles = defaultNumEles;
237 private double latitude;
238 private double defaultLat = Double.NaN;
239 private double longitude;
240 private double defaultLon = Double.NaN;
241 private boolean resetLatLon = true;
242 private int imageLine;
243 private int areaLine;
244 private int defaultLine = -1;
245 private int imageElement;
246 private int areaElement;
247 private int defaultElement = -1;
248 private int lineMag;
249 private double dLineMag;
250 private int defaultLineMag;
251 private int elementMag;
252 private double dElementMag;
253 private int defaultElementMag;
254 private boolean isLineEle = false;
255 private double lRes;
256 protected double baseLRes = 0.0;
257 private double eRes;
258 protected double baseERes = 0.0;
259
260 private Hashtable properties;
261 private int uLLine;
262 private int uLEle;
263 private int centerLine;
264 private int centerEle;
265 protected boolean amUpdating = false;
266
267
268 /** Maps the PROP_ property name to the gui component */
269 private Hashtable propToComps = new Hashtable();
270
271 /** size label */ JLabel sizeLbl;
272
273 /** base number of lines */
274 private double baseNumLines;
275
276 /** base number of elements */
277 private double baseNumElements;
278
279 private DataSourceImpl dataSource;
280 private static DataSourceImpl lastDataSource;
281 private AreaDirectory previewDir;
282 private AREAnav previewNav;
283 private AREAnav areaNav;
284
285 private List latLonLbls = new ArrayList();
286 private List linEleImageLbls = new ArrayList();
287 private List linEleAreaLbls = new ArrayList();
288 private JPanel latLonPanel;
289 private JPanel lineElementPanel;
290
291 /**
292 * limit of slider
293 */
294 private static final int SLIDER_MAX = 1;
295 private static final int SLIDER_MIN = -29;
296 private static final int SLIDER_WIDTH = 150;
297 private static final int SLIDER_HEIGHT = 16;
298
299 /**
300 * Keep track of the lines to element ratio
301 */
302 private double linesToElements = 1.0;
303
304 double[][] imageEL = new double[2][5];
305 double[][] areaEL = new double[2][5];
306 double[][] displayEL = new double[2][5];
307 double[][] latLon = new double[2][5];
308
309 private int[] previewDirBlk;
310
311 private int previewLineRes = 1;
312 private int previewEleRes = 1;
313 private int maxLines = 0;
314 private int maxEles = 0;
315
316 private double bLRes = 0.0;
317 private double bERes = 0.0;
318
319 private List readoutLLWidget = new ArrayList();
320 private List readoutLatFld = new ArrayList();
321 private List readoutLonFld = new ArrayList();
322 private JPanel latLonReadoutPanel;
323
324 private List readoutImageLinFld = new ArrayList();
325 private List readoutImageEleFld = new ArrayList();
326 private JPanel lineElementImageReadoutPanel;
327
328 private List readoutAreaLinFld = new ArrayList();
329 private List readoutAreaEleFld = new ArrayList();
330 private JPanel lineElementAreaReadoutPanel;
331
332 private GuiUtils.CardLayoutPanel readoutPanel;
333
334 public GeoLatLonSelection(DataSourceImpl dataSource,
335 DataChoice dataChoice, Hashtable initProps, MapProjection sample,
336 AreaDirectory dir, AREAnav nav)
337 throws VisADException, RemoteException {
338 super("Advanced");
339
340 if (dataSource != lastDataSource) {
341 this.resetLatLon = true;
342 }
343 lastDataSource = dataSource;
344
345 this.properties = initProps;
346 this.dataSource = dataSource;
347 this.dataChoice = dataChoice;
348 this.sampleProjection = sample;
349 this.previewDir = dir;
350
351 setBaseNumLines(dir.getLines());
352 setBaseNumElements(dir.getElements());
353 this.previewNav = nav;
354 previewDirBlk = this.previewDir.getDirectoryBlock();
355 int areaLinRes = previewDirBlk[11];
356 int areaEleRes = previewDirBlk[12];
357 this.areaNav = this.previewNav;
358 this.areaNav.setRes(areaLinRes, areaEleRes);
359 this.areaNav.setImageStart(previewDirBlk[5], previewDirBlk[6]);
360
361 int numberOfLines;
362 int numberOfElements;
363 if (properties.containsKey(PROP_SIZE)) {
364 String str = (String)properties.get(PROP_SIZE);
365 String[] strs = StringUtil.split(str, " ", 2);
366 numberOfLines = Integer.parseInt(strs[0]);
367 numberOfElements = Integer.parseInt(strs[1]);
368 } else {
369 try {
370 numberOfLines = this.previewDir.getLines();
371 numberOfElements = this.previewDir.getElements();
372 if (numberOfLines < defaultNumLines)
373 defaultNumLines = numberOfLines;
374 if (numberOfElements < defaultNumEles)
375 defaultNumEles = numberOfElements;
376 numberOfLines = defaultNumLines;
377 numberOfElements = defaultNumEles;
378 } catch (Exception e) {
379 logger.error("no directory", e);
380 return;
381 }
382 }
383 setNumLines(numberOfLines);
384 setNumEles(numberOfElements);
385 if (properties.containsKey(PROP_MAG)) {
386 String str = (String)properties.get(PROP_MAG);
387 String[] strs = StringUtil.split(str, " ", 2);
388 this.defaultLineMag = Integer.parseInt(strs[0]);
389 this.defaultElementMag = Integer.parseInt(strs[1]);
390 this.dLineMag = (double)this.defaultLineMag;
391 this.dElementMag = (double)this.defaultElementMag;
392 } else {
393 this.dLineMag = -(double)this.previewDir.getLines()/(double)numberOfLines;
394 this.dElementMag = -(double)this.previewDir.getElements()/(double)numberOfElements;
395 this.defaultLineMag = (int)(Math.floor(dLineMag));
396 this.defaultElementMag = (int)(Math.floor(dElementMag));
397 }
398 setLineMag(this.defaultLineMag);
399 setElementMag(this.defaultElementMag);
400
401 try {
402 if (properties.containsKey(PROP_LRES)) {
403 this.bLRes = Double.parseDouble((String)properties.get(PROP_LRES));
404 //if (dir.getValue(11) == 1) this.bLRes = this.previewDir.getCenterLatitudeResolution();
405 this.baseLRes = this.bLRes * (double)(dir.getValue(11));
406 setLRes(this.baseLRes * Math.abs(this.defaultLineMag));
407 }
408 if (properties.containsKey(PROP_ERES)) {
409 this.bERes = Double.parseDouble((String)properties.get(PROP_ERES));
410 //if (dir.getValue(12) == 1) this.bERes = this.previewDir.getCenterLongitudeResolution();
411 this.baseERes = this.bERes * (double)(dir.getValue(12));
412 setERes(this.baseERes * Math.abs(this.defaultElementMag));
413 }
414 } catch (Exception e) {
415 logger.error("unable to get resolution", e);
416
417 }
418 setBLRes(this.bLRes);
419 setBERes(this.bERes);
420 if (this.baseLRes == 0.0)
421 this.baseLRes = this.previewDir.getCenterLatitudeResolution();
422 if (this.baseERes == 0.0)
423 this.baseERes = this.previewDir.getCenterLongitudeResolution();
424
425 this.place = getPlace();
426 if (properties.containsKey(PROP_PLACE)) {
427 setPlace((String)properties.get(PROP_PLACE));
428 }
429
430 if (properties.containsKey(PROP_PLRES)) {
431 this.previewLineRes = Integer.parseInt((String)properties.get(PROP_PLRES));
432 }
433 if (properties.containsKey(PROP_PERES)) {
434 this.previewEleRes = Integer.parseInt((String)properties.get(PROP_PERES));
435 }
436
437 if (this.resetLatLon) {
438 if (this.previewDir != null) {
439 setLatitude(this.previewDir.getCenterLatitude());
440 setLongitude(this.previewDir.getCenterLongitude());
441 }
442 } else {
443 setLatitude(this.latitude);
444 setLongitude(this.longitude);
445 }
446 convertToLineEle();
447
448 if (properties.containsKey(PROP_LATLON)) {
449 String str = (String)properties.get(PROP_LATLON);
450 String[] strs = StringUtil.split(str, " ", 2);
451 setLatitude(Double.parseDouble(strs[0]));
452 setLongitude(Double.parseDouble(strs[1]));
453 convertToLineEle();
454 this.isLineEle = false;
455 } else if (properties.containsKey(PROP_LINEELE)) {
456 String str = (String)properties.get(PROP_LINEELE);
457 String[] strs = StringUtil.split(str, " ", 3);
458 setLine(Integer.parseInt(strs[0]));
459 setElement(Integer.parseInt(strs[1]));
460 convertToLatLon();
461 this.isLineEle = true;
462 }
463
464 if (this.defaultLineMag > 1) {
465 numberOfLines = numberOfLines * this.defaultLineMag;
466 setNumLines(numberOfLines);
467 setLRes(lRes/this.defaultLineMag);
468 this.defaultLineMag = 1;
469 setLineMag(this.defaultLineMag);
470 }
471 if (this.defaultElementMag > 1) {
472 numberOfElements = numberOfElements * this.defaultElementMag;
473 setNumEles(numberOfElements);
474 setERes(lRes/this.defaultElementMag);
475 this.defaultElementMag = 1;
476 setElementMag(this.defaultElementMag);
477 }
478 }
479
480 protected JComponent doMakeContents() {
481 String[] propArray = getAdvancedProps();
482 String[] labelArray = getAdvancedLabels();
483 Insets dfltGridSpacing = new Insets(4, 0, 4, 0);
484 String dfltLblSpacing = " ";
485 List allComps = new ArrayList();
486
487 for (int propIdx = 0; propIdx < propArray.length; propIdx++) {
488 JComponent propComp = null;
489 String prop = propArray[propIdx];
490 if (prop.equals(PROP_TYPE)) {
491 allComps.add(new JLabel(" "));
492 allComps.add(new JLabel(" "));
493 coordinateTypeComboBox = new JComboBox(coordinateTypes);
494 coordinateTypeComboBox.addActionListener(new ActionListener() {
495 public void actionPerformed(ActionEvent ae) {
496 int selectedIndex = coordinateTypeComboBox.getSelectedIndex();
497 flipLocationPanel(selectedIndex);
498 flipReadoutPanel(selectedIndex);
499 }
500 });
501 propComp = (JComponent)coordinateTypeComboBox;
502 }
503 else if (prop.equals(PROP_LOC)) {
504 locationComboBox = new JComboBox(locations);
505 setPlace(this.place);
506 locationComboBox.addActionListener(new ActionListener() {
507 public void actionPerformed(ActionEvent ae) {
508 String selected = getPlace();
509 cyclePlace();
510 }
511 });
512 propComp = (JComponent)locationComboBox;
513 addPropComp(PROP_LOC, propComp);
514
515 ActionListener latLonChange =new ActionListener() {
516 public void actionPerformed(ActionEvent ae) {
517 String type = getCoordinateType();
518 if (type.equals(TYPE_LATLON)) {
519 setLatitude();
520 setLongitude();
521 convertToLineEle();
522 getGeoLocationInfo();
523 } else {
524 setLineElement();
525 convertToLatLon();
526 getGeoLocationInfo();
527 }
528 }
529 };
530
531 FocusListener linEleFocusChange = new FocusListener() {
532 public void focusGained(FocusEvent fe) {
533 }
534 public void focusLost(FocusEvent fe) {
535 setLineElement();
536 convertToLatLon();
537 getGeoLocationInfo();
538 }
539 };
540
541 if (latLonWidget == null)
542 latLonWidget = new LatLonWidget(latLonChange);
543
544 FocusListener latLonFocusChange = new FocusListener() {
545 public void focusGained(FocusEvent fe) {
546 JTextField latFld = latLonWidget.getLatField();
547 latFld.setCaretPosition(latFld.getText().length());
548 JTextField lonFld = latLonWidget.getLonField();
549 lonFld.setCaretPosition(lonFld.getText().length());
550 }
551 public void focusLost(FocusEvent fe) {
552 setLatitude();
553 setLongitude();
554 convertToLineEle();
555 getGeoLocationInfo();
556 }
557 };
558
559 if (!this.isLineEle) {
560 latLonWidget.setLatLon(this.latitude, this.longitude);
561 }
562 String lineStr = "";
563 String eleStr = "";
564 setLine(this.imageLine);
565 setElement(this.imageElement);
566 if ((this.imageLine >= 0) && (this.imageElement >= 0)) {
567 lineStr =Integer.toString(this.imageLine);
568 eleStr =Integer.toString(this.imageElement);
569 }
570 centerLineFld = new JTextField(lineStr, 3);
571 centerLineFld.addActionListener(latLonChange);
572 centerLineFld.addFocusListener(linEleFocusChange);
573 final String lineField = "";
574 centerElementFld = new JTextField(eleStr, 3);
575 centerElementFld.addActionListener(latLonChange);
576 centerElementFld.addFocusListener(linEleFocusChange);
577 final JButton centerPopupBtn =
578 GuiUtils.getImageButton(
579 "/auxdata/ui/icons/MapIcon16.png", getClass());
580 centerPopupBtn.setToolTipText("Center on current displays");
581
582 centerPopupBtn.addActionListener(new ActionListener() {
583 public void actionPerformed(ActionEvent ae) {
584 dataSource.getDataContext().getIdv().getIdvUIManager().popupCenterMenu(
585 centerPopupBtn, latLonWidget);
586 }
587 });
588
589 JComponent centerPopup = GuiUtils.inset(centerPopupBtn,
590 new Insets(0, 0, 0, 4));
591
592
593 GuiUtils.tmpInsets = dfltGridSpacing;
594 JTextField latFld = latLonWidget.getLatField();
595 JTextField lonFld = latLonWidget.getLonField();
596 latFld.addFocusListener(latLonFocusChange);
597 lonFld.addFocusListener(latLonFocusChange);
598 latLonPanel = GuiUtils.hbox(new Component[] {
599 centerLatLbl = GuiUtils.rLabel(" Lat:" + dfltLblSpacing),
600 latFld,
601 centerLonLbl = GuiUtils.rLabel(" Lon:" + dfltLblSpacing),
602 lonFld,
603 new JLabel(" "), centerPopup
604 });
605
606 lineElementPanel =
607 GuiUtils.hbox(new Component[] {
608 centerLineLbl =
609 GuiUtils.rLabel(" Line:" + dfltLblSpacing),
610 centerLineFld,
611 centerElementLbl = GuiUtils.rLabel(" Element:"
612 + dfltLblSpacing),
613 centerElementFld });
614
615 locationPanel = new GuiUtils.CardLayoutPanel();
616 locationPanel.addCard(latLonPanel);
617 locationPanel.addCard(lineElementPanel);
618
619 if (propComp != null) {
620 allComps.add(GuiUtils.rLabel(labelArray[propIdx]));
621 allComps.add(GuiUtils.left(propComp));
622 }
623 propComp = GuiUtils.hbox(new Component[] { locationPanel }, 1);
624 if (propComp != null) {
625 allComps.add(GuiUtils.rLabel(" "));
626 allComps.add(GuiUtils.left(propComp));
627 }
628 propComp = null;
629 } else if (prop.equals(PROP_SIZE)) {
630 ActionListener sizeChange =new ActionListener() {
631 public void actionPerformed(ActionEvent ae) {
632 int lines = getNumLines() * Math.abs(getLineMag());
633 if (lines > maxLines) lines = maxLines;
634 setBaseNumLines(lines);
635 int eles = getNumEles() * Math.abs(getElementMag());
636 if (eles > maxEles) eles = maxEles;
637 setBaseNumElements(eles);
638 getGeoLocationInfo();
639 }
640 };
641 FocusListener sizeFocusChange = new FocusListener() {
642 public void focusGained(FocusEvent fe) {
643 }
644 public void focusLost(FocusEvent fe) {
645 int lines = getNumLines() * Math.abs(getLineMag());
646 if (lines > maxLines) lines = maxLines;
647 setBaseNumLines(lines);
648 int eles = getNumEles() * Math.abs(getElementMag());
649 if (eles > maxEles) eles = maxEles;
650 setBaseNumElements(eles);
651 getGeoLocationInfo();
652 }
653 };
654
655 this.maxLines = this.previewDir.getLines();
656 this.maxEles = this.previewDir.getElements();
657
658 int lmag = getLineMag();
659 int emag = getElementMag();
660 if (lmag < 0) this.numLines = this.maxLines / Math.abs(lmag);
661 if (emag < 0) this.numEles = this.maxEles / Math.abs(emag);
662
663 setNumLines(this.numLines);
664 numLinesFld = new JTextField(Integer.toString(this.numLines), 4);
665 numLinesFld.addActionListener(sizeChange);
666 numLinesFld.addFocusListener(sizeFocusChange);
667 setNumEles(this.numEles);
668 numElementsFld = new JTextField(Integer.toString(this.numEles), 4);
669 numElementsFld.addActionListener(sizeChange);
670 numElementsFld.addFocusListener(sizeFocusChange);
671 numLinesFld.setToolTipText("Number of lines");
672 numElementsFld.setToolTipText("Number of elements");
673 GuiUtils.tmpInsets = dfltGridSpacing;
674 sizeLbl = GuiUtils.lLabel("");
675
676 fullResBtn = GuiUtils.makeImageButton(
677 "/auxdata/ui/icons/arrow_out.png", this,
678 "setToFullResolution");
679 fullResBtn.setContentAreaFilled(false);
680 fullResBtn.setToolTipText("Set fields to retrieve full image");
681
682 lockBtn =
683 GuiUtils.getToggleImageButton(IdvUIManager.ICON_UNLOCK,
684 IdvUIManager.ICON_LOCK, 0, 0, true);
685 lockBtn.setContentAreaFilled(false);
686 lockBtn.setSelected(true);
687 lockBtn.setToolTipText(
688 "Unlock to automatically change size when changing magnification");
689
690 rawSizeLbl = new JLabel(" Raw size: " + this.maxLines + " X " +
691 this.maxEles);
692 JPanel sizePanel =
693 GuiUtils.left(GuiUtils.doLayout(new Component[] {
694 numLinesFld,
695 new JLabel(" X "), numElementsFld, sizeLbl, new JLabel(" "),
696 fullResBtn, new JLabel(" "), lockBtn,
697 rawSizeLbl }, 9, GuiUtils.WT_N, GuiUtils.WT_N));
698 addPropComp(PROP_SIZE, propComp = sizePanel);
699 } else if (prop.equals(PROP_MAG)) {
700 propComp = GuiUtils.hbox(new Component[] { new JLabel("") }, 1);
701 addPropComp(PROP_MAG, propComp);
702 } else if (prop.equals(PROP_LMAG)) {
703 boolean oldAmSettingProperties = amSettingProperties;
704 amSettingProperties = true;
705 ChangeListener lineListener =
706 new javax.swing.event.ChangeListener() {
707 public void stateChanged(ChangeEvent evt) {
708 if (amSettingProperties) {
709 return;
710 }
711 int val = getMagValue(lineMagSlider);
712 setLineMag(val);
713 amUpdating = true;
714 lineMagSliderChanged(!lockBtn.isSelected());
715 amUpdating = false;
716 getGeoLocationInfo();
717 }
718 };
719 ActionListener lineMagChange =new ActionListener() {
720 public void actionPerformed(ActionEvent ae) {
721 if (amSettingProperties) {
722 return;
723 }
724 setLineMag();
725 changeLineMagSlider(!lockBtn.isSelected());
726 getGeoLocationInfo();
727 }
728 };
729 FocusListener lineMagFocusChange = new FocusListener() {
730 public void focusGained(FocusEvent fe) {
731 }
732 public void focusLost(FocusEvent fe) {
733 if (amSettingProperties) {
734 return;
735 }
736 setLineMag();
737 changeLineMagSlider(!lockBtn.isSelected());
738 getGeoLocationInfo();
739 }
740 };
741 JComponent[] lineMagComps =
742 GuiUtils.makeSliderPopup(SLIDER_MIN, SLIDER_MAX, 0,
743 lineListener);
744 lineMagSlider = (JSlider) lineMagComps[1];
745 lineMagSlider.setPreferredSize(new Dimension(SLIDER_WIDTH,SLIDER_HEIGHT));
746 lineMagSlider.setMajorTickSpacing(1);
747 lineMagSlider.setSnapToTicks(true);
748 lineMagSlider.setExtent(1);
749 int mag = getLineMag();
750 setLineMagSlider(mag);
751 lineMagComps[0].setToolTipText(
752 "Change the line magnification");
753 lineMagSlider.setToolTipText(
754 "Slide to set line magnification factor");
755 String str = "Line Mag=";
756 lineMagFld = new JTextField(Integer.toString(mag),3);
757 lineMagFld.addFocusListener(lineMagFocusChange);
758 lineMagFld.addActionListener(lineMagChange);
759 lineMagLbl =
760 GuiUtils.getFixedWidthLabel(StringUtil.padLeft(str, 4));
761 str = truncateNumericString(Double.toString(this.baseLRes*Math.abs(getLineMag())), 1);
762 str = " Res=" + str + kmLbl;
763 lineResLbl =
764 GuiUtils.getFixedWidthLabel(StringUtil.padLeft(str, 4));
765 amSettingProperties = oldAmSettingProperties;
766
767 GuiUtils.tmpInsets = dfltGridSpacing;
768 lMagPanel = GuiUtils.doLayout(new Component[] {
769 lineMagLbl, lineMagFld,
770 GuiUtils.inset(lineMagComps[1],
771 new Insets(0, 4, 0, 0)), lineResLbl, }, 5,
772 GuiUtils.WT_N, GuiUtils.WT_N);
773 propComp = GuiUtils.hbox(new Component[] { new JLabel(" "), lMagPanel }, 2);
774 addPropComp(PROP_LMAG, propComp = lMagPanel);
775 } else if (prop.equals(PROP_EMAG)) {
776 boolean oldAmSettingProperties = amSettingProperties;
777 amSettingProperties = true;
778 ChangeListener elementListener = new ChangeListener() {
779 public void stateChanged(
780 javax.swing.event.ChangeEvent evt) {
781 if (amSettingProperties) {
782 return;
783 }
784 int val = getMagValue(elementMagSlider);
785 setElementMag(val);
786 amUpdating = true;
787 elementMagSliderChanged(true);
788 amUpdating = false;
789 getGeoLocationInfo();
790 }
791 };
792 ActionListener eleMagChange =new ActionListener() {
793 public void actionPerformed(ActionEvent ae) {
794 if (amSettingProperties) {
795 return;
796 }
797 setElementMag();
798 changeEleMagSlider(!lockBtn.isSelected());
799 getGeoLocationInfo();
800 }
801 };
802 FocusListener eleMagFocusChange = new FocusListener() {
803 public void focusGained(FocusEvent fe) {
804 }
805 public void focusLost(FocusEvent fe) {
806 if (amSettingProperties) {
807 return;
808 }
809 setElementMag();
810 changeEleMagSlider(!lockBtn.isSelected());
811 getGeoLocationInfo();
812 }
813 };
814 JComponent[] elementMagComps =
815 GuiUtils.makeSliderPopup(SLIDER_MIN, SLIDER_MAX, 0,
816 elementListener);
817 elementMagSlider = (JSlider) elementMagComps[1];
818 elementMagSlider.setPreferredSize(new Dimension(SLIDER_WIDTH,SLIDER_HEIGHT));
819 elementMagSlider.setExtent(1);
820 elementMagSlider.setMajorTickSpacing(1);
821 elementMagSlider.setSnapToTicks(true);
822 int mag = getElementMag();
823 setElementMagSlider(mag);
824 elementMagComps[0].setToolTipText(
825 "Change the element magnification");
826 elementMagSlider.setToolTipText(
827 "Slide to set element magnification factor");
828 eleMagFld = new JTextField(Integer.toString(mag),3);
829 eleMagFld.addFocusListener(eleMagFocusChange);
830 eleMagFld.addActionListener(eleMagChange);
831 String str = "Ele Mag=";
832 elementMagLbl =
833 GuiUtils.getFixedWidthLabel(StringUtil.padLeft(str, 4));
834 str = truncateNumericString(Double.toString(this.baseERes*Math.abs(getElementMag())), 1);
835 str = " Res=" + str + kmLbl;
836 elementResLbl =
837 GuiUtils.getFixedWidthLabel(StringUtil.padLeft(str, 4));
838 amSettingProperties = oldAmSettingProperties;
839
840 GuiUtils.tmpInsets = dfltGridSpacing;
841 eMagPanel = GuiUtils.doLayout(new Component[] {
842 elementMagLbl, eleMagFld,
843 GuiUtils.inset(elementMagComps[1],
844 new Insets(0, 4, 0, 0)), elementResLbl, }, 5,
845 GuiUtils.WT_N, GuiUtils.WT_N);
846 propComp = GuiUtils.hbox(new Component[] { new JLabel(" "), eMagPanel }, 2);
847 addPropComp(PROP_EMAG, propComp = eMagPanel);
848 } else if (prop.equals(PROP_READOUT)) {
849 allComps.add(new JLabel(" "));
850 allComps.add(new JLabel(" "));
851 for (int i=0; i<5; i++) {
852 latLonLbls.add(GuiUtils.getFixedWidthLabel(" "));
853 linEleImageLbls.add(GuiUtils.getFixedWidthLabel(" "));
854 linEleAreaLbls.add(GuiUtils.getFixedWidthLabel(" "));
855 }
856 latLonReadoutPanel = GuiUtils.left(GuiUtils.doLayout(
857 latLonLbls, 1, GuiUtils.WT_N, GuiUtils.WT_Y));
858 lineElementImageReadoutPanel = GuiUtils.left(GuiUtils.doLayout(
859 linEleImageLbls, 1, GuiUtils.WT_N, GuiUtils.WT_Y));
860 lineElementAreaReadoutPanel = GuiUtils.left(GuiUtils.doLayout(
861 linEleAreaLbls, 1, GuiUtils.WT_N, GuiUtils.WT_Y));
862
863 readoutPanel = new GuiUtils.CardLayoutPanel();
864 readoutPanel.addCard(latLonReadoutPanel);
865 readoutPanel.addCard(lineElementImageReadoutPanel);
866 readoutPanel.addCard(lineElementAreaReadoutPanel);
867
868 propComp = GuiUtils.hbox(new Component[] { readoutPanel }, 1);
869 addPropComp(PROP_READOUT, propComp);
870 if (propComp != null) {
871 allComps.add(GuiUtils.rLabel(labelArray[propIdx]));
872 allComps.add(GuiUtils.left(propComp));
873 }
874 propComp = null;
875 }
876 if (propComp != null) {
877 allComps.add(GuiUtils.rLabel(labelArray[propIdx]));
878 allComps.add(GuiUtils.left(propComp));
879 }
880 }
881 GuiUtils.tmpInsets = GRID_INSETS;
882 JPanel imagePanel = GuiUtils.doLayout(allComps, 2, GuiUtils.WT_NY,
883 GuiUtils.WT_N);
884 getGeoLocationInfo();
885 return GuiUtils.top(imagePanel);
886 }
887
888 private void updateReadout() {
889 int numCols = 7;
890 for (int i=0; i<5; i++) {
891 String str = readoutLabels[i] +
892 " Lat: " + formatDoubleCoord(numCols, latLon[0][i]) +
893 " Lon: " + formatDoubleCoord(numCols, latLon[1][i]);
894 ((JLabel)latLonLbls.get(i)).setText(str);
895
896 String lineStr = formatIntegerCoord(numCols, imageEL[1][i]);
897 String eleStr = formatIntegerCoord(numCols, imageEL[0][i]);
898 str = readoutLabels[i] + " Line: " + lineStr +
899 " Element: " + eleStr;
900 ((JLabel)linEleImageLbls.get(i)).setText(str);
901
902 lineStr = formatIntegerCoord(numCols, areaEL[1][i]);
903 eleStr = formatIntegerCoord(numCols, areaEL[0][i]);
904 str = readoutLabels[i] + " Line: " + lineStr +
905 " Element: " + eleStr;
906 ((JLabel)linEleAreaLbls.get(i)).setText(str);
907 }
908 }
909
910 private String formatIntegerCoord(int cols, double val) {
911 String outStr = Misc.MISSING;
912 Double dbl = new Double(val);
913 if (!dbl.isNaN()) {
914 int ival = (int)Math.floor(val + 0.5);
915 outStr = Integer.toString(ival);
916 }
917 int len = outStr.length() + 1;
918 while (len < cols) {
919 outStr = new String(" ").concat(outStr);
920 len++;
921 }
922 return outStr;
923 }
924
925 private String formatDoubleCoord(int cols, double val) {
926 String outStr = Misc.MISSING;
927 Double dbl = new Double(val);
928 if (!dbl.isNaN()) {
929 outStr = Double.toString(val);
930 if (outStr.length() > cols)
931 outStr = outStr.substring(0, cols);
932 }
933 int len = outStr.length();
934 while (len < cols) {
935 outStr = new String(" ").concat(outStr);
936 len++;
937 }
938 return outStr;
939 }
940
941 /**
942 * Change coordinate type panel
943 */
944 protected void flipLocationPanel(int locPanel) {
945 int nowPlaying = locationPanel.getVisibleIndex();
946 if (locPanel > 0) {
947 if (nowPlaying == 0) {
948 locationPanel.flip();
949 }
950 setIsLineEle(true);
951 String type = getCoordinateType();
952 int ele = this.imageElement;
953 int lin = this.imageLine;
954 if (type.equals(TYPE_AREA)) {
955 ele = this.areaElement;
956 lin = this.areaLine;
957 }
958 setElement(ele);
959 setLine(lin);
960 } else {
961 if (nowPlaying > 0) locationPanel.flip();
962 setIsLineEle(false);
963 }
964 }
965
966 /**
967 * Change readout type panel
968 */
969 protected void flipReadoutPanel(int roPanel) {
970 readoutPanel.show(roPanel);
971 }
972
973 /**
974 * Set to full resolution
975 */
976 public void setToFullResolution() {
977 setPlace(PLACE_CENTER);
978 setLatitude(this.previewDir.getCenterLatitude());
979 setLongitude(this.previewDir.getCenterLongitude());
980 convertToLinEle();
981 setNumLines(this.maxLines);
982 setNumEles(this.maxEles);
983 setBaseNumLines(this.maxLines);
984 setBaseNumElements(this.maxEles);
985 setLineMag(1);
986 setElementMag(1);
987 setLineMagSlider(1);
988 setLRes(this.baseLRes);
989 setElementMagSlider(1);
990 setERes(this.baseERes);
991 amUpdating = true;
992 lineMagSliderChanged(false);
993 elementMagSliderChanged(false);
994 amUpdating = false;
995 getGeoLocationInfo();
996 }
997
998 @Override public void applyToDataSelection(DataSelection dataSelection) {
999 logger.trace("dataSelection={}", dataSelection);
1000
1001 if (dataSelection == null) {
1002 dataSelection = new DataSelection(true);
1003 }
1004
1005 if (geoLocInfo == null) {
1006 getGeoLocationInfo();
1007 }
1008
1009 GeoLocationInfo geoInfo = geoLocInfo;
1010 if (geoInfo == null) {
1011 logger.trace("err, wtf?");
1012 dataSelection = null;
1013 return;
1014 }
1015
1016 String coordType = getCoordinateType();
1017
1018 if (!isLineEle) {
1019 logger.trace("dealing with LALO coords for datasel={}", dataSelection);
1020 double lat = getLatitude();
1021 double lon = getLongitude();
1022 if (lat > 90.0 && lon> 360.0) {
1023 convertToLatLon();
1024 lat = getLatitude();
1025 lon = getLongitude();
1026 }
1027 // if ((lat == dNaN) || (lon == dNaN)) {
1028 // return;
1029 // }
1030 if ((Double.isNaN(lat) || (Double.isNaN(lon)))) {
1031 return;
1032 }
1033
1034 String latString = Double.toString(lat);
1035 if (latString.length() > 8) {
1036 latString = latString.substring(0,7);
1037 }
1038 String lonString = Double.toString(lon);
1039 if (lonString.length() > 9) {
1040 lonString = lonString.substring(0,8);
1041 }
1042 dataSelection.putProperty(PROP_LATLON, (latString + " " + lonString));
1043 } else {
1044 logger.trace("dealing with line-ele coords for datasel={}", dataSelection);
1045 int lin = getLine();
1046 int ele = getElement();
1047 if ((Double.isNaN(lin)) || (Double.isNaN(ele))) {
1048 return;
1049 }
1050 // if ((lin == dNaN) || (ele == dNaN)) return;
1051
1052 String typeStr = " I";
1053 if (coordType.equals(TYPE_AREA)) typeStr = " F";
1054 String linString = Integer.toString(lin);
1055 String eleString = Integer.toString(ele);
1056 dataSelection.putProperty(PROP_LINEELE, (linString + " " + eleString + typeStr));
1057 }
1058
1059 dataSelection.putProperty(PROP_PLACE, getPlace());
1060 dataSelection.putProperty(PROP_MAG, (getLineMag() + " " + getElementMag()));
1061
1062 GeoSelection geoSelection = new GeoSelection(geoInfo);
1063 dataSelection.setGeoSelection(geoSelection);
1064
1065 int nlins = getNumLines();
1066 int neles = getNumEles();
1067 if (nlins > 0 && neles > 0) {
1068 dataSelection.putProperty(PROP_SIZE, (nlins + " " + neles));
1069 }
1070 logger.trace("dataChoice={} dataSelection={}", dataChoice, dataSelection);
1071 dataChoice.setDataSelection(dataSelection);
1072
1073 this.dataSource.setDataSelection(dataSelection);
1074 }
1075
1076 @Override public boolean getShowInControlProperties() {
1077 return false;
1078 }
1079
1080 public GeoLocationInfo getGeoLocationInfo() {
1081 geoLocInfo = null;
1082 double[][] el = convertToDisplayCoords();
1083 int ele = (int)Math.floor(el[0][0] + 0.5);
1084 if (ele < 0) ele = 0;
1085 int lin = (int)Math.floor(el[1][0] + 0.5);
1086 if (lin < 0) lin = 0;
1087 geoLocInfo = getGeoLocationInfo(lin, ele);
1088 return geoLocInfo;
1089 }
1090
1091 protected GeoLocationInfo getGeoLocationInfo(int lin, int ele) {
1092 int nLin = getNumLines();
1093 if (nLin > 0) {
1094 int nEle = getNumEles();
1095 if (nEle > 0) {
1096 int lMag = getLineMag();
1097 if (lMag > 1) return geoLocInfo;
1098 int eMag = getElementMag();
1099 if (eMag > 1) return geoLocInfo;
1100 geoLocInfo = makeGeoLocationInfo(lin, ele, nLin, nEle,
1101 lMag, eMag);
1102 return geoLocInfo;
1103 }
1104 }
1105 for (int i = 0; i < 2; i++) {
1106 for (int j = 0; j < 5; j++) {
1107 latLon[i][j] = Double.NaN;
1108 imageEL[i][j] = Double.NaN;
1109 areaEL[i][j] = Double.NaN;
1110 displayEL[i][j] = Double.NaN;
1111 }
1112 }
1113 updateReadout();
1114 setLine(-1);
1115 setElement(-1);
1116 return null;
1117 }
1118
1119 private GeoLocationInfo makeGeoLocationInfo(int lin, int ele, int nlins, int neles,
1120 int linMag, int eleMag) {
1121 geoLocInfo = null;
1122
1123 String plc = getPlace();
1124 String type = getCoordinateType();
1125
1126 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1127 Rectangle2D mapArea = macs.getDefaultMapArea();
1128 double previewXDim = mapArea.getWidth();
1129 double previewYDim = mapArea.getHeight();
1130
1131 double dLine = (double)nlins/(2.0*this.previewLineRes)*Math.abs(linMag);
1132 double dEle = (double)neles/(2.0*this.previewEleRes)*Math.abs(eleMag);
1133
1134 if (plc.equals(PLACE_CENTER)) {
1135 displayEL[0][0] = ele;
1136 displayEL[1][0] = lin;
1137 displayEL[0][1] = ele - dEle;
1138 if (displayEL[0][1] < 0) displayEL[0][1] = 0.0;
1139 displayEL[1][1] = lin + dLine;
1140 if (displayEL[1][1] > previewYDim) displayEL[1][1] = previewYDim;
1141 } else if (plc.equals(PLACE_ULEFT)) {
1142 displayEL[0][0] = ele + dEle;
1143 if (displayEL[0][0] > previewXDim) displayEL[0][0] = previewXDim;
1144 displayEL[1][0] = lin - dLine;
1145 if (displayEL[1][0] < 0) displayEL[1][0] = 0.0;
1146 displayEL[0][1] = ele;
1147 displayEL[1][1] = lin;
1148 }
1149 int cEle = (int)Math.ceil(displayEL[0][0]);
1150 int cLin = (int)Math.ceil(displayEL[1][0]);
1151 displayEL[0][2] = cEle + dEle;
1152 if (displayEL[0][2] > previewXDim) displayEL[0][2] = previewXDim;
1153 displayEL[1][2] = cLin + dLine;
1154 if (displayEL[1][2] > previewYDim) displayEL[1][2] = previewYDim;
1155 displayEL[0][3] = cEle - dEle;
1156 if (displayEL[0][3] < 0) displayEL[0][3] = 0.0;
1157 displayEL[1][3] = cLin - dLine;
1158 if (displayEL[1][3] < 0) displayEL[1][3] = 0.0;
1159 displayEL[0][4] = cEle + dEle;
1160 if (displayEL[0][4] > previewXDim) displayEL[0][4] = previewXDim;
1161 displayEL[1][4] = cLin - dLine;
1162 if (displayEL[1][4] < 0) displayEL[1][4] = 0.0;
1163 /*
1164 System.out.println("\nDisplay:");
1165 System.out.println(" 0: " + displayEL[1][0] + " " + displayEL[0][0]);
1166 System.out.println(" 1: " + displayEL[1][1] + " " + displayEL[0][1]);
1167 System.out.println(" 2: " + displayEL[1][2] + " " + displayEL[0][2]);
1168 System.out.println(" 3: " + displayEL[1][3] + " " + displayEL[0][3]);
1169 System.out.println(" 4: " + displayEL[1][4] + " " + displayEL[0][4]);
1170 */
1171 areaEL = displayCoordToAreaCoord(displayEL);
1172 /*
1173 System.out.println("\nArea:");
1174 System.out.println(" 0: " + areaEL[1][0] + " " + areaEL[0][0]);
1175 System.out.println(" 1: " + areaEL[1][1] + " " + areaEL[0][1]);
1176 System.out.println(" 2: " + areaEL[1][2] + " " + areaEL[0][2]);
1177 System.out.println(" 3: " + areaEL[1][3] + " " + areaEL[0][3]);
1178 System.out.println(" 4: " + areaEL[1][4] + " " + areaEL[0][4]);
1179 */
1180 for (int i=0; i<5; i++) {
1181 if (areaEL[0][i] < 0.0) areaEL[0][i] = 0.0;
1182 if (areaEL[0][i] > this.maxEles) areaEL[0][i] = (double)this.maxEles;
1183 if (areaEL[1][i] < 0.0) areaEL[1][i] = 0.0;
1184 if (areaEL[1][i] > this.maxLines) areaEL[1][i] = (double)this.maxLines;
1185 }
1186
1187 try {
1188 latLon = macs.toReference(displayEL);
1189 } catch (Exception e) {
1190 System.out.println("Error converting input lat/lon e=" + e);
1191 }
1192 /*
1193 System.out.println("\nLat/Lon:");
1194 System.out.println(" 0: " + latLon[0][0] + " " + latLon[1][0]);
1195 System.out.println(" 1: " + latLon[0][1] + " " + latLon[1][1]);
1196 System.out.println(" 2: " + latLon[0][2] + " " + latLon[1][2]);
1197 System.out.println(" 3: " + latLon[0][3] + " " + latLon[1][3]);
1198 System.out.println(" 4: " + latLon[0][4] + " " + latLon[1][4]);
1199 */
1200 double maxLat = latLon[0][1];
1201 if (latLon[0][2] > maxLat) maxLat = latLon[0][2];
1202 double minLat = latLon[0][3];
1203 if (latLon[0][4] < minLat) minLat = latLon[0][4];
1204 double maxLon = latLon[1][4];
1205 if (latLon[1][2] > maxLon) maxLon = latLon[1][2];
1206 double minLon = latLon[1][1];
1207 if (latLon[1][3] < minLon) minLon = latLon[1][3];
1208
1209 imageEL = this.previewNav.areaCoordToImageCoord(areaEL);
1210 /*
1211 System.out.println("\nImage:");
1212 System.out.println(" 0: " + imageEL[1][0] + " " + imageEL[0][0]);
1213 System.out.println(" 1: " + imageEL[1][1] + " " + imageEL[0][1]);
1214 System.out.println(" 2: " + imageEL[1][2] + " " + imageEL[0][2]);
1215 System.out.println(" 3: " + imageEL[1][3] + " " + imageEL[0][3]);
1216 System.out.println(" 4: " + imageEL[1][4] + " " + imageEL[0][4]);
1217 */
1218 updateReadout();
1219
1220 geoLocInfo = new GeoLocationInfo(maxLat, minLon, minLat, maxLon);
1221
1222 return geoLocInfo;
1223 }
1224
1225 /**
1226 * Get the list of advanced property names
1227 *
1228 * @return array of advanced property names
1229 */
1230 protected String[] getAdvancedProps() {
1231 return ADVANCED_PROPS;
1232 }
1233
1234 /**
1235 * Get the list of advanced property labels
1236 *
1237 * @return list of advanced property labels
1238 */
1239 protected String[] getAdvancedLabels() {
1240 return ADVANCED_LABELS;
1241 }
1242
1243
1244 /**
1245 * Cycle the place
1246 */
1247 public void cyclePlace() {
1248
1249 String type = getCoordinateType();
1250 int dLine = getNumLines()/2 * Math.abs(getLineMag());
1251 int dEle = getNumEles()/2 * Math.abs(getElementMag());
1252 if (this.place.equals(PLACE_CENTER)) {
1253 int newVal = this.areaLine + dLine;
1254 if (newVal > this.maxLines/2) newVal = this.maxLines/2;
1255 this.areaLine = newVal;
1256 newVal = this.areaElement + dEle;
1257 if (newVal > this.maxEles/2) newVal = this.maxEles/2;
1258 this.areaElement = newVal;
1259 } else {
1260 int newVal = this.areaLine - dLine;
1261 if (newVal < 0) newVal = 0;
1262 this.areaLine = newVal;
1263 newVal = this.areaElement - dEle;
1264 if (newVal < 0) newVal = 0;
1265 this.areaElement = newVal;
1266 }
1267 double[][] el = new double[2][1];
1268 el[0][0] = this.areaElement;
1269 el[1][0] = this.areaLine;
1270 double[][] vals = this.areaNav.areaCoordToImageCoord(el);
1271 this.imageElement = (int)Math.floor(vals[0][0] + 0.5);
1272 this.imageLine = (int)Math.floor(vals[1][0] + 0.5);
1273
1274 if (type.equals(TYPE_AREA)) {
1275 setLine(this.areaLine);
1276 setElement(this.areaElement);
1277 } else if (type.equals(TYPE_IMAGE)) {
1278 setLine(this.imageLine);
1279 setElement(this.imageElement);
1280 }
1281 double[][] ll = this.areaNav.toLatLon(el);
1282 setLatitude(ll[0][0]);
1283 setLongitude(ll[1][0]);
1284 }
1285
1286
1287 /**
1288 * Associates the goven JComponent with the PROP_ property
1289 * identified by the given propId
1290 *
1291 * @param propId The property
1292 * @param comp The gui component that allows the user to set the property
1293 *
1294 * @return Just returns the given comp
1295 */
1296 protected JComponent addPropComp(String propId, JComponent comp) {
1297 Object oldComp = propToComps.get(propId);
1298 if (oldComp != null) {
1299 throw new IllegalStateException(
1300 "Already have a component defined:" + propId);
1301 }
1302 propToComps.put(propId, comp);
1303 return comp;
1304 }
1305
1306 /**
1307 * Translate a place name into a human readable form
1308 *
1309 * @param place raw name
1310 *
1311 * @return human readable name
1312 */
1313 protected String translatePlace(String thisPlace) {
1314 if (thisPlace.equals("Upper Left")) {
1315 return PLACE_ULEFT;
1316 }
1317 if (thisPlace.equals("Center")) {
1318 return PLACE_CENTER;
1319 }
1320 return thisPlace;
1321 }
1322
1323 private void setNumberOfLines(int val) {
1324 numLinesFld.setText(Integer.toString(val));
1325 }
1326
1327 private void setNumberOfElements(int val) {
1328 numElementsFld.setText(Integer.toString(val));
1329 }
1330
1331 public String getPlace() {
1332 try {
1333 this.place = translatePlace((String)locationComboBox.getSelectedItem());
1334 } catch (Exception e) {
1335 this.place = defaultPlace;
1336 }
1337 return this.place;
1338 }
1339
1340 public void setPlace(String str) {
1341 if (str.equals("")) str = defaultPlace;
1342 this.place = str;
1343 if (str.equals(PLACE_CENTER))
1344 locationComboBox.setSelectedItem("Center");
1345 else
1346 locationComboBox.setSelectedItem("Upper Left");
1347 }
1348
1349 public int getNumLines() {
1350 int val = -1;
1351 try {
1352 val = Integer.parseInt(numLinesFld.getText().trim());
1353 } catch (Exception e) {
1354 System.out.println("=====> exception in getNumLines: e=" + e);
1355 }
1356 setNumLines(val);
1357 return this.numLines;
1358 }
1359
1360 public void setNumLines(int val) {
1361 this.numLines = val;
1362 if (val >= 0) setNumberOfLines(val);
1363 }
1364
1365 public int getNumEles() {
1366 int val = -1;
1367 try {
1368 val = Integer.parseInt(numElementsFld.getText().trim());
1369 } catch (Exception e) {
1370 System.out.println("=====> exception in getNumEles: e=" + e);
1371 }
1372 setNumEles(val);
1373 return this.numEles;
1374 }
1375
1376 public void setNumEles(int val) {
1377 val = (int)((double)val/4.0 + 0.5)*4;
1378 this.numEles = val;
1379 if (val >= 0) setNumberOfElements(val);
1380 }
1381
1382 public int getLine() {
1383 int val = -1;
1384 try {
1385 if (!(centerLineFld.getText().equals(Misc.MISSING)))
1386 val = Integer.parseInt(centerLineFld.getText().trim());
1387 } catch (Exception e) {
1388 }
1389 return val;
1390 }
1391
1392 protected void setLineElement() {
1393 double[][] el = getLineElement();
1394 String type = getCoordinateType();
1395 if (type.equals(TYPE_IMAGE)) {
1396 this.imageElement = (int)Math.floor(el[0][0] + 0.5);
1397 this.imageLine = (int)Math.floor(el[1][0] + 0.5);
1398 double[][] vals = this.areaNav.imageCoordToAreaCoord(el);
1399 this.areaElement = (int)Math.floor(vals[0][0] + 0.5);
1400 this.areaLine = (int)Math.floor(vals[1][0] + 0.5);
1401 } else {
1402 this.areaElement = (int)Math.floor(el[0][0] + 0.5);
1403 this.areaLine = (int)Math.floor(el[1][0] + 0.5);
1404 double[][] vals = this.areaNav.areaCoordToImageCoord(el);
1405 this.imageElement = (int)Math.floor(vals[0][0] + 0.5);
1406 this.imageLine = (int)Math.floor(vals[1][0] + 0.5);
1407 }
1408 }
1409
1410 public void setLine(int val) {
1411 if (val < 0)
1412 centerLineFld.setText(Misc.MISSING);
1413 else
1414 centerLineFld.setText(Integer.toString(val));
1415 }
1416
1417 public int getElement() {
1418 int val =-1;
1419 try {
1420 val = Integer.parseInt(centerElementFld.getText().trim());
1421 } catch (Exception e) {
1422 }
1423 return val;
1424 }
1425
1426 private double[][] getLineElement() {
1427 double[][] el = new double[2][1];
1428 el[0][0] = (double)getElement();
1429 el[1][0] = (double)getLine();
1430 return el;
1431 }
1432
1433 public void setElement(int val) {
1434 if (val < 0)
1435 centerElementFld.setText(Misc.MISSING);
1436 else
1437 centerElementFld.setText(Integer.toString(val));
1438 }
1439
1440 public int getLineMag() {
1441 return this.lineMag;
1442 }
1443
1444 private void setElementMag() {
1445 int val = 1;
1446 try {
1447 val = Integer.parseInt(eleMagFld.getText().trim());
1448 } catch (Exception e) {
1449 System.out.println(" setElementMag e=" + e);
1450 return;
1451 }
1452 setElementMag(val);
1453 }
1454
1455 public void setLineMag(int val) {
1456 if (val > SLIDER_MAX) val = SLIDER_MAX;
1457 if (val < SLIDER_MIN-1) val = SLIDER_MIN-1;
1458 if (val == -1) val = 1;
1459 this.lineMag = val;
1460 setDLineMag((double)val);
1461 }
1462
1463 private void setLineMagSlider(int val) {
1464 if (val == 1) val = -1;
1465 if (val > SLIDER_MAX) val = -1;
1466 if (val < SLIDER_MIN) val = SLIDER_MIN-1;
1467 lineMagSlider.setValue(val + 1);
1468 }
1469
1470 public int getElementMag() {
1471 return this.elementMag;
1472 }
1473
1474 private void setLineMag() {
1475 int val = 1;
1476 try {
1477 val = Integer.parseInt(lineMagFld.getText().trim());
1478 } catch (Exception e) {
1479 }
1480 setLineMag(val);
1481 }
1482
1483 public void setDLineMag(double val) {
1484 this.dLineMag = val;
1485 }
1486
1487 public double getDLineMag() {
1488 return this.dLineMag;
1489 }
1490
1491 public void setDElementMag(double val) {
1492 this.dElementMag = val;
1493 }
1494
1495 private void setElementMagSlider(int val) {
1496 if (val == 1) val = -1;
1497 if (val > SLIDER_MAX) val = -1;
1498 if (val < SLIDER_MIN) val = SLIDER_MIN-1;
1499 elementMagSlider.setValue(val + 1);
1500 }
1501
1502 public double getDElementMag() {
1503 return this.dElementMag;
1504 }
1505
1506 public void setElementMag(int val) {
1507 if (val > SLIDER_MAX) val = SLIDER_MAX;
1508 if (val < SLIDER_MIN-1) val = SLIDER_MIN-1;
1509 if (val == -1) val = 1;
1510 this.elementMag = val;
1511 setDElementMag((double)val);
1512 }
1513
1514 public double getLatitude() {
1515 double val = latLonWidget.getLat();
1516 // Double dbl = new Double(val);
1517 if (Double.isNaN(val)) val = defaultLat;
1518 if (val < -90.0 || val > 90.0) val = defaultLat;
1519 setLatitude(val);
1520 return this.latitude;
1521 }
1522
1523 private void setLatitude() {
1524 this.latitude = latLonWidget.getLat();
1525 }
1526
1527 public void setLatitude(double val) {
1528 if (val < -90.0 || val > 90.0)
1529 val = defaultLat;
1530 latLonWidget.setLat(val);
1531 this.latitude = val;
1532 this.resetLatLon = false;
1533 }
1534
1535 private void setLongitude() {
1536 this.longitude = latLonWidget.getLon();
1537 }
1538
1539 public double getLongitude() {
1540 double val = latLonWidget.getLon();
1541 // Double dbl = new Double(val);
1542 if (Double.isNaN(val)) val = defaultLon;
1543 if (val < -180.0 || val > 180.0) val = defaultLon;
1544 setLongitude(val);
1545 return this.longitude;
1546 }
1547
1548 public void setLongitude(double val) {
1549 if (val < -180.0 || val > 180.0)
1550 val = defaultLon;
1551 latLonWidget.setLon(val);
1552 this.longitude = val;
1553 this.resetLatLon = false;
1554 }
1555
1556 protected void convertToLineEle() {
1557 double[][] ll = new double[2][1];
1558 ll[0][0] = getLatitude();
1559 ll[1][0] = getLongitude();
1560 double[][] el = this.areaNav.toLinEle(ll);
1561 this.areaElement = (int)Math.floor(el[0][0] + 0.5);
1562 this.areaLine = (int)Math.floor(el[1][0] + 0.5);
1563 el = this.areaNav.areaCoordToImageCoord(el);
1564 this.imageElement = (int)Math.floor(el[0][0] + 0.5);
1565 this.imageLine = (int)Math.floor(el[1][0] + 0.5);
1566 }
1567
1568 protected void convertToLatLon() {
1569 double[][] el = getLineElement();
1570 double[][] ll = new double[2][1];
1571 String coordType = getCoordinateType();
1572 if (coordType.equals(TYPE_IMAGE))
1573 el = this.previewNav.imageCoordToAreaCoord(el);
1574
1575 try {
1576 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1577 ll = macs.toReference(el);
1578 setLatitude(ll[0][0]);
1579 setLongitude(ll[1][0]);
1580 getGeoLocationInfo();
1581 } catch (Exception e) {
1582 System.out.println("convertToLatLon e=" + e);
1583 }
1584 }
1585
1586 protected void convertToLatLon(int ele, int lin) {
1587 try {
1588 double[][] el = new double[2][1];
1589 double[][] ll = new double[2][1];
1590 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1591 el[0][0] = (double)ele;
1592 el[1][0] = (double)lin;
1593 ll = macs.toReference(el);
1594 setLatitude(ll[0][0]);
1595 setLongitude(ll[1][0]);
1596 double[][] imageLE = new double[2][1];
1597 double[][] areaLE = new double[2][1];
1598 areaLE = this.previewNav.toLinEle(ll);
1599 imageLE = this.previewNav.areaCoordToImageCoord(areaLE);
1600 setCenterCoords((int)imageLE[0][0], (int)imageLE[1][0]);
1601 getGeoLocationInfo();
1602 } catch (Exception e) {
1603 System.out.println("convertToLatLon e=" + e);
1604 }
1605 }
1606
1607 protected double[][] convertToDisplayCoords() {
1608 double[][] el = getLineElement();
1609 try {
1610 double[][] ll = new double[2][1];
1611 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1612 String type = getCoordinateType();
1613 if (type.equals(TYPE_LATLON)) {
1614 ll[0][0] = getLatitude();
1615 ll[1][0] = getLongitude();
1616 el = macs.fromReference(ll);
1617 } else {
1618 int[] dirB = macs.getDirBlock();
1619 int previewLineMag = dirB[11];
1620 int previewEleMag = dirB[12];
1621 int dirLMag = this.previewDir.getValue(11);
1622 int dirEMag = this.previewDir.getValue(12);
1623 if (type.equals(TYPE_IMAGE))
1624 el = this.areaNav.imageCoordToAreaCoord(el);
1625 Rectangle2D mapArea = macs.getDefaultMapArea();
1626 int previewXDim = new Long(new Double(mapArea.getMaxX() - mapArea.getMinX()).longValue()).intValue();
1627 int previewYDim = new Long(new Double(mapArea.getMaxY() - mapArea.getMinY()).longValue()).intValue();
1628 el[0][0] = el[0][0] * dirEMag / previewEleMag;
1629 el[1][0] = previewYDim - 1 - el[1][0] * dirLMag / previewLineMag;;
1630 }
1631 } catch (Exception e) {
1632 System.out.println("convertToDisplayCoords e=" + e);
1633 }
1634 return el;
1635 }
1636
1637 private double[][] displayCoordToAreaCoord(double[][] disp) {
1638 double[][] area = new double[2][disp[0].length];
1639 try {
1640 if (sampleProjection != null) {
1641 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1642 double[][] ll = macs.toReference(disp);
1643 double[][] el = this.areaNav.toLinEle(ll);
1644 int midEle = (int)Math.floor(el[0][0] + 0.5);
1645 int midLin = (int)Math.floor(el[1][0] + 0.5);
1646
1647 int width = (int)Math.floor(Math.abs(disp[0][2] - disp[0][1])
1648 * getPreviewEleRes() + 0.5);
1649
1650 int height = (int)Math.floor(Math.abs(disp[1][3] - disp[1][1])
1651 * getPreviewLineRes() + 0.5);
1652 int deltaEle = width/2;
1653 int deltaLin = height/2;
1654
1655 area[0][0] = midEle;
1656 area[1][0] = midLin;
1657 area[0][1] = midEle - deltaEle;
1658 area[1][1] = midLin - deltaLin;
1659 area[0][2] = midEle + deltaEle;
1660 area[1][2] = midLin - deltaLin;
1661 area[0][3] = midEle - deltaEle;
1662 area[1][3] = midLin + deltaLin;
1663 area[0][4] = midEle + deltaEle;
1664 area[1][4] = midLin + deltaLin;
1665
1666 }
1667 } catch (Exception e) {
1668 System.out.println("displayCoordToAreaCoord e=" + e);
1669 }
1670 return area;
1671 }
1672
1673 private double[][] areaCoordToDisplayCoord(double[][] area) {
1674 double[][] disp = new double[2][area[0].length];
1675 try {
1676 if (sampleProjection != null) {
1677 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1678 int[] dirB = macs.getDirBlock();
1679 int previewLineMag = dirB[11];
1680 int previewEleMag = dirB[12];
1681 Rectangle2D mapArea = macs.getDefaultMapArea();
1682 int previewXDim = new Long(new Double(mapArea.getMaxX() - mapArea.getMinX()).longValue()).intValue();
1683 int previewYDim = new Long(new Double(mapArea.getMaxY() - mapArea.getMinY()).longValue()).intValue();
1684 for (int i=0; i<area[0].length; i++) {
1685 disp[0][i] = area[0][i] / previewEleMag;
1686 disp[1][i] = previewYDim - 1 - area[1][i] / previewLineMag;
1687 }
1688 }
1689 } catch (Exception e) {
1690 System.out.println("displayCoordToAreaCoord e=" + e);
1691 }
1692 return disp;
1693 }
1694
1695 protected void convertToLinEle() {
1696 try {
1697 double[][] el = new double[2][1];
1698 double[][] ll = new double[2][1];
1699 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
1700 ll[0][0] = getLatitude();
1701 ll[1][0] = getLongitude();
1702 String coordType = getCoordinateType();
1703 el = this.previewNav.toLinEle(ll);
1704 if (coordType.equals(TYPE_IMAGE))
1705 el = this.previewNav.areaCoordToImageCoord(el);
1706 setLine((int)el[1][0]);
1707 setElement((int)el[0][0]);
1708 getGeoLocationInfo();
1709 } catch (Exception e) {
1710 System.out.println("convertToLinEle e=" + e);
1711 }
1712 }
1713
1714 public String getCoordinateType() {
1715 String ret = defaultType;
1716 try {
1717 ret = (String)coordinateTypeComboBox.getSelectedItem();
1718 } catch (Exception e) {
1719 }
1720 return ret;
1721 }
1722
1723 protected void setCoordinateType(String type) {
1724 if (!type.equals(TYPE_IMAGE)) {
1725 if (!type.equals(TYPE_AREA)) {
1726 type = TYPE_LATLON;
1727 }
1728 }
1729 coordinateTypeComboBox.setSelectedItem(type);
1730 }
1731
1732 protected void setLockOn(boolean val) {
1733 lockBtn.setSelected(val);
1734 }
1735
1736 public boolean getLockOn() {
1737 return lockBtn.isSelected();
1738 }
1739
1740 protected void setULCoords(double x, double y) {
1741 uLLine = (int)y;
1742 uLEle = (int)x;
1743 }
1744
1745 protected void setCenterCoords(int x, int y) {
1746 centerLine = y;
1747 setLine(y);
1748 centerEle = x;
1749 setElement(x);
1750 }
1751
1752 protected void elementMagSliderChanged(boolean recomputeLineEleRatio) {
1753 int value = getElementMag();
1754 if (!amUpdating) {
1755 value = getElementMagValue();
1756 setElementMag(value);
1757 }
1758 if ((Math.abs(value) < SLIDER_MAX)) {
1759 int lineMag = getLineMagValue();
1760 if (lineMag > value) {
1761 linesToElements = Math.abs(lineMag
1762 / (double) value);
1763 } else {
1764 linesToElements = Math.abs((double) value
1765 / lineMag);
1766 }
1767 }
1768 elementMagLbl.setText("Ele Mag=");
1769 eleMagFld.setText(new Integer(value).toString());
1770 String str = " Res=" +
1771 truncateNumericString(Double.toString(this.baseERes*Math.abs(value)), 1);
1772 elementResLbl.setText(StringUtil.padLeft(str, 4) + kmLbl);
1773
1774 if (!lockBtn.isSelected()) {
1775 if (value > 0) {
1776 setNumberOfElements((int)(this.baseNumElements * value));
1777 } else {
1778 setNumberOfElements((int)(this.baseNumElements
1779 / (double) -value));
1780 }
1781 }
1782 }
1783
1784 private void changeLineMagSlider(boolean autoSetSize) {
1785 int value = getLineMag();
1786 setLineMagSlider(value);
1787 }
1788
1789 private void changeEleMagSlider(boolean autoSetSize) {
1790 int value = getElementMag();
1791 setElementMagSlider(value);
1792 }
1793
1794 /**
1795 * Handle the line mag slider changed event
1796 *
1797 * @param evt the event
1798 */
1799 protected void lineMagSliderChanged(boolean autoSetSize) {
1800 try {
1801 int value = getLineMag();
1802 if (!amUpdating) {
1803 value = getLineMagValue();
1804 setLineMag(value);
1805 }
1806 lineMagLbl.setText("Line Mag=");
1807 lineMagFld.setText(new Integer(value).toString());
1808 String str = " Res=" +
1809 truncateNumericString(Double.toString(this.baseLRes*Math.abs(value)), 1);
1810 lineResLbl.setText(StringUtil.padLeft(str, 4) + kmLbl);
1811
1812 if (autoSetSize) {
1813 if (value > 0) {
1814 setNumberOfLines((int)(this.baseNumLines * value));
1815 } else {
1816 setNumberOfLines((int)(this.baseNumLines
1817 / (double) -value));
1818 }
1819 }
1820
1821 if (value == 1) { // special case
1822 if (linesToElements < 1.0) {
1823 value = (int) (-value / linesToElements);
1824 } else {
1825 value = (int) (value * linesToElements);
1826 }
1827 } else if (value > 1) {
1828 value = (int) (value * linesToElements);
1829 } else {
1830 value = (int) (value / linesToElements);
1831 }
1832
1833 amSettingProperties = true;
1834 setElementMag(value);
1835 setElementMagSlider(value);
1836 amSettingProperties = false;
1837 elementMagSliderChanged(false);
1838 } catch (Exception exc) {
1839 System.out.println("Setting line magnification" + exc);
1840 }
1841 }
1842
1843 /**
1844 * Get the value of the line magnification slider.
1845 *
1846 * @return The magnification value for the line
1847 */
1848 protected int getLineMagValue() {
1849 int val = getMagValue(lineMagSlider);
1850 return val;
1851 }
1852
1853 /**
1854 * Get the value of the element magnification slider.
1855 *
1856 * @return The magnification value for the element
1857 */
1858 protected int getElementMagValue() {
1859 int val = getMagValue(elementMagSlider) - 1;
1860 setElementMag(val);
1861 return val;
1862 }
1863
1864 /**
1865 * Get the value of the given magnification slider.
1866 *
1867 * @param slider The slider to get the value from
1868 * @return The magnification value
1869 */
1870 private int getMagValue(JSlider slider) {
1871 //Value is [-SLIDER_MAX,SLIDER_MAX]. We change 0 and -1 to 1
1872 int value = slider.getValue();
1873 if (value == 0) {
1874 value = SLIDER_MAX;
1875 return value;
1876 } else if (value < SLIDER_MIN) {
1877 value = SLIDER_MIN;
1878 }
1879 return value - 1;
1880 }
1881
1882
1883 /**
1884 * _more_
1885 *
1886 * @param el _more_
1887 * @param name _more_
1888 * @param listener _more_
1889 *
1890 * @return _more_
1891 */
1892
1893 private JMenuItem makeLocationMenuItem(final LatLonPoint llp,
1894 final String name) {
1895 JMenuItem mi = null;
1896 try {
1897 double alt = 0.0;
1898 EarthLocationTuple elt =
1899 new EarthLocationTuple(llp.getLatitude(), llp.getLongitude(), alt);
1900 mi =
1901 new JMenuItem(
1902 StringUtil.padRight(name + ": ", 15, " ")
1903 + dataSource.getDataContext().getIdv().getDisplayConventions()
1904 .formatLatLonPoint(elt.getLatLonPoint()));
1905 GuiUtils.setFixedWidthFont(mi);
1906 } catch (Exception e) {
1907 System.out.println("makeLocationMenuItem e=" + e);
1908 }
1909 return mi;
1910 }
1911
1912
1913 public boolean getIsLineEle() {
1914 return this.isLineEle;
1915 }
1916
1917 public void setIsLineEle(boolean val) {
1918 this.isLineEle = val;
1919 }
1920
1921
1922 public double getLRes() {
1923 return this.lRes;
1924 }
1925
1926 public void setLRes(double val) {
1927 if (val < 1) val = this.baseLRes;
1928 this.lRes = val;
1929 }
1930
1931 public void setBLRes(double val) {
1932 this.bLRes = val;
1933 }
1934
1935 public void setBERes(double val) {
1936 this.bERes = val;
1937 }
1938
1939 public double getBLRes() {
1940 return this.bLRes;
1941 }
1942
1943 public double getBERes() {
1944 return this.bERes;
1945 }
1946
1947 public double getERes() {
1948 return this.eRes;
1949 }
1950
1951 public void setERes(double val) {
1952 if (val < 1) val = this.baseERes;
1953 this.eRes = val;
1954 }
1955
1956 public int getPreviewLineRes() {
1957 return this.previewLineRes;
1958 }
1959
1960 public void setPreviewLineRes(int val) {
1961 this.previewLineRes = val;
1962 }
1963
1964 public int getPreviewEleRes() {
1965 return this.previewEleRes;
1966 }
1967
1968 public void setPreviewEleRes(int val) {
1969 this.previewEleRes = val;
1970 }
1971
1972 private String truncateNumericString(String str, int numDec) {
1973 int indx = str.indexOf(".") + numDec + 1;
1974 if (indx >= str.length()) indx = str.length();
1975 return str.substring(0,indx);
1976 }
1977
1978 public String getLatLonType() {
1979 return TYPE_LATLON;
1980 }
1981
1982 protected double[][] getLatLonPoints() {
1983 return latLon;
1984 }
1985
1986 protected double[][] getImagePoints() {
1987 return imageEL;
1988 }
1989
1990 protected double[][] getAreaPoints() {
1991 return areaEL;
1992 }
1993
1994 protected double[][] getDisplayELPoints() {
1995 return displayEL;
1996 }
1997
1998 protected double getBaseLRes() {
1999 return this.baseLRes;
2000 }
2001
2002 protected double getBaseERes() {
2003 return this.baseERes;
2004 }
2005
2006 protected void setBaseNumLines(int val) {
2007 this.baseNumLines = (double)val;
2008 }
2009
2010 public void setDataChoice(DataChoice choice) {
2011 logger.trace("oldChoice={} newChoice={}", this.dataChoice, choice);
2012 this.dataChoice = choice;
2013 }
2014
2015 public DataChoice getDataChoice() {
2016 return this.dataChoice;
2017 }
2018
2019 protected void setBaseNumElements(int val) {
2020 this.baseNumElements = (double)val;
2021 }
2022
2023 public void update(AreaDirectory dir, MapProjection sample, AREAnav nav,
2024 String coordType, double[] coords) {
2025 boolean saveLock = getLockOn();
2026 setLockOn(true);
2027 this.maxLines = dir.getLines();
2028 this.maxEles = dir.getElements();
2029 sampleProjection = sample;
2030
2031 double baseLResOld = getBaseLRes();
2032 double baseEResOld = getBaseERes();
2033 double lDMagOld = getDLineMag();
2034 double eDMagOld = getDElementMag();
2035 int lMagOld = getLineMag();
2036 int eMagOld = getElementMag();
2037 int lSizeOld = getNumLines();
2038 int eSizeOld = getNumEles();
2039
2040 double baseLResNew = getBLRes();
2041 double baseEResNew = getBERes();
2042 try {
2043 baseLResNew *= (double)(dir.getValue(11));
2044 baseEResNew *= (double)(dir.getValue(12));
2045 } catch (Exception e) {
2046 }
2047
2048 double lDMagNew = lDMagOld * baseLResOld / baseLResNew;
2049 int lMagNew = (int)Math.ceil(lDMagNew - 0.5);
2050 if (lMagNew > -2) lMagNew = 1;
2051 double eDMagNew = eDMagOld * baseEResOld / baseEResNew;
2052 int eMagNew = (int)Math.ceil(eDMagNew - 0.5);
2053 if (eMagNew > -2) eMagNew = 1;
2054
2055 double lResOld = Math.abs(lMagOld) * baseLResOld;
2056 double eResOld = Math.abs(eMagOld) * baseEResOld;
2057 double lResNew = Math.abs(lMagNew) * baseLResNew;
2058 double eResNew = Math.abs(eMagNew) * baseEResNew;
2059
2060 int lSizeNew = (int)Math.floor(((double)lSizeOld * lResOld / lResNew) + 0.5);
2061 if (lSizeNew > this.maxLines) lSizeNew = this.maxLines;
2062 int eSizeNew = (int)Math.floor(((double)eSizeOld * eResOld / eResNew) + 0.5);
2063 if (eSizeNew > this.maxEles) eSizeNew = this.maxEles;
2064 setNumLines(lSizeNew);
2065 setNumEles(eSizeNew);
2066
2067 this.baseLRes = baseLResNew;
2068 this.baseERes = baseEResNew;
2069
2070 amUpdating = true;
2071 amSettingProperties = true;
2072 int newVal = 0;
2073 try {
2074 this.defaultLineMag = lMagNew;
2075 setLRes(lResNew);
2076 newVal = lMagNew;
2077 if (newVal > -2) newVal = 1;
2078 setLineMag(newVal);
2079 changeLineMagSlider(!lockBtn.isSelected());
2080 } catch (Exception e) {
2081 System.out.println("lineMagSlider: e=" + e);
2082 }
2083
2084 try {
2085 this.defaultElementMag = eMagNew;
2086 setERes(eResNew);
2087 newVal = eMagNew;
2088 if (newVal > -2) newVal = 1;
2089 } catch (Exception e) {
2090 System.out.println("elementMagSlider: e=" + e);
2091 }
2092 amUpdating = false;
2093 amSettingProperties = false;
2094
2095 int ele = 0;
2096 AREACoordinateSystem macs = (AREACoordinateSystem)sampleProjection;
2097 Rectangle2D mapArea = macs.getDefaultMapArea();
2098 double previewYDim = mapArea.getHeight();
2099 int line = (int)Math.floor(previewYDim);
2100 try {
2101 int lat = (int)Math.floor(getLatitude() + 0.5);
2102 if ((lat <= 90.0) && (lat >= -90.0)) {
2103 double[][] ll = new double[2][1];
2104 ll[0][0] = lat;
2105 ll[1][0] = getLongitude();
2106 double[][] el = sample.fromReference(ll);
2107 ele = (int)Math.floor(el[0][0] + 0.5);
2108 line = (int)Math.floor(el[1][0] + 0.5);
2109 }
2110 this.areaNav = nav;
2111 int areaLinRes = dir.getValue(11);
2112 int areaEleRes = dir.getValue(12);
2113 int startLine = dir.getValue(5);
2114 int startEle = dir.getValue(6);
2115 this.previewDir = dir;
2116 this.areaNav = this.previewNav;
2117 this.areaNav.setRes(areaLinRes, areaEleRes);
2118 this.areaNav.setImageStart(startLine, startEle);
2119
2120 setCoordinateType(coordType);
2121 if (coordType.equals(TYPE_LATLON)) {
2122 setLatitude(coords[0]);
2123 setLongitude(coords[1]);
2124 convertToLineEle();
2125 } else if (coordType.equals(TYPE_AREA)) {
2126 double dCoord = coords[0] * baseLResOld/baseLResNew;
2127 setLine((int)Math.floor(dCoord+0.5));
2128 dCoord = coords[1] * baseEResOld/baseEResNew;
2129 setElement((int)Math.floor(dCoord+0.5));
2130 setLineElement();
2131 convertToLatLon();
2132 }
2133
2134 } catch (Exception e) {
2135 System.out.println("e=" + e);
2136 }
2137
2138 try {
2139 rawSizeLbl.setText(" Raw size: " + this.maxLines + " X " + this.maxEles);
2140 } catch (Exception e) {
2141 System.out.println("updating raw size: e=" + e);
2142 }
2143
2144 amUpdating = true;
2145 lineMagSliderChanged(false);
2146 setElementMag(newVal);
2147 elementMagSliderChanged(false);
2148 amUpdating = false;
2149 changeEleMagSlider(!lockBtn.isSelected());
2150 setLockOn(saveLock);
2151 getGeoLocationInfo(line, ele);
2152 }
2153 }