Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlDownloaderMarkers

/*
* 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.text.JTextComponent;
import xplanetconfigurator.util.OwnPreferences;

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

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

    /** Creates new form JPanelAll */
    public JPanelControlDownloaderMarkers(MainFrame mainFrame) {
        super(mainFrame);
        initComponents();
        this.logger = Logger.getLogger(this.getClass().getName());
        this.markerPanels = new ArrayList();
        // this.addMarkerPanels();
        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();
        jLabelWait = new javax.swing.JLabel();
        jTextFieldWait = new javax.swing.JTextField();
        jLabelMinutes = new javax.swing.JLabel();
        jPanelMarkersAndButtons = new javax.swing.JPanel();
        jPanelAddRemove = new javax.swing.JPanel();
        jButtonAdd = new javax.swing.JButton();
        jButtonRemove = new javax.swing.JButton();
        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());

        jLabelWait.setText("Download Intervall"); // NOI18N
        jLabelWait.setName("jLabelWait"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelWait.add(jLabelWait, gridBagConstraints);

        jTextFieldWait.setMinimumSize(new java.awt.Dimension(70, 20));
        jTextFieldWait.setName("jTextFieldWait"); // NOI18N
        jTextFieldWait.setPreferredSize(new java.awt.Dimension(70, 20));
        jTextFieldWait.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldWaitCaretUpdate(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        jPanelWait.add(jTextFieldWait, gridBagConstraints);

        jLabelMinutes.setText("minutes");
        jLabelMinutes.setName("jLabelMinutes"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        jPanelWait.add(jLabelMinutes, gridBagConstraints);

        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("Markers"));
        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);

        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("Download Intervall\nIs in minutes. If the text field is empty the downloader takes 180 minutes\n(3 hours) as default. Applies for all markers.\n\nAdd/Remove a Marker\n- To add a marker press the upper \"+\" button. Type a name in the dialog.\nAdd a URL to the combo box. Example:\nname:\tvolcanos\nURL:\thttp://xydomain.org/example/volcanos\n- To remove a marker press the upper \"-\" button.\n\nRemember this is the download only. If you want o see the markers you\nhave to set at least the parameter \"marker_file\" in the config file.\nPlease refer to the XPlanet parameters below that are related to the clouds.\n\n\n---XPlanet Parameters in Config File---\n\nmarker_color\nSpecify the default color for all markers.  This color will be\noverridden if a color is specified for a marker in the marker file.\nThe default is red.\n\nmarker_file\nSpecify a file containing user defined marker data to display on the\nmap.  This option may be used more than once.  The default is no\nmarker file.  See the README and sample files in the xplanet/markers\ndirectory for more information.\n\nmarker_font\nSpecify the default font for all markers for this body.  This option\nmay be overridden inside the marker file.  The default is to use the\nvalue from the command line -font option.\n\nmarker_fontsize\nSpecify the default font size for all markers for this body.  This\noption may be overridden inside the marker file.  The default is to\nuse the value from the command line -fontsize option.\n\nmax_radius_for_label\nDon't draw a label for the body if its radius is greater than this\nvalue.  The default is 3 pixels.\n\nmin_radius_for_label\nDon't draw a label for the body if its radius is less than this\nvalue.  The default is 0.01 pixel.\n\nmin_radius_for_markers\nDon't draw markers on the body if its radius is less than this value.\nThe default is 40 pixels.\n\ntext_color\nSpecify the color for the markers and body label.  The default is red.\n\n\n---XPlanet Parameters in Command Line---\n\n-markerbounds filename\nWrite coordinates of the bounding box for each marker to filename.\nThis might be useful if you're using xplanet to make imagemaps for web\npages.  Each line looks like:\n\n204,312 277,324 Los Angeles\n\nwhere the coordinates are for the upper left and lower right corners\nof the box.  This file gets rewritten every time xplanet renders its\nimage.\n\n\n"); // 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 jTextFieldWaitCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldWaitCaretUpdate
        if (this.jTextFieldWait.hasFocus()) {
            this.sendDownloadParamterWait();
        }
    }//GEN-LAST:event_jTextFieldWaitCaretUpdate

    private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
        this.addMarker = true;
        JDialogTextLineInput dialog = new JDialogTextLineInput("Add a Marker. 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 Marker. 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
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonRemove;
    private javax.swing.JLabel jLabelHelp;
    private javax.swing.JLabel jLabelMinutes;
    private javax.swing.JLabel jLabelWait;
    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;
    private javax.swing.JTextField jTextFieldWait;
    // 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
        String params = this.getMainFrame().getDownloaderConfig();
        // Take any markerPanel for the wait
        String regExpr = "(?i)(markers\\.\\w+.wait=)(\\S+)";
        String found = this.receiveParameter(params, regExpr, this.jTextFieldWait, 2);
        this.checkMarkerPanels();
        // TODO: Call all markers to reload its values (status of local and downloaded file,...)
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMarker markerPanel = (JPanelControlDownloaderMarker) it.next();
            markerPanel.receiveCommandLineParameters(parameters);
        }
        if (found != null) {
            this.downloadIntervallTmpForNewMarkers = found;
            return true;
        } else {
            this.downloadIntervallTmpForNewMarkers = "180";
            this.jTextFieldWait.setText("180");
            return false;
        }
    }

    private void checkMarkerPanels() {
        List markerNamesInDownloadConfig = this.readAllMarkerPanesFromDownloaderConfiguration("(?i)(?m)^(markers\\.)(\\w+)");
        List markerNamesInGUI = this.getAllMarkerPanelsShownInGUI();
        // Remove MarkerPanels from the GUI that are not in the config any longer
        Iterator it = markerNamesInGUI.iterator();
        while (it.hasNext()) {
            String markerNameGUI = (String) it.next();
            if (!markerNamesInDownloadConfig.contains(markerNameGUI)) {
                // Remove from GUI. (Tries to remove it from config as well although it not there.)
                this.removeMarkerPanel(markerNameGUI);
            }
        }
        // Add MarkerPanels that are missing in the GUI but not in the config.
        it = markerNamesInDownloadConfig.iterator();
        while (it.hasNext()) {
            String markerNameConfig = (String) it.next();
            if (!markerNamesInGUI.contains(markerNameConfig)) {
                // Remove from GUI. (Tries to remove it from config as well although it not there.)
                this.addMarkerPanel(markerNameConfig);
            }
        }
    }

    /**
     *
     * @return a List of Strings containing all marker names shown in the GUI
     */
    private List getAllMarkerPanelsShownInGUI() {
        List tempListMarkerNames = new ArrayList();
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMarker markerPanel = (JPanelControlDownloaderMarker) it.next();
            String s = markerPanel.getMarkerName();
            tempListMarkerNames.add(s);
        }
        return tempListMarkerNames;
    }

    private void sendDownloadParamterWait() {
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMarker markerPanel = (JPanelControlDownloaderMarker) it.next();
            this.sendDownloadParameter(
                    this.jTextFieldWait,
                    "(markers\\." + markerPanel.getMarkerName() + "\\.wait=)(.*)",
                    "markers." + markerPanel.getMarkerName() + ".wait");
        }
    }

    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 markerPanel 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)^(markers\\.)(\\w+)";
        Pattern p = Pattern.compile(regExpr);
        Matcher m = p.matcher(params);
        List names = new ArrayList();
        while (m.find()) {
            String s = m.group(2);
            if (names.contains(s)) {
                continue;
            }
            this.logger.finer("Found marker named: " + s);
            names.add(s);
        }
        Iterator it = names.iterator();
        while (it.hasNext()) {
            String panelName = (String) it.next();
            this.addMarkerPanel(panelName);
        }
    }

    private void alignMarkers() {
        Iterator it = this.markerPanels.iterator();
        int maxWidth = 0;
        while (it.hasNext()) {
            JPanelControlDownloaderMarker marker = (JPanelControlDownloaderMarker) it.next();
            int w = marker.getWidthOfJLabelMarkerName();
            if (w > maxWidth) {
                maxWidth = w;
            }
        }
        it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMarker markerPanel = (JPanelControlDownloaderMarker) it.next();
            markerPanel.setWidthOfJLabelMarkerName(maxWidth);
            markerPanel.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 is not intuitive to use.)
        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;
        }
    }

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

        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(markerPanel, 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()) {
            JPanelControlDownloaderMarker markerPanel = (JPanelControlDownloaderMarker) it.next();
            String s = markerPanel.getMarkerName();
            if (s.equalsIgnoreCase(markerNameToRemove)) {
                this.jPanelMarkers.remove(markerPanel);
                this.markerPanels.remove(markerPanel);
                this.removeMarkerFromUplaoder(s, "markers");
                this.jPanelMarkers.validate();
                return;
            }
        }
    }

    /**
     * Add or remove a markerPanel 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 markerPanel
        if (!this.addMarker) {
            this.removeMarkerPanel(nameFromDialog);
            this.updateConfiguration();
            return;
        }
        // Add markerPanel
        // Check if other markers carry the same name
        Iterator it = this.markerPanels.iterator();
        while (it.hasNext()) {
            JPanelControlDownloaderMarker marker = (JPanelControlDownloaderMarker) it.next();
            String s = marker.getMarkerName();
            if (s.equalsIgnoreCase(nameFromDialog)) {
                this.popError("A marker of this name does exits.\nChoose another name.");
                return;
            }
        }
        // Check the whole downloader config for double names
        boolean exists = this.checkIfNameOfMarkerExists(nameFromDialog, "markers");
        if (exists) {
            this.popError("A marker or satellite named like this does exits.\nChoose another name.");
            return;
        }
        this.addMarkerPanel(nameFromDialog);
        this.alignMarkers();
        this.jPanelMarkers.validate();
        this.updateConfiguration();
    }

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

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

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

    /**
     * Updates the section (earth, moon,....) in the configuration by
     * adding/changing/removing the marker_file for the section.
     */
    public void updateConfiguration() {
        Iterator it = this.markerPanels.iterator();
        String keyValuePairs = "";
        while (it.hasNext()) {
            JPanelControlDownloaderMarker marker = (JPanelControlDownloaderMarker) it.next();
            String markerURL = marker.getCurrentURL();
            String fileName = getFileNameOfURL(markerURL);
            if (fileName == null) {
                continue;
            }
            // Do not allow blanks
            // fileName = fileName.replaceAll("\\s+", "");
            if (markerURL != null) {
                if (keyValuePairs.length() > 0) {
                    keyValuePairs = keyValuePairs + "\n";
                }
                keyValuePairs = keyValuePairs + "marker_file=" + fileName;
            }

        }
        this.logger.finer("Update arc files of section default with key-value-pairs of '" + keyValuePairs + "'.");
        sendConfigParameter("earth", keyValuePairs, "(?i)(marker_file=)(\\S*)");
    }

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

Related Classes of xplanetconfigurator.gui.JPanelControlDownloaderMarkers

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.