Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlConfigFileClouds

/*
* 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.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.text.JTextComponent;
import xplanetconfigurator.util.XPlanetRessourceFinder;

/**
*
* @author tom
*/
public class JPanelControlConfigFileClouds extends ControlPanel {

    private Logger logger;

    /** Creates new form JPanelAll */
    public JPanelControlConfigFileClouds(MainFrame mainFrame) {
        super(mainFrame);
        initComponents();
        this.logger = Logger.getLogger(this.getClass().getName());
    }

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

        jPanelControls = new javax.swing.JPanel();
        jTextFieldParameterCloudMap = new javax.swing.JTextField();
        jLabelCloudMap = new javax.swing.JLabel();
        jLabelCloudGamma = new javax.swing.JLabel();
        jTextFieldParameterCloudGamma = new javax.swing.JTextField();
        jLabelCloudThreshold = new javax.swing.JLabel();
        jTextFieldParameterCloudThreshold = new javax.swing.JTextField();
        jCheckBoxCloudSsec = new javax.swing.JCheckBox();
        jButtonAdd = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        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 componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        setLayout(new java.awt.GridBagLayout());

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

        jTextFieldParameterCloudMap.setMinimumSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudMap.setName("jTextFieldParameterCloudMap"); // NOI18N
        jTextFieldParameterCloudMap.setPreferredSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudMap.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldParameterCloudMapCaretUpdate(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jTextFieldParameterCloudMap, gridBagConstraints);

        jLabelCloudMap.setText("<html><b>cloud_map"); // NOI18N
        jLabelCloudMap.setName("jLabelCloudMap"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jLabelCloudMap, gridBagConstraints);

        jLabelCloudGamma.setText("<html><b>cloud_gamma"); // NOI18N
        jLabelCloudGamma.setName("jLabelNumTimes"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jLabelCloudGamma, gridBagConstraints);

        jTextFieldParameterCloudGamma.setMinimumSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudGamma.setName("jTextFieldParameterCloudGamma"); // NOI18N
        jTextFieldParameterCloudGamma.setPreferredSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudGamma.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldParameterCloudGammaCaretUpdate(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jTextFieldParameterCloudGamma, gridBagConstraints);

        jLabelCloudThreshold.setText("<html><b>cloud_threshold"); // NOI18N
        jLabelCloudThreshold.setName("jLabelCloudThreshold"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jLabelCloudThreshold, gridBagConstraints);

        jTextFieldParameterCloudThreshold.setMinimumSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudThreshold.setName("jTextFieldParameterCloudThreshold"); // NOI18N
        jTextFieldParameterCloudThreshold.setPreferredSize(new java.awt.Dimension(70, 20));
        jTextFieldParameterCloudThreshold.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldParameterCloudThresholdCaretUpdate(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jTextFieldParameterCloudThreshold, gridBagConstraints);

        jCheckBoxCloudSsec.setText("<html><b>cloud_ssec"); // NOI18N
        jCheckBoxCloudSsec.setName("jCheckBoxCloudSsec"); // NOI18N
        jCheckBoxCloudSsec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxCloudSsecActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jCheckBoxCloudSsec, gridBagConstraints);

        jButtonAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xplanetconfigurator/gui/resources/img/Button-Add-16x16.gif"))); // NOI18N
        jButtonAdd.setToolTipText("Choose Cloud Map...");
        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 = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jButtonAdd, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(jPanelControls, gridBagConstraints);

        jSeparator1.setName("jSeparator1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        add(jSeparator1, gridBagConstraints);

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

        jLabelHelp.setText("Help Text of XPlanet");
        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("cloud_map\nSpecify an image to overlay on the planet map.  The default is no\ncloud map.\n\ncloud_ssec\nIf true, assume the cloud map is an image downloaded from the Space\nScience and Engineering Center (SSEC) at the University of Wisconsin.\nThe latest image (updated every three hours) can be obtained from\nhttp://www.ssec.wisc.edu/data/comp/latest_moll.gif. This image is a\n640x350 pixel Mollweide composite image with ugly pink coastlines.\nXplanet will reproject and resize the image as well as remove and fill\nin the coastlines.\n\ncloud_gamma\nApply a gamma correction to the cloud image before overlaying.  Each\npixel's brightness is adjusted according to:\nnew_value = 255 * [(old_value/255)^(1/gamma)]\nThe default is 1 (no gamma correction).\n\ncloud_threshold\nCloud pixel values below threshold will be ignored.  The value for\nthreshold should be between 0 and 255.  The default is 90.\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);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jPanelHelp, 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 jTextFieldParameterCloudGammaCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldParameterCloudGammaCaretUpdate
        this.sendConfigParameter(this.jTextFieldParameterCloudGamma, "cloud_gamma", "(?i)(cloud_gamma=)(\\S*)");
}//GEN-LAST:event_jTextFieldParameterCloudGammaCaretUpdate

    private void jTextFieldParameterCloudThresholdCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldParameterCloudThresholdCaretUpdate
        this.sendConfigParameter(this.jTextFieldParameterCloudThreshold, "cloud_threshold", "(?i)(cloud_threshold=)(\\S*)");
}//GEN-LAST:event_jTextFieldParameterCloudThresholdCaretUpdate

    private void jCheckBoxCloudSsecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxCloudSsecActionPerformed
        this.sendConfigParameter(this.jCheckBoxCloudSsec, "cloud_ssec", "(?i)(cloud_ssec=)(\\S*)");
}//GEN-LAST:event_jCheckBoxCloudSsecActionPerformed

    private void jTextFieldParameterCloudMapCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldParameterCloudMapCaretUpdate
        this.sendConfigParameter(this.jTextFieldParameterCloudMap, "cloud_map", "(?i)(cloud_map=)(\\S*)");
}//GEN-LAST:event_jTextFieldParameterCloudMapCaretUpdate

    private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
        //        JDialogTextLineInput dialog = new JDialogTextLineInput("Please give a URL", this);
        //        dialog.setVisible(true);
        this.chooseMarkerFromDirectory();
}//GEN-LAST:event_jButtonAddActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JCheckBox jCheckBoxCloudSsec;
    private javax.swing.JLabel jLabelCloudGamma;
    private javax.swing.JLabel jLabelCloudMap;
    private javax.swing.JLabel jLabelCloudThreshold;
    private javax.swing.JLabel jLabelHelp;
    private javax.swing.JPanel jPanelControls;
    private javax.swing.JPanel jPanelHelp;
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextAreaHelp;
    private javax.swing.JTextField jTextFieldParameterCloudGamma;
    private javax.swing.JTextField jTextFieldParameterCloudMap;
    private javax.swing.JTextField jTextFieldParameterCloudThreshold;
    // End of variables declaration//GEN-END:variables

    @Override
    boolean receiveCommandLineParameters(String parameters) throws XPlanetException {
        boolean hasFound = this.findParameterString(parameters);
        if (hasFound) {
            String sectionText = this.getWholeSection();
            String regExpr = "(?i)(cloud_gamma=)(\\S+)";
            this.receiveParameter(sectionText, regExpr, this.jTextFieldParameterCloudGamma, 2);
            regExpr = "(?i)(cloud_map=)(\\S+)";
            this.receiveParameter(sectionText, regExpr, this.jTextFieldParameterCloudMap, 2);
            regExpr = "(?i)(cloud_threshold=)(\\S+)";
            this.receiveParameter(sectionText, regExpr, this.jTextFieldParameterCloudThreshold, 2);
            regExpr = "(?i)(cloud_ssec=)(true)";
            this.receiveParameter(sectionText, regExpr, this.jCheckBoxCloudSsec);
            return true;
        } else {
            this.logger.finest("Did not find own parameter");
            return false;
        }
    }

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

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

    /**
     * Open a file chooser and show the content of the marker directory to
     * add a marker file.
     */
    private void chooseMarkerFromDirectory() {
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        XPlanetRessourceFinder rf = new XPlanetRessourceFinder();
        String downloaderRootDir = rf.getRootDirectoryForDownloads();
        String dir = downloaderRootDir + File.separator + "images";
        // Select the directory
        File f = new File(dir);
        String selectedFileName = (String) this.jTextFieldParameterCloudMap.getText();
        if (selectedFileName != null) {
            // Select the selected marker file
            String s = dir + File.separator + selectedFileName;
            f = new File(s);
        }
        fc.setSelectedFile(f);
        fc.setMultiSelectionEnabled(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            this.logger.finer("User choose a marker file from the markers directory: " + file.getAbsolutePath());
            String fileName = file.getName();
            if (fileName != null) {
                this.logger.finer("The file name is: " + fileName + ". Adding to list...");
            }
            this.jTextFieldParameterCloudMap.setText(fileName);
            this.sendConfigParameter(this.jTextFieldParameterCloudMap, "cloud_map", "(?i)(cloud_map=)(\\S*)", true);
        }
    }

    @Override
    void receiveCommandLineParameters() {
        String params = this.getMainFrame().getConfigParameters();
        try {
            this.receiveCommandLineParameters(params);
        } catch (XPlanetException ex) {
            this.logger.log(Level.SEVERE, null, ex);
        }
    }
}
TOP

Related Classes of xplanetconfigurator.gui.JPanelControlConfigFileClouds

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.