Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlConfigFileSatellites

/*
* 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 JPanelControlConfigFileSatellites extends ControlPanel {

    private Logger logger;

    /** Creates new form JPanelAll */
    public JPanelControlConfigFileSatellites(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();
        jLabelSatelliteFile = new javax.swing.JLabel();
        jComboBoxSatFile = new javax.swing.JComboBox();
        jButtonAdd = new javax.swing.JButton();
        jButtonDelete = 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());

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

        jComboBoxSatFile.setMinimumSize(new java.awt.Dimension(100, 18));
        jComboBoxSatFile.setName("jComboBoxSatFile"); // NOI18N
        jComboBoxSatFile.setPreferredSize(new java.awt.Dimension(100, 18));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jComboBoxSatFile, 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 = 3;
        gridBagConstraints.gridy = 1;
        jPanelControls.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 = 4;
        gridBagConstraints.gridy = 1;
        jPanelControls.add(jButtonDelete, 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("satellite_file\nSpecify a file containing a list of satellites to display.  A file\ncontaining NORAD two line element (TLE) sets named satfile.tle must\nexist along with satfile.  A good source of TLEs is www.celestrak.com.\nThis option may be used more than once.  The default is no satellite\nfiles.  See the README and sample files in the xplanet/satellites\ndirectory for more information."); // 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 jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
        //        JDialogTextLineInput dialog = new JDialogTextLineInput("Please give a URL", this);
        //        dialog.setVisible(true);
        this.chooseSatfilesFromDirectory();
}//GEN-LAST:event_jButtonAddActionPerformed

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
        String url = (String) this.jComboBoxSatFile.getSelectedItem();
        this.jComboBoxSatFile.removeItem(url);
        this.sendConfigParameter(this.jComboBoxSatFile, "satellite_file", "(?i)(\\bsatellite_file\\b=)(.*)");
}//GEN-LAST:event_jButtonDeleteActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdd;
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JComboBox jComboBoxSatFile;
    private javax.swing.JLabel jLabelHelp;
    private javax.swing.JLabel jLabelSatelliteFile;
    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;
    // 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 regExprListItems = "(?i)(satellite_file=)(.*)";
            // Add or remove from combobox
            this.receiveParameter(sectionText, null, regExprListItems, 2, this.jComboBoxSatFile);
            return true;
        } else {
            this.jComboBoxSatFile.removeAllItems();
            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 chooseSatfilesFromDirectory() {
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        XPlanetRessourceFinder rf = new XPlanetRessourceFinder();
        String downloaderRootDir = rf.getRootDirectoryForDownloads();
        String dir = downloaderRootDir + File.separator + "satellites";
        // Select the directory
        File f = new File(dir);
        String selectedFileName = (String) this.jComboBoxSatFile.getSelectedItem();
        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 satellite 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...");
            }
            // Remove the .tle if the user choose this file
            fileName = fileName.replaceAll("(i?)\\.tle", "");
            // Do not allow double entries
            int count = this.jComboBoxSatFile.getItemCount();
            for (int i = 0; i < count; i++) {
                String s = (String) this.jComboBoxSatFile.getItemAt(i);
                if (s.equalsIgnoreCase(fileName)) {
                    this.logger.finer("The file name is already in the list: " + fileName);
                    return;
                }
            }
            // Check if both files exist "iss" and "iss.tle".
            f = new File(dir + File.separator + fileName);
            if (!f.exists()) {
                this.popError("Both files must exist for satellite: " + fileName + "\n" + fileName + " is missing.");
                return;
            }
            f = new File(dir + File.separator + fileName + ".tle");
            if (!f.exists()) {
                this.popError("Both files must exist for satellite: " + fileName + "\n" + fileName + ".tle is missing.");
                return;
            }

            // Add the satellite
            this.jComboBoxSatFile.addItem(fileName);
            this.sendConfigParameter(this.jComboBoxSatFile, "satellite_file", "(?i)(\\bsatellite_file\\b=)(.*)");
        }
    }

    @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.JPanelControlConfigFileSatellites

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.