Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlDownloaderMaps

/*
* 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.GridBagConstraints;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import xplanetconfigurator.util.OwnPreferences;

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

    private static final String GUI_DIVIDER_LOCATION_HORIZONTAL = "maps.gui_divider_location_horizontal";
    private Logger logger;
    private List markerPanels;
    int markerCountGridY = 1;
    boolean addMarker;
    boolean isAddingPixelForAlignmentRefresh;
    private List bodyNames;
    private List tempListSortPanels;

    /** Creates new form JPanelAll */
    public JPanelControlDownloaderMaps(MainFrame mainFrame) {
        super(mainFrame);
        initComponents();
        this.logger = Logger.getLogger(this.getClass().getName());
        this.fillMaps();
        this.markerPanels = new ArrayList();
        this.tempListSortPanels = new ArrayList();
        this.addMarkerPanels();
        this.addMapsNotFoundInDownloaderConfig();
        this.addSortedPanels();
        this.sendDownloadParamterWaitMinusOne();
        this.loadUserPrefs();
    }

    /** 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;

        jSplitPaneMain = new javax.swing.JSplitPane();
        jPanelControls = new javax.swing.JPanel();
        jPanelWait = new javax.swing.JPanel();
        jPanelMarkersAndButtons = new javax.swing.JPanel();
        jPanelAddRemove = new javax.swing.JPanel();
        jButtonAdd = new javax.swing.JButton();
        jButtonRemove = new javax.swing.JButton();
        jButtonDownloadAllMissingFiles = new javax.swing.JButton();
        jLabelMapsFoundCountHeader = new javax.swing.JLabel();
        jLabelMapsFoundCount = new javax.swing.JLabel();
        jLabelMapsMissingCountHeader = new javax.swing.JLabel();
        jLabelMapsMissingCount = new javax.swing.JLabel();
        jScrollPanelMarkers = new javax.swing.JScrollPane();
        jPanelMarkers = new javax.swing.JPanel();
        jPanelPlaceholder = new javax.swing.JPanel();
        jPanelHelp = new javax.swing.JPanel();
        jLabelHelp = new javax.swing.JLabel();
        jScrollPane = new javax.swing.JScrollPane();
        jTextAreaHelp = new javax.swing.JTextArea();

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

        jSplitPaneMain.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPaneMain.setName("jSplitPaneMain"); // NOI18N

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

        jPanelWait.setName("jPanelWait"); // NOI18N
        jPanelWait.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        jPanelControls.add(jPanelWait, gridBagConstraints);

        jPanelMarkersAndButtons.setBorder(javax.swing.BorderFactory.createTitledBorder("Maps"));
        jPanelMarkersAndButtons.setName("jPanelMarkersAndButtons"); // NOI18N
        jPanelMarkersAndButtons.setLayout(new java.awt.GridBagLayout());

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

        jButtonAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Button-Add-16x16.gif"))); // NOI18N
        jButtonAdd.setToolTipText("Add Marker");
        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 = 0;
        gridBagConstraints.gridy = 0;
        jPanelAddRemove.add(jButtonAdd, gridBagConstraints);

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

        jButtonDownloadAllMissingFiles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Refresh16.gif"))); // NOI18N
        jButtonDownloadAllMissingFiles.setToolTipText("Download all missing Maps");
        jButtonDownloadAllMissingFiles.setName("jButtonDownloadAllMissingFiles"); // NOI18N
        jButtonDownloadAllMissingFiles.setPreferredSize(new java.awt.Dimension(25, 25));
        jButtonDownloadAllMissingFiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDownloadAllMissingFilesActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        jPanelAddRemove.add(jButtonDownloadAllMissingFiles, gridBagConstraints);

        jLabelMapsFoundCountHeader.setText("Found:");
        jLabelMapsFoundCountHeader.setName("jLabelMapsFoundCountHeader"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        jPanelAddRemove.add(jLabelMapsFoundCountHeader, gridBagConstraints);

        jLabelMapsFoundCount.setName("jLabelMapsFoundCount"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        jPanelAddRemove.add(jLabelMapsFoundCount, gridBagConstraints);

        jLabelMapsMissingCountHeader.setText("Missing:");
        jLabelMapsMissingCountHeader.setName("jLabelMapsMissingCountHeader"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        jPanelAddRemove.add(jLabelMapsMissingCountHeader, gridBagConstraints);

        jLabelMapsMissingCount.setName("jLabelMapsMissingCount"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        jPanelAddRemove.add(jLabelMapsMissingCount, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        jPanelMarkersAndButtons.add(jPanelAddRemove, gridBagConstraints);

        jScrollPanelMarkers.setMinimumSize(new java.awt.Dimension(23, 120));
        jScrollPanelMarkers.setName("jScrollPanelMarkers"); // NOI18N
        jScrollPanelMarkers.setPreferredSize(new java.awt.Dimension(23, 120));

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

        jPanelPlaceholder.setName("jPanelPlaceholder"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 99;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        jPanelMarkers.add(jPanelPlaceholder, gridBagConstraints);

        jScrollPanelMarkers.setViewportView(jPanelMarkers);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        jPanelMarkersAndButtons.add(jScrollPanelMarkers, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanelControls.add(jPanelMarkersAndButtons, gridBagConstraints);

        jSplitPaneMain.setLeftComponent(jPanelControls);

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

        jLabelHelp.setText("Help Text");
        jLabelHelp.setName("jLabelHelp"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelHelp.add(jLabelHelp, gridBagConstraints);

        jScrollPane.setName("jScrollPane"); // NOI18N

        jTextAreaHelp.setColumns(20);
        jTextAreaHelp.setEditable(false);
        jTextAreaHelp.setRows(5);
        jTextAreaHelp.setText("This panel shows if the bodies like the earth or the moom have a map.\nIt downloads the map/image of a body from the URL to the local\nsubdirectory \"./images/\". \n\nPlease refer to the XPlanet parameters below that are related\nto maps/images.\n\n\n---XPlanet Parameters in Config File---\n\n-quality quality\nThis option is only used when creating JPEG images.  The quality can\nrange from 0 to 100.  The default value is 80.\n\n\n---XPlanet Parameters in Command Line---\n\ncolor\nIf an image map for the body is not found, use the specified color\ninstead.  The default is white, although a color is specified for most\nbodies in the default configuration file.\n\nimage\nSpecify the image map to use.  The default is body.jpg\n(e.g. earth.jpg, neptune.jpg)\n\nmap\nSame as the image option above.\n\nmapbounds={lat1,lon1,lat2,lon2}\nAssume that each map file read in has its northwest corner at\nlat1,lon1 and its southeast corner at lat2,lon2.  This is useful if\nyou have a high-res map but just want to show a small area."); // NOI18N
        jTextAreaHelp.setName("jTextAreaHelp"); // NOI18N
        jScrollPane.setViewportView(jTextAreaHelp);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanelHelp.add(jScrollPane, gridBagConstraints);

        jSplitPaneMain.setRightComponent(jPanelHelp);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jSplitPaneMain, 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
        this.addMarker = true;
        JDialogTextLineInput dialog = new JDialogTextLineInput("Add a Map. Please give a Name", this);
        dialog.setVisible(true);
    }//GEN-LAST:event_jButtonAddActionPerformed

    private void jButtonRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
        this.addMarker = false;
        JDialogTextLineInput dialog = new JDialogTextLineInput("Remove a Map. Please give a Name", this);
        dialog.setVisible(true);
    }//GEN-LAST:event_jButtonRemoveActionPerformed

    private void formComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentHidden
        this.saveUserPrefs();
    }//GEN-LAST:event_formComponentHidden

    private void jButtonDownloadAllMissingFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDownloadAllMissingFilesActionPerformed
        this.downloadAllMissingMaps();
}//GEN-LAST:event_jButtonDownloadAllMissingFilesActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonDownloadAllMissingFiles;
    private javax.swing.JButton jButtonRemove;
    private javax.swing.JLabel jLabelHelp;
    private javax.swing.JLabel jLabelMapsFoundCount;
    private javax.swing.JLabel jLabelMapsFoundCountHeader;
    private javax.swing.JLabel jLabelMapsMissingCount;
    private javax.swing.JLabel jLabelMapsMissingCountHeader;
    private javax.swing.JPanel jPanelAddRemove;
    private javax.swing.JPanel jPanelControls;
    private javax.swing.JPanel jPanelHelp;
    private javax.swing.JPanel jPanelMarkers;
    private javax.swing.JPanel jPanelMarkersAndButtons;
    private javax.swing.JPanel jPanelPlaceholder;
    private javax.swing.JPanel jPanelWait;
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JScrollPane jScrollPanelMarkers;
    private javax.swing.JSplitPane jSplitPaneMain;
    private javax.swing.JTextArea jTextAreaHelp;
    // End of variables declaration//GEN-END:variables

    /**
     * Analyse the configuration of the downloader and set the values of
     * the markers accordingly.
     *
     * @param parameters
     * @return
     */
    @Override
    boolean receiveCommandLineParameters(String parameters) {
        // Update the Status
        boolean found = false;
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap mapPanel = (JPanelControlDownloaderMap) it.next();
            boolean b = mapPanel.receiveCommandLineParameters(parameters);
            if (b) {
                found = b;
            }
        }
        this.countFoundMissingMaps();
        return found;
    }

    public String getText() {
        return this.jTextAreaHelp.getText();
    }

    public JTextComponent getTextComponent() {
        return this.jTextAreaHelp;
    }

    @Override
    public boolean isDownloaderControlPanel() {
        return true;
    }

    /**
     * Called at intial load depending on the Uploader (config of uploader)
     * and if the user adds a mapPanel by pressing the add button
     */
    private void addMarkerPanels() {
        // Read the config and add the markers found in the text of the config (file)
        // of the uploader.
        String params = this.getMainFrame().getDownloaderConfig();
        // Find all markers
        String regExpr = "(?i)(?m)^(maps\\.)(\\w+)";
        Pattern p = Pattern.compile(regExpr);
        Matcher m = p.matcher(params);
        while (m.find()) {
            String s = m.group(2);
            if (this.tempListSortPanels.contains(s)) {
                continue;
            }
            this.logger.finer("Found map named: " + s);
            this.tempListSortPanels.add(s);
        }
    }

    private void alignMarkers() {
        Iterator it = this.markerPanels.iterator();
        int maxWidth = 0;
        while (it.hasNext()) {
            JPanelControlDownloaderMap marker = (JPanelControlDownloaderMap) it.next();
            int w = marker.getWidthOfJLabelMarkerName();
            if (w > maxWidth) {
                maxWidth = w;
            }
        }
        it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap mapPanel = (JPanelControlDownloaderMap) it.next();
            mapPanel.setWidthOfJLabelMarkerName(maxWidth);
            mapPanel.validate();
        }

        // This all does not work to repaint the alignment of the marker.
//        this.jPanelMarkers.validate();
//        this.jPanelMarkers.validate();

        // TODO: Do it like intended by swing
        //       The alignment drove me crazy
        int h = this.jPanelMarkers.getHeight();
        int w = this.jPanelMarkers.getWidth();
        if (isAddingPixelForAlignmentRefresh) {
            this.jPanelMarkers.setSize(w + 1, h);
            isAddingPixelForAlignmentRefresh = false;
        } else {
            this.jPanelMarkers.setSize(w - 1, h);
            isAddingPixelForAlignmentRefresh = true;
        }
    }

    /**
     * Add maps not already found in the configuration of
     * the Downloader
     */
    private void addMapsNotFoundInDownloaderConfig() {
        // Iterate through the list of markers that are already defined
        // because the Downlooder knows them
        Iterator it = this.tempListSortPanels.iterator();
        List tempList = new ArrayList(this.bodyNames);
        while (it.hasNext()) {
            String mapName = (String) it.next();
            tempList.remove(mapName);
        }
        // Now the temp list contains all elements that are NOT already added.
        // Add them!
        it = tempList.iterator();
        while (it.hasNext()) {
            String mapToAdd = (String) it.next();
            this.logger.finer("Found a map of a body the Downloader does not know already. Adding the Panel for it: " + mapToAdd);
            // Store for sorting
            this.tempListSortPanels.add(mapToAdd);
            // this.addMarkerPanel(mapToAdd);
        }
    }

    /**
     * Called at intial load depending on the Uploader (config of uploader)
     * and if the user adds a mapPanel by pressing the add button
     */
    private void addMarkerPanel(String markerName) {
        JPanelControlDownloaderMap mapPanel = new JPanelControlDownloaderMap(this.getMainFrame(), markerName);
        this.markerPanels.add(mapPanel);

        GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = this.markerCountGridY++;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 1.0;
        this.jPanelMarkers.add(mapPanel, gridBagConstraints);
        // Import for aligning the markers. It not called the label to allign
        // has 0 with and hight and will not be visible.
        this.jPanelMarkers.validate();
    }

    private void removeMarkerPanel(String markerNameToRemove) {
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap mapPanel = (JPanelControlDownloaderMap) it.next();
            String s = mapPanel.getMarkerName();
            if (s.equalsIgnoreCase(markerNameToRemove)) {
                // Do not remove maps of the fixed list of bodies
                if (this.bodyNames.contains(s.toLowerCase())) {
                    this.popError("" +
                            "This map can't be removed\n" +
                            "because it belongs to a" +
                            "celestial body.");
                    return;
                }
                this.jPanelMarkers.remove(mapPanel);
                this.markerPanels.remove(mapPanel);
                this.removeMarkerFromUplaoder(s, "maps");
                this.jPanelMarkers.validate();
                return;
            }
        }
    }

    /**
     * Add or remove a mapPanel after the user opened a Dialog.
     * @param nameFromDialog
     */
    public void receiveUserTextLine(String nameFromDialog) {
        // do not allow blanks
        nameFromDialog = nameFromDialog.replaceAll("\\s+", "");
        if (nameFromDialog.equals("")) {
            //Do nothing
            return;
        }
        nameFromDialog = nameFromDialog.toLowerCase();
        // Check wether to remove mapPanel
        if (!this.addMarker) {
            this.removeMarkerPanel(nameFromDialog);
            return;
        }
        // Add mapPanel
        // Check if other markers carry the same name
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap marker = (JPanelControlDownloaderMap) it.next();
            String s = marker.getMarkerName();
            if (s.equalsIgnoreCase(nameFromDialog)) {
                this.popError("A map of this name does exits.\nChoose another name.");
                return;
            }
        }
        // Check the whole downloader config for double names
        boolean exists = this.checkIfNameOfMarkerExists(nameFromDialog, "maps");
        if (exists) {
            this.popError("A marker or satellite named like this does exit.\nChoose another name.");
            return;
        }
        this.addMarkerPanel(nameFromDialog);
        this.alignMarkers();
        this.jPanelMarkers.validate();
        // Allways tell the Downloader to exclude this URL from automatic downloads
        this.sendDownloadParamterWaitMinusOne();
    }

    private void loadUserPrefs() {
        logger.finer("Getting user preferences...");
        OwnPreferences prefs = OwnPreferences.userNodeForPackage(this.getClass())// Position an size of frame

        int i = prefs.getInt(JPanelControlDownloaderMaps.GUI_DIVIDER_LOCATION_HORIZONTAL, 300);
        this.jSplitPaneMain.setDividerLocation(i);
    }

    private void saveUserPrefs() {
        OwnPreferences prefs = OwnPreferences.userNodeForPackage(this.getClass());
        prefs.putInt(JPanelControlDownloaderMaps.GUI_DIVIDER_LOCATION_HORIZONTAL, this.jSplitPaneMain.getDividerLocation());
    }

    private void fillMaps() {
        this.bodyNames = new ArrayList();
        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");
        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");
        this.bodyNames.add("pluto");
        this.bodyNames.add("charon");
    }

    /**
     * Tell the Downloader not to download any of the maps automatically by
     * setting the wait time for every URL to '-1'.
     */
    private void sendDownloadParamterWaitMinusOne() {
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap markerPanel = (JPanelControlDownloaderMap) it.next();
            JTextField tempField = new JTextField();
            tempField.setText("-1");
            this.sendDownloadParameter(
                    tempField,
                    "(maps\\." + markerPanel.getMarkerName() + "\\.wait=)(.*)",
                    "maps." + markerPanel.getMarkerName() + ".wait");
        }
    }

    /**
     * Call each mapPanel to download its map if missing.
     */
    private void downloadAllMissingMaps() {
        List typeIDsToDownload = new ArrayList();
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMap markerPanel = (JPanelControlDownloaderMap) it.next();
            boolean needsDownload = markerPanel.isNeedingDownload();
            if (needsDownload) {
                String typeId = "maps." + markerPanel.getMarkerName();
                this.logger.finer("Adding type.id '" + typeId + "' to the list of files to downlaod...");
                typeIDsToDownload.add(typeId);
                // Assume the user wants to use the downloaded maps.
                // Update the maps in every section
                markerPanel.updateConfiguration();
            }
        }
        this.getMainFrame().startDownloaderOnce(typeIDsToDownload);
    }

    private void countFoundMissingMaps() {
        Iterator it = this.markerPanels.iterator();
        int countFoundMaps = 0;
        int countMissingMaps = 0;
        while (it.hasNext()) {
            JPanelControlDownloaderMap markerPanel = (JPanelControlDownloaderMap) it.next();
            boolean exists = markerPanel.mapExists();
            if(exists) {
                countFoundMaps++;
            } else {
                countMissingMaps++;
            }
        }
        this.jLabelMapsFoundCount.setText(Integer.toString(countFoundMaps));
        this.jLabelMapsMissingCount.setText(Integer.toString(countMissingMaps));
    }

    private void addSortedPanels() {
        List tempList = new ArrayList(this.tempListSortPanels);
        List tempListSorted = new ArrayList();
        Iterator it = this.bodyNames.iterator();
        while(it.hasNext()) {
            String bodyName = (String) it.next();
            this.logger.finer("Adding body '" + bodyName + "' to sorted list.");
            tempListSorted.add(bodyName);
            tempList.remove(bodyName);
        }
        if(! tempList.isEmpty()) {
            this.logger.finer("There are more maps defined than contained in the list of default names for the bodies. Add them...");
            tempListSorted.addAll(tempList);
        }
        it = tempListSorted.iterator();
        while(it.hasNext()) {
            String bodyName = (String) it.next();
            this.addMarkerPanel(bodyName);
        }
    }

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

Related Classes of xplanetconfigurator.gui.JPanelControlDownloaderMaps

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.