Package com.groovesquid.gui

Source Code of com.groovesquid.gui.Settings

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.groovesquid.gui;

import com.groovesquid.Config;
import com.groovesquid.InitThread;
import com.groovesquid.Main;
import com.groovesquid.model.Language;
import com.groovesquid.util.Utils;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.*;

/**
*
* @author marius
*/
public class Settings extends javax.swing.JFrame {

    private String originalDownloadDirectory, originalMaxParallelDownloads, originalFileNameScheme, originalProxyHost, originalProxyPort;
    private boolean originalAutocompleteEnabled;
    private int originalDownloadComplete, originalLanguage;
   
    /**
     * Creates new form Settings
     */
    public Settings() {
        initComponents();
       
        // center screen
        setLocationRelativeTo(null);
       
        // icon
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon.png")));
       
        // update config settings
        resetSettings();
       
        // original settings
        setOriginalSettings();
    }

    /**
     * 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() {

        reconnectButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        downloadDirectoryTextField = new javax.swing.JTextField();
        maxParallelDownloadsSpinner = new javax.swing.JSpinner();
        saveSettingsButton = new javax.swing.JButton();
        downloadDirectoryButton = new javax.swing.JButton();
        fileNameSchemeTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        autocompleteEnabledCheckBox = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        downloadCompleteComboBox = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        languageComboBox = new javax.swing.JComboBox();
        resetOriginalSettingsButton = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        fileExistsComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        proxyHostTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        proxyPortTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle(Main.getLocaleString("SETTINGS"));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        reconnectButton.setText(Main.getLocaleString("RECONNECT"));
        reconnectButton.setFocusable(false);
        reconnectButton.setRequestFocusEnabled(false);
        reconnectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reconnectButtonActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel6.setText(Main.getLocaleString("MAX_PARALLEL_DOWNLOADS"));

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel1.setText(Main.getLocaleString("DOWNLOAD_DIRECTORY"));

        downloadDirectoryTextField.setRequestFocusEnabled(false);

        maxParallelDownloadsSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(10), Integer.valueOf(1), null, Integer.valueOf(1)));
        maxParallelDownloadsSpinner.setValue(10);

        saveSettingsButton.setText(Main.getLocaleString("SAVE_AND_CLOSE"));
        saveSettingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveSettingsButtonActionPerformed(evt);
            }
        });

        downloadDirectoryButton.setText("...");
        downloadDirectoryButton.setFocusable(false);
        downloadDirectoryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadDirectoryButtonActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel2.setText(Main.getLocaleString("FILENAME_SCHEME"));

        jLabel3.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
        jLabel3.setLabelFor(fileNameSchemeTextField);
        jLabel3.setText("<html><body>This is a format string for file path of downloaded files. Use / to create a subdirectory. Use &lt;Artist&gt; to insert the artist's name, &lt;Album&gt; to insert the album title, &lt;Title&gt; to insert the track's name, &lt;#&gt; to insert the track number (if any), &lt;%&gt; to insert the track order (for playlists only). Use &lt;##&gt; or &lt;###&gt; to pad the track number with leading zeroes (&lt;%%&gt; or &lt;%%%&gt; respectively for playlist track order). &lt;ALBUM&gt; inserts the album name in uppercase, &lt;album&gt; in lowercase (likewise for &lt;Artist&gt; and &lt;Title&gt;). &lt;Album?text&gt; inserts 'text' only if the album name is not empty (likewise for &lt;Artist&gt;, &lt;Title&gt;, &lt;#&gt; and &lt;%&gt;).</body></html>");
        jLabel3.setPreferredSize(new java.awt.Dimension(2361, 80));

        jLabel4.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel4.setText(Main.getLocaleString("SEARCH_AUTOCOMPLETE"));

        autocompleteEnabledCheckBox.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        autocompleteEnabledCheckBox.setText(Main.getLocaleString("ENABLED"));

        jLabel5.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel5.setText(Main.getLocaleString("DOWNLOAD_COMPLETED"));

        downloadCompleteComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Do nothing", "Open file", "Open file's directory" }));

        jLabel7.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel7.setText(Main.getLocaleString("LANGUAGE"));

        resetOriginalSettingsButton.setText(Main.getLocaleString("RESET_ORIGINAL_SETTINGS"));
        resetOriginalSettingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetOriginalSettingsButtonActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel8.setText(Main.getLocaleString("FILE_EXISTS"));

        jLabel9.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel9.setText(Main.getLocaleString("PROXY_HOST"));

        jLabel10.setFont(new java.awt.Font("Lucida Grande", 1, 11)); // NOI18N
        jLabel10.setText(Main.getLocaleString("PROXY_PORT"));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(reconnectButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 75, Short.MAX_VALUE)
                        .add(resetOriginalSettingsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 227, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(saveSettingsButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(jLabel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(downloadDirectoryTextField)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(downloadDirectoryButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 48, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, fileNameSchemeTextField)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(downloadCompleteComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(autocompleteEnabledCheckBox)
                                    .add(maxParallelDownloadsSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(fileExistsComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(languageComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(proxyHostTextField)
                                    .add(proxyPortTextField))
                                .add(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(downloadDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(downloadDirectoryButton)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(maxParallelDownloadsSpinner)
                    .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(fileNameSchemeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(autocompleteEnabledCheckBox))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(downloadCompleteComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(15, 15, 15)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(fileExistsComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(languageComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(proxyHostTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel10)
                    .add(proxyPortTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(131, 131, 131)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(reconnectButton)
                    .add(saveSettingsButton)
                    .add(resetOriginalSettingsButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void downloadDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadDirectoryButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(Main.getConfig().getDownloadDirectory()));
        chooser.setDialogTitle("Select Download Directory");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            String downloadDirectory = chooser.getSelectedFile().getPath();
            Main.getConfig().setDownloadDirectory(downloadDirectory);
            downloadDirectoryTextField.setText(downloadDirectory);
        }
    }//GEN-LAST:event_downloadDirectoryButtonActionPerformed

    private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsButtonActionPerformed
        if(saveSettings()) {
            dispose();
        }
    }//GEN-LAST:event_saveSettingsButtonActionPerformed

    private void reconnectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reconnectButtonActionPerformed
        // init grooveshark
        new InitThread().start();
    }//GEN-LAST:event_reconnectButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if(settingsChanged()) {
            if(JOptionPane.showConfirmDialog(this, "You did made changes to the settings. Do you want to save them?", "Save", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
                if(saveSettings()) {
                    dispose();
                }
            } else {
                resetSettings();
                dispose();
            }
        } else {
            dispose();
        }
    }//GEN-LAST:event_formWindowClosing

    private void resetOriginalSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetOriginalSettingsButtonActionPerformed
        Main.getConfig().resetSettings();
        Main.saveConfig();
        resetSettings();
    }//GEN-LAST:event_resetOriginalSettingsButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox autocompleteEnabledCheckBox;
    private javax.swing.JComboBox downloadCompleteComboBox;
    private javax.swing.JButton downloadDirectoryButton;
    private javax.swing.JTextField downloadDirectoryTextField;
    private javax.swing.JComboBox fileExistsComboBox;
    private javax.swing.JTextField fileNameSchemeTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox languageComboBox;
    private javax.swing.JSpinner maxParallelDownloadsSpinner;
    private javax.swing.JTextField proxyHostTextField;
    private javax.swing.JTextField proxyPortTextField;
    private javax.swing.JButton reconnectButton;
    private javax.swing.JButton resetOriginalSettingsButton;
    private javax.swing.JButton saveSettingsButton;
    // End of variables declaration//GEN-END:variables

    public boolean saveSettings() {
        if(checkSettings()) {
            Main.getConfig().setDownloadDirectory(downloadDirectoryTextField.getText());
            Main.getConfig().setMaxParallelDownloads((Integer) (maxParallelDownloadsSpinner.getValue()));
            Main.getConfig().setFileNameScheme(fileNameSchemeTextField.getText());
            Main.getConfig().setAutocompleteEnabled(autocompleteEnabledCheckBox.isSelected());
            Main.getConfig().setDownloadComplete(downloadCompleteComboBox.getSelectedIndex());
            if(originalLanguage != languageComboBox.getSelectedIndex()) {
                String localeString = ((Language)Utils.getByIndex(Main.getLanguages(), languageComboBox.getSelectedIndex())).getLocaleString();
                Main.getConfig().setLocale(localeString);
                Main.resetGui();
            }
            if(!proxyHostTextField.getText().isEmpty() && !proxyPortTextField.getText().isEmpty()) {
                Main.getConfig().setProxyHost(proxyHostTextField.getText());
                try {
                    Main.getConfig().setProxyPort(Integer.parseInt(proxyPortTextField.getText()));
                } catch(NumberFormatException e) {
                    JOptionPane.showMessageDialog(this, "Proxy Port must be numeric.");
                    return false;
                }
            } else {
                Main.getConfig().setProxyHost(null);
                Main.getConfig().setProxyPort(null);
            }
            setOriginalSettings();
            JOptionPane.showMessageDialog(this, "Settings have been successfully saved.");
            return true;
        } else {
            return false;
        }
    }
   
    public boolean settingsChanged() {
        return !originalDownloadDirectory.equals(downloadDirectoryTextField.getText()) || !originalMaxParallelDownloads.equals(maxParallelDownloadsSpinner.getValue().toString()) || !originalFileNameScheme.equals(fileNameSchemeTextField.getText()) || originalAutocompleteEnabled != autocompleteEnabledCheckBox.isSelected() || originalDownloadComplete != downloadCompleteComboBox.getSelectedIndex() || originalLanguage != languageComboBox.getSelectedIndex() && !originalProxyHost.equals(proxyHostTextField.getText()) && !originalProxyPort.equals(proxyPortTextField.getText());
    }
   
    public boolean checkSettings() {
        if(new File(downloadDirectoryTextField.getText()).exists()) {
            return true;
        } else {
            JOptionPane.showMessageDialog(this, "The given download directory does not exist.", "Error", JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }
   
    public JTextField getDownloadDirectoryTextField() {
        return downloadDirectoryTextField;
    }

    public JSpinner getMaxParallelDownloadsSpinner() {
        return maxParallelDownloadsSpinner;
    }

    private void resetSettings() {
        downloadDirectoryTextField.setText(Main.getConfig().getDownloadDirectory());
        maxParallelDownloadsSpinner.setValue(Main.getConfig().getMaxParallelDownloads());
        fileNameSchemeTextField.setText(Main.getConfig().getFileNameScheme());
        autocompleteEnabledCheckBox.setSelected(Main.getConfig().getAutocompleteEnabled());
       
        String[] downloadCompleteActions = Config.DownloadComplete.names();
        DefaultComboBoxModel downloadCompleteComboBoxModel = new DefaultComboBoxModel();
        downloadCompleteComboBox.setModel(downloadCompleteComboBoxModel);
        for(String downloadCompleteAction : downloadCompleteActions) {
            downloadCompleteComboBoxModel.addElement(Main.getLocaleString(downloadCompleteAction));
        }
        downloadCompleteComboBox.setSelectedIndex(Main.getConfig().getDownloadComplete());
       
        String[] fileExistsActions = Config.FileExists.names();
        DefaultComboBoxModel fileExistsComboBoxModel = new DefaultComboBoxModel();
        fileExistsComboBox.setModel(fileExistsComboBoxModel);
        for(String fileExistsAction : fileExistsActions) {
            fileExistsComboBoxModel.addElement(Main.getLocaleString(fileExistsAction));
        }
        fileExistsComboBox.setSelectedIndex(Main.getConfig().getFileExists());
       
        DefaultComboBoxModel languageComboBoxModel = new DefaultComboBoxModel();
        languageComboBox.setModel(languageComboBoxModel);
        for(Language lang : Main.getLanguages().values()) {
            languageComboBoxModel.addElement(lang.getLanguageName());
        }
        languageComboBox.setSelectedIndex(Main.getLanguageIndex());
       
        if(Main.getConfig().getProxyHost() != null && Main.getConfig().getProxyPort() != null) {
            proxyHostTextField.setText(Main.getConfig().getProxyHost());
            proxyPortTextField.setText(Main.getConfig().getProxyPort().toString());
        }
    }

    private void setOriginalSettings() {
        originalDownloadDirectory = downloadDirectoryTextField.getText();
        originalMaxParallelDownloads = maxParallelDownloadsSpinner.getValue().toString();
        originalFileNameScheme = fileNameSchemeTextField.getText();
        originalAutocompleteEnabled = autocompleteEnabledCheckBox.isSelected();
        originalDownloadComplete = downloadCompleteComboBox.getSelectedIndex();
        originalLanguage = languageComboBox.getSelectedIndex();
        originalProxyHost = proxyHostTextField.getText();
        originalProxyPort = proxyPortTextField.getText();
    }

}
TOP

Related Classes of com.groovesquid.gui.Settings

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.