Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlDownloaderMap

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* JPanelAll.java
*
* Created on 27.04.2009, 22:13:10
*/
package xplanetconfigurator.gui;

import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.swing.text.JTextComponent;
import xplanetconfigurator.util.XPlanetRessourceFinder;

/**
*
* @author tom
*/
public class JPanelControlDownloaderMap extends ControlPanel implements IAskForUserTextLine {

    private Logger logger;
    private Map defaultURLs;

    /** Creates new form JPanelAll */
    public JPanelControlDownloaderMap(MainFrame mainFrame, String markerName) {
        super(mainFrame);
        initComponents();
        this.logger = Logger.getLogger(this.getClass().getName());
        this.setMarkerName(markerName);
        this.jLabelMapName.setText(markerName);
        this.fillDefaultURLs();
        this.fillUrlList();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanelMap = new javax.swing.JPanel();
        jLabelMapName = new javax.swing.JLabel();
        jLabelUrl = new javax.swing.JLabel();
        jComboBoxMap = new javax.swing.JComboBox();
        jButtonAdd = new javax.swing.JButton();
        jButtonDelete = new javax.swing.JButton();
        jButtonDownload = new javax.swing.JButton();
        jPanelStatus = new javax.swing.JPanel();
        jLabelHeaderStatus = new javax.swing.JLabel();
        jLabelStatus = new javax.swing.JLabel();
        jLabelHeaderStatusLastDowload = new javax.swing.JLabel();
        jLabelStatusLastDownload = new javax.swing.JLabel();
        jLabelStatusLastDownloadUpToDate = new javax.swing.JLabel();

        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        setLayout(new java.awt.GridBagLayout());

        jPanelMap.setName("jPanelMap"); // NOI18N
        jPanelMap.setLayout(new java.awt.GridBagLayout());

        jLabelMapName.setText("name"); // NOI18N
        jLabelMapName.setName("jLabelMapName"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 7);
        jPanelMap.add(jLabelMapName, gridBagConstraints);

        jLabelUrl.setText("<html><b>URL"); // NOI18N
        jLabelUrl.setName("jLabelUrl"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelMap.add(jLabelUrl, gridBagConstraints);

        jComboBoxMap.setName("jComboBoxMap"); // NOI18N
        jComboBoxMap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMapActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        jPanelMap.add(jComboBoxMap, gridBagConstraints);

        jButtonAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Button-Add-16x16.gif"))); // NOI18N
        jButtonAdd.setName("jButtonAdd"); // NOI18N
        jButtonAdd.setPreferredSize(new java.awt.Dimension(25, 25));
        jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        jPanelMap.add(jButtonAdd, gridBagConstraints);

        jButtonDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Button-Delete-16x16.gif"))); // NOI18N
        jButtonDelete.setName("jButtonDelete"); // NOI18N
        jButtonDelete.setPreferredSize(new java.awt.Dimension(25, 25));
        jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDeleteActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        jPanelMap.add(jButtonDelete, gridBagConstraints);

        jButtonDownload.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Refresh16.gif"))); // NOI18N
        jButtonDownload.setToolTipText("Download now");
        jButtonDownload.setName("jButtonDownload"); // NOI18N
        jButtonDownload.setPreferredSize(new java.awt.Dimension(25, 25));
        jButtonDownload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDownloadActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        jPanelMap.add(jButtonDownload, gridBagConstraints);

        jPanelStatus.setName("jPanelStatus"); // NOI18N
        jPanelStatus.setLayout(new java.awt.GridBagLayout());

        jLabelHeaderStatus.setText("Local:");
        jLabelHeaderStatus.setName("jLabelHeaderStatus"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelStatus.add(jLabelHeaderStatus, gridBagConstraints);

        jLabelStatus.setName("jLabelStatus"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 7);
        jPanelStatus.add(jLabelStatus, gridBagConstraints);

        jLabelHeaderStatusLastDowload.setText("Internet:");
        jLabelHeaderStatusLastDowload.setName("jLabelHeaderStatusLastDowload"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelStatus.add(jLabelHeaderStatusLastDowload, gridBagConstraints);

        jLabelStatusLastDownload.setName("jLabelStatusLastDownload"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 7);
        jPanelStatus.add(jLabelStatusLastDownload, gridBagConstraints);

        jLabelStatusLastDownloadUpToDate.setName("jLabelStatusLastDownloadUpToDate"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        jPanelStatus.add(jLabelStatusLastDownloadUpToDate, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelMap.add(jPanelStatus, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 7, 0);
        add(jPanelMap, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        this.receiveCommandLineParameters();
    }//GEN-LAST:event_formComponentShown

    private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
        JDialogTextLineInput dialog = new JDialogTextLineInput("Please give a URL", this);
        dialog.setVisible(true);
    }//GEN-LAST:event_jButtonAddActionPerformed

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
        String url = (String) this.jComboBoxMap.getSelectedItem();
        this.jComboBoxMap.removeItem(url);
        // Inform the downloader, becaus it is ruling over the downloader config
        this.sendComboboxContentToDownlaoder();
    }//GEN-LAST:event_jButtonDeleteActionPerformed

    private void jComboBoxMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMapActionPerformed
        if (this.jComboBoxMap.hasFocus()) {
            // For selection only
            this.sendComboboxContentToDownlaoder();
            this.updateConfiguration();
        }
}//GEN-LAST:event_jComboBoxMapActionPerformed

    private void jButtonDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDownloadActionPerformed
        this.downloadMap();
    }//GEN-LAST:event_jButtonDownloadActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonDownload;
    private javax.swing.JComboBox jComboBoxMap;
    private javax.swing.JLabel jLabelHeaderStatus;
    private javax.swing.JLabel jLabelHeaderStatusLastDowload;
    private javax.swing.JLabel jLabelMapName;
    private javax.swing.JLabel jLabelStatus;
    private javax.swing.JLabel jLabelStatusLastDownload;
    private javax.swing.JLabel jLabelStatusLastDownloadUpToDate;
    private javax.swing.JLabel jLabelUrl;
    private javax.swing.JPanel jPanelMap;
    private javax.swing.JPanel jPanelStatus;
    // End of variables declaration//GEN-END:variables

    /**
     * React to caret updates of the text area to add/remove/modify
     * the cloud file names in the combo box. This is done
     * by caret updates of the text area. The caret updates are (text of text area)
     * is send to this line and handled with by the receiveCommandLineParameters(String).
     * There is another way to add/remove cloud file names in the combo box: via
     * the buttons and the dialog.
     * @param parameters
     * @return
     */
    @Override
    boolean receiveCommandLineParameters(String parameters) {
        //+++ Update Status ++++++++++++++++++++++++++++++++++++++++++++++++++++
        // Update the Status
        String regExpr = "(?i)(maps\\." + this.getMarkerName() + "\\.localstatus=)(.*)";
        String found = this.receiveParameter(parameters, regExpr, 2, this.jLabelStatus);
        if (found == null) {
            // Only needet at the very beginnig, first use of programm
            // The downloader does not know the status. This can happen if the
            // the map was added initially (first use of the programm). In this
            // case the map is not configured in the configuration of the downloader
            // and therefor no status does exist.
            // Tell the user it the map is there.
            // this.mapExists();
        }
        // Update the intervall time
        regExpr = "(?i)(maps\\." + this.getMarkerName() + "\\.lastupdate=)(.*)";
        found = this.receiveParameter(parameters, regExpr, 2, this.jLabelStatusLastDownload);
        // Show up to date
        regExpr = "(?i)(maps\\." + this.getMarkerName() + "\\.downloadstatus=)(.*)";
        found = this.receiveParameter(parameters, regExpr, 2, this.jLabelStatusLastDownloadUpToDate);
        if (found != null) {
            return true;
        } else {
            return false;
        }
    }

    public String getText() {
        // nothing to seach
        return "";
    }

    public JTextComponent getTextComponent() {
        // nothing to seach
        return null;
    }

    @Override
    public boolean isDownloaderControlPanel() {
        // Yes it is but a child
        return false;
    }

    private void fillUrlList() {
        String params = this.getMainFrame().getDownloaderConfig();
        String regExprSelected = "(?i)(maps\\." + this.getMarkerName() + "\\.url\\.selected=)(.*)";
        String regExprListItems = "(?i)(maps\\." + this.getMarkerName() + "\\.url\\.listitem=)(.*)";
        this.receiveParameter(params, regExprSelected, regExprListItems, 2, this.jComboBoxMap);
        int count = this.jComboBoxMap.getItemCount();
        if (count < 1) {
            // Fill a default URL if the combo box is empty
            String s = this.getMarkerName();
            List defaultURL = (List) this.defaultURLs.get(s);
            if (defaultURL != null) {
                Iterator it = defaultURL.iterator();
                while (it.hasNext()) {
                    String url = (String) it.next();
                    this.receiveUserTextLine(url);
                }
            }
        }
    }

    /**
     * React to the dialog. The user can press a button and open a dialog
     * to add a new marker file name. There is another way to add/remove/modify
     * the cloud file names in the combo box: over the text area. This is done
     * by caret updates of the text area. The caret updates are (text of text area)
     * is send to this line and handled with by the receiveCommandLineParameters(String).
     * @param fileName
     */
    @Override
    public void receiveUserTextLine(String fileName) {
        // Do not allow double entries
        int count = this.jComboBoxMap.getItemCount();
        for (int i = 0; i < count; i++) {
            String s = (String) this.jComboBoxMap.getItemAt(i);
            if (s.equalsIgnoreCase(fileName)) {
                return;
            }
        }
        this.jComboBoxMap.addItem(fileName);
        // Inform the downloader, becaus it is ruling over the downloader config
        this.sendComboboxContentToDownlaoder();
    }

    public void sendComboboxContentToDownlaoder() {
        this.sendDownloadParameter(
                this.jComboBoxMap,
                "(?i)(maps\\." + this.getMarkerName() + "\\.url\\.listitem=)(.*)",
                "maps." + this.getMarkerName() + ".url.listitem",
                "(?i)(maps\\." + this.getMarkerName() + "\\.url\\.selected=)(.*)",
                "maps." + this.getMarkerName() + ".url.selected",
                "xplanet/images", "maps", "");
    }

    /**
     * @return the withOfJLabelMarkerName
     */
    public int getWidthOfJLabelMarkerName() {
        return this.jLabelMapName.getWidth();
    }

    /**
     * @param withOfJLabelMarkerName the withOfJLabelMarkerName to set
     */
    public void setWidthOfJLabelMarkerName(int with) {
        int height = this.jLabelMapName.getHeight();
        Dimension d = new Dimension(with, height);
        this.jLabelMapName.setMinimumSize(d);
        this.jLabelMapName.setPreferredSize(d);
        this.jPanelMap.validate();
    }

    private void fillDefaultURLs() {
        this.defaultURLs = new HashMap();
        List urls = new ArrayList();

        // Sun
        urls = new ArrayList();
        urls.add("http://www.johnstonsarchive.net/spaceart/sunmap.jpg");
        this.defaultURLs.put("sun", urls);

        // Earth
        urls = new ArrayList();
        // natural
        urls.add("http://flatplanet.sourceforge.net/maps/images/PathfinderMap.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/PathfinderMap_hires.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earth-living.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earth-sumner.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earth.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earthicefree.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earthicemap.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earthmap_hires.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/land_ocean_ice_2048.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/land_shallow_topo_2048.jpg");
        urls.add("http://www.radcyberzine.com/xglobe/earth_2400.jpg");
        // data
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_anntotprecip.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_avganntemp.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_builtupland.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_croplands.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_npp.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_oilusageperperson.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_population.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/atl_populationgrowthrate.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/bio_Dec97-Feb98.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/bio_Jun98-Aug98.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/bio_Mar98-May98.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/bio_Sep97-Nov97.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earthcyl2.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/sea_surface_temp.jpg");
        // historical
        urls.add("http://flatplanet.sourceforge.net/maps/images/1678k5.jpg");
        // night
        urls.add("http://flatplanet.sourceforge.net/maps/images/land_ocean_ice_lights_2048.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/lightpollution_2000_fixed.png");
        urls.add("http://flatplanet.sourceforge.net/maps/images/night-brilliant.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/night-dark.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/night-electric.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/night_jk.jpg");
        // topo
        urls.add("http://flatplanet.sourceforge.net/maps/images/GLOBEcolor_fast.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/GLOBEcolor_slow.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/GLOBErelief_fast.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/GLOBErelief_slow.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/USGS.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/caida.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/crust-age.jpg");
        // abstract
        urls.add("http://flatplanet.sourceforge.net/maps/images/coastlines.jpg");
        urls.add("http://flatplanet.sourceforge.net/maps/images/earth_tru_simple_invert.jpg");
        this.defaultURLs.put("earth", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/moon.jpg");
        this.defaultURLs.put("moon", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/mercury.jpg");
        urls.add("http://laps.fsl.noaa.gov/albers/sos/mercury/mercury/mercury_rgb_cyl_www.jpg");
        this.defaultURLs.put("mercury", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/venus.jpg");
        urls.add("http://laps.fsl.noaa.gov/albers/sos/venus/venus4/venus4_rgb_cyl_www.jpg");
        urls.add("hhttp://laps.fsl.noaa.gov/albers/sos/venus/venus_shaded.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/ven0aaa2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/ven0ajj2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/ven0auu1.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/ven0mss2.jpg");
        this.defaultURLs.put("venus", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/mars.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/mar0kuu2.jpg");
        this.defaultURLs.put("mars", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/mar1kuu2.jpg");
        this.defaultURLs.put("phobos", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/mar2kuu2.jpg");
        this.defaultURLs.put("deimos", urls);

        urls = new ArrayList();
        urls.add("http://www.mmedia.is/~bjj/data/io/io.jpg");
        urls.add("http://laps.fsl.noaa.gov/albers/sos/jupiter/io/io_rgb_cyl.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup1vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup1vss2.jpg");
        this.defaultURLs.put("io", urls);

        urls = new ArrayList();
        urls.add("http://www.mmedia.is/~bjj/data/europa/europa.jpg");
        urls.add("http://laps.fsl.noaa.gov/albers/sos/jupiter/europa/europa2_out.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup2vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup2vss2.jpg");
        this.defaultURLs.put("europa", urls);

        urls = new ArrayList();
        urls.add("http://www.mmedia.is/~bjj/data/ganymede/ganymede.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup3vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup3vss2.jpg");
        this.defaultURLs.put("ganymede", urls);

        urls = new ArrayList();
        urls.add("http://www.mmedia.is/~bjj/data/callisto/callisto.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup4vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup4vss2.jpg");
        this.defaultURLs.put("callisto", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/jupiter.jpg");
        urls.add("http://laps.fsl.noaa.gov/albers/sos/jupiter/jupiter/jupiter_rgb_cyl_www.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/jup0vss1.jpg");
        this.defaultURLs.put("jupiter", urls);

        urls = new ArrayList();
        urls.add("http://www.mmedia.is/~bjj/data/saturn/saturn.jpg");
        this.defaultURLs.put("saturn", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/mimas/mimas_rgb_cyl_www.jpg");
        urls.add("http://www.mmedia.is/~bjj/data/mimas/mimas_bump.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat1vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat1vss2.jpg");
        this.defaultURLs.put("mimas", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/enceladus/enceladus_rgb_cyl_www.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat2vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat2vss2.jpg");
        this.defaultURLs.put("enceladus", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/tethys/tethys_rgb_cyl_www.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat3vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat3vss2.jpg");
        this.defaultURLs.put("tethys", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/dione/dione_rgb_cyl_www.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat5vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat5vss2.jpg");
        this.defaultURLs.put("dione", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/rhea/rhea_rgb_cyl_www.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat4vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat4vss2.jpg");
        this.defaultURLs.put("rhea", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/titan/titan_rgb_cyl_www.jpg");
        this.defaultURLs.put("titan", urls);

        urls = new ArrayList();
        urls.add("http://laps.fsl.noaa.gov/albers/sos/saturn/iapetus/iapetus_rgb_cyl_www.jpg");
        urls.add("http://www.johnstonsarchive.net/spaceart/phoebemap.jpg");
        this.defaultURLs.put("iapetus", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/sat8vuu2.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/sat8vss2.jpg");
        this.defaultURLs.put("phoebe", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/uranus.jpg");
        this.defaultURLs.put("uranus", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/ura5vuu2.jpg");
        this.defaultURLs.put("miranda", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/ura1vuu2.jpg");
        this.defaultURLs.put("ariel", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/ura2vuu2.jpg");
        this.defaultURLs.put("umbriel", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/ura3vuu2.jpg");
        this.defaultURLs.put("titania", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/ura4vuu2.jpg");
        this.defaultURLs.put("oberon", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/neptune.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/nep0fds1.jpg");
        this.defaultURLs.put("neptune", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/nep1vuu2.jpg");
        this.defaultURLs.put("triton", urls);

        urls = new ArrayList();
        urls.add("http://flatplanet.sourceforge.net/maps/images/pluto.jpg");
        urls.add("http://maps.jpl.nasa.gov/pix/plu0rss1.jpg");
        this.defaultURLs.put("pluto", urls);

        urls = new ArrayList();
        urls.add("http://maps.jpl.nasa.gov/pix/plu1rss1.jpg");
        this.defaultURLs.put("charon", urls);

        /*
        this.bodyNames.add("sun");
        this.bodyNames.add("mercury");
        this.bodyNames.add("venus");
        this.bodyNames.add("earth");
        this.bodyNames.add("moon");
        this.bodyNames.add("mars");
        this.bodyNames.add("phobos");
        this.bodyNames.add("deimos");
        this.bodyNames.add("jupiter");
        this.bodyNames.add("io");
        this.bodyNames.add("europa");
        this.bodyNames.add("ganymede");
        this.bodyNames.add("callisto");
        this.bodyNames.add("saturn");
        this.bodyNames.add("mimas");
        this.bodyNames.add("enceladus");
        this.bodyNames.add("tethys");
        this.bodyNames.add("dione");
        this.bodyNames.add("rhea");
        this.bodyNames.add("titan");
        this.bodyNames.add("hyperion"); missing
        this.bodyNames.add("iapetus");
        this.bodyNames.add("phoebe");
        this.bodyNames.add("uranus");
        this.bodyNames.add("miranda");
        this.bodyNames.add("ariel");
        this.bodyNames.add("umbriel");
        this.bodyNames.add("titania");
        this.bodyNames.add("oberon");
        this.bodyNames.add("neptune");
        this.bodyNames.add("triton");
        this.bodyNames.add("nereid"); missing
        this.bodyNames.add("pluto");
        this.bodyNames.add("charon");
         */
    }

    /**
     */
    /**
     * Check if the selected URL has a local copy. Set the status (text of label.)
     * If the list of URLs is empty take the name of the body (panel), e.g.
     * 'earth', 'moon',...
     * @return true if the file was found
     */
    public boolean mapExists() {
        String fileName = getFileNameOfURL();
        if (fileName == null) {
            // If the combo box is empty take the name of the body, e.g. 'earth', 'moon',...
            fileName = this.getMarkerName();
            this.logger.finer("Take the name of the panel (body) as file name: " + fileName);
        }
        XPlanetRessourceFinder rf = new XPlanetRessourceFinder();
        String downloaderRootDir = rf.getRootDirectoryForDownloads();
        String dir = downloaderRootDir + File.separator + "images";
        String path = dir + File.separator + fileName;
        File f = new File(path);
        if (f.exists()) {
            this.logger.finer("The map for '" + fileName + "' does exist on local drive.");
            this.jLabelStatus.setText("<html><font color='green'>Found</font></html>");
            return true;
        } else {
            this.logger.finer("The map for '" + fileName + "' does NOT exist on local drive.");
            this.jLabelStatus.setText("<html><font color='red'>Missing</font></html>");
            return false;
        }
    }

    public boolean isNeedingDownload() {
        String tpyeId = "maps." + this.getMarkerName();
        boolean found = this.mapExists();
        if (found) {
            this.logger.finer("The map is on local drive for " + tpyeId);
            return false;
        } else {
            // Check URL
            if (this.jComboBoxMap.getItemCount() > 0) {
                // If the combo box has a selected item
                this.logger.finer("Yes this map (for '" + tpyeId + "') needs a download: maps." + this.getMarkerName());
                return true;
            } else {
                // If the combo box is empty take the name of the body, e.g. 'earth', 'moon',...
                this.logger.finer("No this map is not ready for update: maps." + this.getMarkerName() + ". The map is missing on the local drive but has no URL to download from.");
                return false;
            }
        }
    }

    private String getFileNameOfURL() {
        if (this.jComboBoxMap.getItemCount() > 0) {
            // If the combo box has a selected item
            String url = (String) this.jComboBoxMap.getSelectedItem();
            // URLs allways have forward slashes
            String[] splittees = url.split("/");
            int length = splittees.length;
            String fileName = splittees[length - 1];
            this.logger.finer("Take the selected item in the combo box as file name '" + fileName + "', found in the URL '" + url + "'.");
            return fileName;
        }
        return null;
    }

    private void downloadMap() {
        String fileName = this.getFileNameOfURL();
        if (fileName == null) {
            this.logger.finer("Nothing to download. No URL in combo box.");
            return;
        }
        String id = this.getMarkerName();
        this.getMainFrame().startDownloaderOnce("maps." + id);
        this.updateConfiguration();
    }

    /**
     * Updates the section (earth, moon,....) in the configuration by
     * adding/changing/removing the map in this section.
     */
    public void updateConfiguration() {
        String fileName = this.getFileNameOfURL();
        if (fileName == null) {
            this.logger.finer("Nothing to download. No URL in combo box.");
            return;
        }
        String id = this.getMarkerName();
        // Check wether the section does exist just in case the user added
        // more maps than defined in the list of default body names. Only those
        // names can be configured in the sections of the config file.
        List configurableSectionNames = getConfigurableSectionNames();
        if (configurableSectionNames.contains(id)) {
            // Update the configuration
            this.logger.finer("Update the map of section with the id '" + id + "'.");
            sendConfigParameter(id, "image", fileName, "(?i)(image=)(\\S*)");
        } else {
            this.logger.fine("This map with the id '" + id + "' can not be configured as section.");
        }
    }

    @Override
    void receiveCommandLineParameters() {
        String params = this.getMainFrame().getDownloaderConfig();
        this.receiveCommandLineParameters(params);
    }
}
TOP

Related Classes of xplanetconfigurator.gui.JPanelControlDownloaderMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.