/* Copyright (c) 1995-2012 held by the author(s). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the Naval Postgraduate School (NPS) Modeling Virtual Environments and Simulation (MOVES) Institute (http://www.nps.edu and http://www.movesinstitute.org) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * Autonomous Unmanned Vehicle Workbench * Naval Postgraduate School, Monterey, CA * www.nps.edu * By: Mike Bailey * Date: May 25, 2005 * Time: 9:17:43 AM * * @version $Id: GeoUtils.java 8201 2012-07-31 21:36:44Z tnorbraten $ */ package workbench.util; import static edu.nps.util.LogUtils.getLogger; import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import workbench.main.AUVWorkbenchConfig2; import workbench.main.MultiMissionController; public class GeoUtils { public static final int LAT_INDEX = 0; public static final int LON_INDEX = 1; static final String BASE_KEY = "geo.defaultorigin.geolocation"; static final String PROJECT_BASE_KEY = "x3d.geolocation"; final static String BEGIN_DOWNLOADING = "Begin downloading"; final static String CANCEL = "Cancel"; final static String COPY = "Copy"; final static String CLEAR = "Clear"; final static String CLOSE = "Close"; final static String SELECT = "Select"; /** * This method gets the GeoOrigin from the current project's auvwProject.xml file. * @return the project's GeoOrigin latitude/longitude as a pair of floats. */ public static float[] getGeoOrigin() { float[] retf = new float[2]; AUVWorkbenchConfig2 cfg2 = AUVWorkbenchConfig2.instance(); String units = cfg2.val(PROJECT_BASE_KEY + "[@units]"); //String handle = cfg2.val(PROJECT_BASE_KEY + ".handle"); String latitude = cfg2.val(PROJECT_BASE_KEY + ".latitude"); String longitude = cfg2.val(PROJECT_BASE_KEY + ".longitude"); //String x3dScene = cfg2.val(PROJECT_BASE_KEY + ".X3Dscene"); retf[LAT_INDEX] = toFloat(latitude, units); retf[LON_INDEX] = toFloat(longitude, units); return retf; } /** Obtains the full geo spatial information set from c_geo.xml config file * * @return the full geo spatial information set from c_geo.xml config file */ public static GeoLocation getGeoOriginFull() { AUVWorkbenchConfig2 cfg2 = AUVWorkbenchConfig2.instance(); //String units = cfg2.val(BASE_KEY+"[@units]"); String handle = cfg2.val(BASE_KEY + ".handle"); String latitude = cfg2.val(BASE_KEY + ".latitude"); String longitude = cfg2.val(BASE_KEY + ".longitude"); String scale = cfg2.val("geo.scale"); String _projScale = cfg2.val(BASE_KEY + ".scale"); scale = _projScale.length() <= 0 ? scale : _projScale; // todo remove when all project config files have scale String x3d = cfg2.valExpanded(BASE_KEY + ".X3Dscene"); return new GeoUtils.GeoLocation(handle, latitude, longitude, scale, x3d); } /** Obtains and sets a project's specific geo origin information set to c_geo.xml config file * * @param handle name of the geo location * @param latitude geo coordinate * @param longitude geo coordinate * @param scale open map scale to initially set * @param x3d a scene graph URL of the geo location */ public static void setGeoOrigin(String handle, String latitude, String longitude, String scale, String x3d) { AUVWorkbenchConfig2 cfg2 = AUVWorkbenchConfig2.instance(); //cfg2.setVal(BASE_KEY+"[@units]",...); cfg2.setVal(BASE_KEY + ".handle", handle); cfg2.setVal(BASE_KEY + ".latitude", latitude); cfg2.setVal(BASE_KEY + ".longitude", longitude); cfg2.setVal(BASE_KEY + ".scale", scale); cfg2.setVal(BASE_KEY + ".X3Dscene", x3d); } private static float toFloat(String coord, String units) { // support //if(units.equalsIgnoreCase("decimalDegrees")) float coordinate = 0.0f; try { coordinate = Float.parseFloat(coord); } catch (Exception e) { System.err.println("Error parsing coord (" + coord + ") value"); } return coordinate; } private static double toDouble(String coord, String units) { // support //if(units.equalsIgnoreCase("decimalDegrees")) double coordinate = 0.0d; try { coordinate = Double.parseDouble(coord); } catch (Exception e) { System.err.println("Error parsing coord (" + coord + ") value"); } return coordinate; } /*---- uploads/downloads of GIS data ------*/ /** Spawns a separate thread for downloading GIS datasets */ public static void downloadGIS() { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GeoDownload.showDialog(); } }); } /*----- geo loc adjustment -----*/ public static void chooseOrigin(Frame owner, MultiMissionController controller) { GeoOriginSelectionDialog.showDialog(owner); if (GeoOriginSelectionDialog.getChoice() != null) // might have been cancelled { SwingUtilities.invokeLater(new informer(controller)); } } public static class informer implements Runnable { MultiMissionController controller; informer(MultiMissionController controller) { this.controller = controller; } @Override public void run() { controller.actionPerformed(MultiMissionController.GEOSPATIAL_ORIGIN_NEW); } } public static class GeoLocation { public String handle, x3dScene; public double lat, lon; public float scale; public GeoLocation(String handle, String lat, String lon, String scale, String x3dScene) { this.handle = handle; this.lat = toDouble(lat, "decimalDegrees"); this.lon = toDouble(lon, "decimalDegrees"); this.scale = Float.parseFloat(scale); this.x3dScene = x3dScene; } } /** Command line invocation for the application * @param args command line arguments (if any) */ public static void main(String[] args) { // GeoOriginSelectionDialog.showDialog(null); // GeoLocation g = GeoOriginSelectionDialog.getChoice(); // System.out.println(g.handle); // System.exit(0); GeoUtils.downloadGIS(); } } /** * GUI class for "Select Geographic Origin" table */ class GeoOriginSelectionDialog extends JDialog { private static GeoOriginSelectionDialog dialog; private JTable table; private AUVWorkbenchConfig2 cfg2; private GeoUtils.GeoLocation currentGeoLocation; private boolean cancelled = false; private String[][] favorites; private List favoritesArrayList; private static final int HANDL = 0; private static final int LATI = 1; private static final int LONG = 2; private static final int SCALE = 3; private static final int X3D = 4; private ActionListener selectHandler; static final String BASE_KEY = "geo.defaultorigin.geolocation"; /** * reset dialog buttons, make it visible * @param owner is parent frame */ public static void showDialog(Frame owner) { buildIt(owner); dialog.cancelled = false; dialog.setVisible(true); // above call blocks } /** * only build Select Geographic Origin table if needed * @param owner is parent frame */ private static void buildIt(Frame owner) { if (dialog == null) { dialog = new GeoOriginSelectionDialog(owner); } dialog.setCombo(); } public static GeoUtils.GeoLocation getChoice() { return dialog.cancelled ? null : dialog.currentGeoLocation; } class myROJTable extends JTable { public myROJTable(Object[][] d, Object[] h) { super(d, h); } @Override public boolean isCellEditable(int row, int column) { return false; } } private void setCombo() { String[] current = getCurrent(); int i; for (i = 0; i < favorites.length; i++) { if (current[HANDL].equals(favorites[i][HANDL]) && current[LATI].equals(favorites[i][LATI]) && current[LONG].equals(favorites[i][LONG])) { break; } } int choice = (i >= favorites.length ? 0 : i); table.setRowSelectionInterval(choice, choice); table.scrollRectToVisible(table.getCellRect(choice, 0, true)); } /** * GUI constructor for "Select Geographic Origin" table * @param owner is parent frame */ private GeoOriginSelectionDialog(Frame owner) { super(owner, "Select Geographic Origin", true); cfg2 = AUVWorkbenchConfig2.instance(); favorites = getFavorites(); Dimension dialogDimension = new Dimension(900, 200); JPanel c = new JPanel(); setContentPane(c); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); c.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); c.setSize(dialogDimension); table = new myROJTable(favorites, new String[]{"name", "latitude", "longitude"}); table.setPreferredScrollableViewportSize(dialogDimension); table.setCellEditor(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionAllowed(true); // TODO: make first column wider than second and third // table.setColumnModel(); JScrollPane jsp = new JScrollPane(table); jsp.setPreferredSize(dialogDimension); c.add(jsp); JPanel bigButtonPanel = new JPanel(); bigButtonPanel.setLayout(new BoxLayout(bigButtonPanel, BoxLayout.X_AXIS)); JButton helpButton = new JButton("?"); JButton selectButton = new JButton(GeoUtils.SELECT); JButton cancelButton = new JButton(GeoUtils.CANCEL); bigButtonPanel.add(helpButton); bigButtonPanel.add(Box.createHorizontalGlue()); bigButtonPanel.add(selectButton); bigButtonPanel.add(cancelButton); c.add(bigButtonPanel); pack(); setResizable(true);//false); cancelButton.requestFocusInWindow(); setLocationRelativeTo(owner); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancelled = true; dialog.setVisible(false); } }); selectButton.addActionListener(selectHandler = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); String[] current = favorites[row]; currentGeoLocation = favoritesArrayList.get(row); //cfg2.setVal(BASE_KEY+"[@units]",...); cfg2.setVal(BASE_KEY + ".handle", current[HANDL]); cfg2.setVal(BASE_KEY + ".latitude", current[LATI]); cfg2.setVal(BASE_KEY + ".longitude", current[LONG]); cfg2.setVal(BASE_KEY + ".scale", current[SCALE]); cfg2.setVal(BASE_KEY + ".X3Dscene", current[X3D]); dialog.setVisible(false); } }); helpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO less verbose JOptionPane.showMessageDialog(GeoOriginSelectionDialog.this, "
The Geographic Origin set in the mission project from this dialog
" + "is used 1) as a new mission location if a Mission Offset is not explicitly set in
" + "the mission edit panel, and 2) the center of the OpenMap mission view. The chosen
" + "location for this project is persistent over workbench launches.", "Geographic Origin Help", JOptionPane.INFORMATION_MESSAGE); } }); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { selectHandler.actionPerformed(null); } } }); } String[] getCurrent() { //String units = cfg2.val(BASE_KEY+"[@units]"); String handle = cfg2.val(BASE_KEY + ".handle"); String latitude = cfg2.val(BASE_KEY + ".latitude"); String longitude = cfg2.val(BASE_KEY + ".longitude"); String x3d = cfg2.valExpanded(BASE_KEY + ".X3Dscene"); String scale = cfg2.val("geo.scale"); String _projScale = cfg2.val(BASE_KEY + ".scale"); scale = _projScale.length() <= 0 ? scale : _projScale; // todo remove when all project config files have scale currentGeoLocation = new GeoUtils.GeoLocation(handle, latitude, longitude, scale, x3d); return new String[]{handle, latitude, longitude, scale, x3d}; } /** * Get string array of geospatial locations * @return double array */ private String[][] getFavorites() { String favsKey = "geo.favoriteorigins.geolocation"; favoritesArrayList = new ArrayList(); int num = cfg2.num(favsKey + ".latitude"); String[][] reta = new String[num][5]; for (int i = 0; i < num; i++) { String key = favsKey + "(" + i + ")"; String handle = cfg2.val(key + ".handle"); String lat = cfg2.val(key + ".latitude"); String lon = cfg2.val(key + ".longitude"); String x3d = cfg2.valExpanded(key + ".X3Dscene"); String scale = cfg2.val("geo.scale"); String _projScale = cfg2.val(key + ".scale"); scale = _projScale.length() <= 0 ? scale : _projScale; // todo remove when all project config files have scale favoritesArrayList.add(new GeoUtils.GeoLocation(handle, lat, lon, scale, x3d)); reta[i][0] = handle; reta[i][1] = lat; reta[i][2] = lon; reta[i][3] = scale; reta[i][4] = x3d; } return reta; } } /** * The GeoDownload GUI interface is used to select and download GIS data assets. * This is an iconizable, nonmodal panel that does not block any other functions. */ class GeoDownload extends JPanel implements ActionListener, Runnable { private static JFrame frame = new JFrame("Geospatial Datasets Download"); private static GeoDownload dialog; private JButton doitButton, cancelButton, copyButton, clearButton, closeButton; private JCheckBox appsCb, allCb, dncsCb, dnc13Cb, dnc15Cb, dnc17Cb, dnc26Cb, hamptonRoadsCb, montereyBayCb, narragansettBayCb, panamaCityCb, sanDiegoCb; private JCheckBox esriCb, esriFloridaCb, esriMontereyCb, esriNarragansettBayCb, esriPugetSoundCb; private JTextArea statusTextArea; private AntTaskRunner antTaskRunner; private static final String labelTxt = "" + "These tasks download geospatial datasets from servers at the Naval Postgraduate School.
" + "Datasets are extensive and large. Each download may take several minutes, or even hours
" + "across slow links." + ""; /** * Build the GeoDownload interface */ public static void showDialog() { buildIt(); } /** * Build the GeoDownload interface */ private static void buildIt() { frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog = new GeoDownload(frame); dialog.setOpaque(true); frame.setResizable(false); frame.setLocation(315, 185); getLogger(GeoUtils.class).debug("frame x: " + frame.getX()); getLogger(GeoUtils.class).debug("frame y: " + frame.getY()); frame.pack(); frame.setVisible(true); } /** * Constructor that creates GUI panel for downloading and extracting GIS archives * @param owner JFrame of parent */ private GeoDownload(JFrame owner) { super(true); JPanel downloadPanel = new JPanel(); JPanel downloadPanelLeft = new JPanel(); JPanel downloadPanelRight = new JPanel(); downloadPanel.setLayout(new BoxLayout(downloadPanel, BoxLayout.X_AXIS)); downloadPanelLeft.setLayout(new BoxLayout(downloadPanelLeft, BoxLayout.Y_AXIS)); downloadPanelRight.setLayout(new BoxLayout(downloadPanelRight, BoxLayout.Y_AXIS)); downloadPanel.add(downloadPanelLeft); downloadPanel.add(downloadPanelRight); JLabel headerLabel = new JLabel(labelTxt); headerLabel.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "Notice")); headerLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT); downloadPanelLeft.add(headerLabel); downloadPanelLeft.add(Box.createVerticalStrut(10)); JPanel esriButtonPanel = new JPanel(); esriButtonPanel.setLayout(new BoxLayout(esriButtonPanel, BoxLayout.Y_AXIS)); esriButtonPanel.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "ESRI Tiger")); esriButtonPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT); JPanel DncButtonPanel = new JPanel(); DncButtonPanel.setLayout(new BoxLayout(DncButtonPanel, BoxLayout.Y_AXIS)); DncButtonPanel.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "DNC - For Official Use Only (FOUO)")); DncButtonPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT); JPanel oceanographyButtonPanel = new JPanel(); oceanographyButtonPanel.setLayout(new BoxLayout(oceanographyButtonPanel, BoxLayout.Y_AXIS)); oceanographyButtonPanel.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "Oceanography Data")); oceanographyButtonPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT); JPanel allButtonPanel = new JPanel(); allButtonPanel.setLayout(new BoxLayout(allButtonPanel, BoxLayout.Y_AXIS)); allButtonPanel.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "Helper applications, all datasets")); allButtonPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT); esriFloridaCb = new JCheckBox("Download ESRI Tiger data: Florida"); esriMontereyCb = new JCheckBox("Download ESRI Tiger data: Monterey California"); esriNarragansettBayCb = new JCheckBox("Download ESRI Tiger data: Narragansett Bay Rhode Island (AUV Fest 2008)", true); esriPugetSoundCb = new JCheckBox("Download ESRI Tiger data: Puget Sound Washington", true); esriCb = new JCheckBox("Download all available ESRI Tiger Census data"); dnc13Cb = new JCheckBox("Download DNC 13: North America West (includes Monterey)"); dnc15Cb = new JCheckBox("Download DNC 15: Gulf of Mexico / Straits of Florida (includes Panama City)"); dnc17Cb = new JCheckBox("Download DNC 17: Eastern United States / Providence and Narragansett Bay"); dnc26Cb = new JCheckBox("Download DNC 26: British Columbia (includes Puget Sound)"); dncsCb = new JCheckBox("Download all available Digital Nautical Chart (DNC) data"); hamptonRoadsCb = new JCheckBox("Download oceanography data: Hampton Roads VA"); montereyBayCb = new JCheckBox("Download oceanography data: Monterey Bay CA"); narragansettBayCb = new JCheckBox("Download oceanography data: Narragansett Bay Rhode Island (AUV Fest 2008)"); panamaCityCb = new JCheckBox("Download oceanography data: Panama City FL"); sanDiegoCb = new JCheckBox("Download oceanography data: San Diego CA"); appsCb = new JCheckBox("Download available helper applications for this operating system"); allCb = new JCheckBox("Download all available geospatial datasets and helper applications"); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(esriFloridaCb); buttonGroup.add(esriMontereyCb); buttonGroup.add(esriNarragansettBayCb); buttonGroup.add(esriPugetSoundCb); buttonGroup.add(esriCb); buttonGroup.add(dnc13Cb); buttonGroup.add(dnc15Cb); buttonGroup.add(dnc26Cb); buttonGroup.add(dnc17Cb); buttonGroup.add(dncsCb); buttonGroup.add(hamptonRoadsCb); buttonGroup.add(montereyBayCb); buttonGroup.add(narragansettBayCb); buttonGroup.add(panamaCityCb); buttonGroup.add(sanDiegoCb); buttonGroup.add(appsCb); buttonGroup.add(allCb); esriButtonPanel.add(esriFloridaCb); esriButtonPanel.add(Box.createVerticalStrut(5)); esriButtonPanel.add(esriMontereyCb); esriButtonPanel.add(Box.createVerticalStrut(5)); esriButtonPanel.add(esriNarragansettBayCb); esriButtonPanel.add(Box.createVerticalStrut(5)); esriButtonPanel.add(esriPugetSoundCb); esriButtonPanel.add(Box.createVerticalStrut(5)); esriButtonPanel.add(esriCb); downloadPanelLeft.add(esriButtonPanel); downloadPanelLeft.add(Box.createVerticalStrut(10)); DncButtonPanel.add(dnc13Cb); DncButtonPanel.add(Box.createVerticalStrut(5)); DncButtonPanel.add(dnc15Cb); DncButtonPanel.add(Box.createVerticalStrut(5)); DncButtonPanel.add(dnc17Cb); DncButtonPanel.add(Box.createVerticalStrut(5)); DncButtonPanel.add(dnc26Cb); DncButtonPanel.add(Box.createVerticalStrut(5)); DncButtonPanel.add(dncsCb); downloadPanelLeft.add(DncButtonPanel); downloadPanelLeft.add(Box.createVerticalStrut(10)); oceanographyButtonPanel.add(hamptonRoadsCb); oceanographyButtonPanel.add(Box.createVerticalStrut(5)); oceanographyButtonPanel.add(montereyBayCb); oceanographyButtonPanel.add(Box.createVerticalStrut(5)); oceanographyButtonPanel.add(narragansettBayCb); oceanographyButtonPanel.add(Box.createVerticalStrut(5)); oceanographyButtonPanel.add(panamaCityCb); oceanographyButtonPanel.add(Box.createVerticalStrut(5)); oceanographyButtonPanel.add(sanDiegoCb); oceanographyButtonPanel.add(Box.createVerticalStrut(5)); downloadPanelLeft.add(oceanographyButtonPanel); downloadPanelLeft.add(Box.createVerticalStrut(10)); allButtonPanel.add(appsCb); allButtonPanel.add(Box.createVerticalStrut(5)); allButtonPanel.add(allCb); downloadPanelLeft.add(allButtonPanel); statusTextArea = new JTextArea(16, 40); statusTextArea.setLineWrap(true); statusTextArea.setWrapStyleWord(true); JScrollPane statusScrollPane = new JScrollPane(statusTextArea); statusScrollPane.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.black, 1), "Download console")); statusScrollPane.setToolTipText("Display status messages from Ant build.xml task"); downloadPanelRight.add(statusScrollPane); downloadPanelRight.add(Box.createVerticalStrut(10)); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); doitButton = new JButton(GeoUtils.BEGIN_DOWNLOADING); doitButton.setToolTipText("Begin downloading helper applications, geospatial datasets"); cancelButton = new JButton(GeoUtils.CANCEL); cancelButton.setToolTipText("Cancel download in progress"); cancelButton.setEnabled(false); copyButton = new JButton(GeoUtils.COPY); copyButton.setToolTipText("
Copy output console to system clipboard"); clearButton = new JButton(GeoUtils.CLEAR); clearButton.setToolTipText("Clear console text log"); closeButton = new JButton(GeoUtils.CLOSE); closeButton.setToolTipText("Close this panel"); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(doitButton); buttonPanel.add(cancelButton); buttonPanel.add(copyButton); buttonPanel.add(clearButton); buttonPanel.add(closeButton); downloadPanelRight.add(buttonPanel); GeoDownload instance = this; doitButton.addActionListener(instance); cancelButton.addActionListener(instance); copyButton.addActionListener(instance); clearButton.addActionListener(instance); closeButton.addActionListener(instance); downloadPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); owner.setContentPane(downloadPanel); cancelButton.requestFocusInWindow(); antTaskRunner = new AntTaskRunner(this, statusTextArea); } /** * Perform user interface action * @param e passed ActionEvent */ @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(GeoUtils.CANCEL)) { antTaskRunner.setIsCancelled(true); jobDone(); } else if (e.getActionCommand().equals(GeoUtils.CLOSE)) { frame.setVisible(false); frame.dispose(); } else if (e.getActionCommand().equals(GeoUtils.CLEAR)) { statusTextArea.setText(""); } else if (e.getActionCommand().equals(GeoUtils.COPY)) { ClipboardUtil.invokeClipboard(statusTextArea); } else if (e.getActionCommand().equals(GeoUtils.BEGIN_DOWNLOADING)) { doitButton.setEnabled(false); cancelButton.setEnabled(true); clearButton.setEnabled(false); closeButton.setEnabled(false); antTaskRunner.buildMainArguments(); String[] userPassword = new String[]{"",""}; if(needPassword()) { userPassword = antTaskRunner.getUserPassword(); } // cancelled if (userPassword[0] == null || userPassword[1] == null) { antTaskRunner.setIsCancelled(true); jobDone(); return; } // Security userPassword = null; Thread myThread = new Thread(this, "GeoDownload"); myThread.setPriority(Thread.NORM_PRIORITY); myThread.start(); } } /** * Reset buttons when current download job is done */ private void jobDone() { doitButton.setEnabled(true); cancelButton.setEnabled(false); clearButton.setEnabled(true); closeButton.setEnabled(true); } /** * For Official Use Only (FOUO) datasets require a password to continue * @return whether password is needed */ private boolean needPassword() { return dncsCb.isSelected() || dnc13Cb.isSelected()|| dnc15Cb.isSelected()|| dnc17Cb.isSelected()|| dnc26Cb.isSelected(); } /** * Determine user choice and launch corresponding Ant task */ @Override public void run() { // Set the actual task here if (dncsCb.isSelected()) { antTaskRunner.setTaskname("online.getDNCs"); } else if (dnc13Cb.isSelected()) { antTaskRunner.setTaskname("online.getDNC13"); } else if (dnc15Cb.isSelected()) { antTaskRunner.setTaskname("online.getDNC15"); } else if (dnc17Cb.isSelected()) { antTaskRunner.setTaskname("online.getDNC17"); } else if (dnc26Cb.isSelected()) { antTaskRunner.setTaskname("online.getDNC26"); } else if (narragansettBayCb.isSelected()) { antTaskRunner.setTaskname("online.getAUVFest2008GIS"); } else if (hamptonRoadsCb.isSelected()) { antTaskRunner.setTaskname("online.getHamptonRoadsVirginiaGIS"); } else if (montereyBayCb.isSelected()) { antTaskRunner.setTaskname("online.getMontereyBayCaliforniaGIS"); } else if (panamaCityCb.isSelected()) { antTaskRunner.setTaskname("online.getPanamaCityFloridaGIS"); } else if (sanDiegoCb.isSelected()) { antTaskRunner.setTaskname("online.getSanDiegoCaliforniaGIS"); } else if (esriCb.isSelected()) { antTaskRunner.setTaskname("online.getEsriTigerZips"); } else if (esriFloridaCb.isSelected()) { antTaskRunner.setTaskname("online.getEsriTigerFlorida"); } else if (esriMontereyCb.isSelected()) { antTaskRunner.setTaskname("online.getEsriTigerMontereyCalifornia"); } else if (esriNarragansettBayCb.isSelected()) { antTaskRunner.setTaskname("online.getEsriTigerNarragansettBay"); } else if (esriPugetSoundCb.isSelected()) { antTaskRunner.setTaskname("online.getEsriTigerPugetSoundWashington"); } else if (appsCb.isSelected()) { antTaskRunner.setTaskname("online.getApps"); } else if (allCb.isSelected()) { antTaskRunner.setTaskname("online.getAll"); } else { getLogger(GeoUtils.class).error("GeoDownload error: unrecognized button selection"); return; } Thread myThread = new Thread(antTaskRunner, "AntTaskRunner"); myThread.setPriority(Thread.NORM_PRIORITY); myThread.start(); try { myThread.join(); } catch (InterruptedException ex) { antTaskRunner.appendStatus("\nError: " + ex.getMessage(), true); } jobDone(); } } // end class file GeoUtils.java