Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JPanelControlConfigFileArcs

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

    private Logger logger;

    /** Creates new form JPanelAll */
    public JPanelControlConfigFileArcs(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();
        jPanelMarkerFile = new javax.swing.JPanel();
        jLabelOrbitMarkerFile = new javax.swing.JLabel();
        jComboBoxMarkerFile = new javax.swing.JComboBox();
        jButtonAdd = new javax.swing.JButton();
        jButtonDelete = new javax.swing.JButton();
        jLabelArcColor = new javax.swing.JLabel();
        jTextFieldParameterArcColor = new javax.swing.JTextField();
        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());

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

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

        jComboBoxMarkerFile.setMinimumSize(new java.awt.Dimension(100, 18));
        jComboBoxMarkerFile.setName("jComboBoxMarkerFile"); // NOI18N
        jComboBoxMarkerFile.setPreferredSize(new java.awt.Dimension(100, 18));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelMarkerFile.add(jComboBoxMarkerFile, 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;
        jPanelMarkerFile.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;
        jPanelMarkerFile.add(jButtonDelete, gridBagConstraints);

        jLabelArcColor.setText("<html><b>arc_color"); // NOI18N
        jLabelArcColor.setName("jLabelArcColor"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelMarkerFile.add(jLabelArcColor, gridBagConstraints);

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

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanelControls.add(jPanelMarkerFile, 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("arc_color\nSpecify the default color for great arcs.  This color will be\noverridden if a color is specified for an arc in the arc file.  The\ncolor may be specified either as a name, a hexadecimal number, or as\nan RGB triple.  For example, arc_color=red, arc_color=0xff0000, and\narc_color={255,0,0} all mean the same thing.  The default value is\nwhite.\n\narc_file\nSpecify a great arc file for this planet.  This option may be used\nmore than once.  See the README and sample files in the xplanet/arcs\ndirectory for more information.  The default is no arc files."); // 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 jTextFieldParameterArcColorCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldParameterArcColorCaretUpdate
        this.sendConfigParameter(this.jTextFieldParameterArcColor, "arc_color", "(?i)(arc_color=)(\\S*)");
}//GEN-LAST:event_jTextFieldParameterArcColorCaretUpdate

    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

    private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteActionPerformed
        String url = (String) this.jComboBoxMarkerFile.getSelectedItem();
        this.jComboBoxMarkerFile.removeItem(url);
        this.sendConfigParameter(this.jComboBoxMarkerFile, "arc_file", "(?i)(\\barc_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 jComboBoxMarkerFile;
    private javax.swing.JLabel jLabelArcColor;
    private javax.swing.JLabel jLabelHelp;
    private javax.swing.JLabel jLabelOrbitMarkerFile;
    private javax.swing.JPanel jPanelControls;
    private javax.swing.JPanel jPanelHelp;
    private javax.swing.JPanel jPanelMarkerFile;
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextAreaHelp;
    private javax.swing.JTextField jTextFieldParameterArcColor;
    // End of variables declaration//GEN-END:variables

    @Override
    boolean receiveCommandLineParameters(String parameters) throws XPlanetException {
        boolean hasFound = this.findParameterString(parameters);
        if (hasFound) {
            // Find the the whole section
            String sectionText = this.getWholeSection();
            String regExpr = "(?i)(arc_color=)(\\S+)";
            this.receiveParameter(sectionText, regExpr, this.jTextFieldParameterArcColor, 2);
            String regExprListItems = "(?i)(arc_file=)(.*)";
            this.receiveParameter(parameters, null, regExprListItems, 2, this.jComboBoxMarkerFile);
            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 + "arcs";
        // Select the directory
        File f = new File(dir);
        String selectedFileName = (String) this.jComboBoxMarkerFile.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 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...");
            }
            // Do not allow double entries
            int count = this.jComboBoxMarkerFile.getItemCount();
            for (int i = 0; i < count; i++) {
                String s = (String) this.jComboBoxMarkerFile.getItemAt(i);
                if (s.equalsIgnoreCase(fileName)) {
                    this.logger.finer("The file name is already in the list: " + fileName);
                    return;
                }
            }
            this.jComboBoxMarkerFile.addItem(fileName);
            this.sendConfigParameter(this.jComboBoxMarkerFile, "arc_file", "(?i)(\\barc_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.JPanelControlConfigFileArcs

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.