Package clockradio

Source Code of clockradio.SettingsGUINew

package clockradio;

import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author tom
*/
public class SettingsGUINew extends JFrame {
    // Variables declaration

    private static final long serialVersionUID = 2440370646386239199L;
    private JFileChooser soundselect;
    private Settings settings;
    private JPanel alarmPanel;
    private JPanel alarmScheduleTap;
    private JTextField pathTextF;
    private JButton browseForSound;
    private JCheckBox snoozeEnable;
    private JLabel snoozeLabel;
    private JSlider snoozeSlider;
    private JLabel alarmSchedHelpText;
    private JLabel alarmShedTitel;
    private JLabel alarmSoundLabel;
    private JRadioButton alarmScheduleRadioButton;
    private JTextField alarmTimeInputField;
    private JCheckBox binaryCheck;
    private JButton cancelButton;
    private JRadioButton dailyAlarmRadioButton;
    private JCheckBox difEasy;
    private JCheckBox difHard;
    private JCheckBox difNormal;
    private JLabel difficultyTitel;
    private JPanel generalSettingsTap;
    private JLabel generalTitel;
    private JLabel snoozeSetting;
    private JSeparator jSeparator1;
    private JSeparator jSeparator2;
    private JSeparator jSeparator3;
    private JSeparator jSeparator4;
    private JTabbedPane jTabbedPane1;
    private JButton loadButton;
    private JCheckBox mathMultiplyCheck;
    private JCheckBox mathAdditionCheck;
    private JCheckBox mathCheck;
    private JCheckBox mathSubtractionCheck;
    private JCheckBox oddoneoutCheck;
    private JButton saveButton;
    private JButton defaultButton;
    private JCheckBox shapesCheck;
    private JButton showExButton;
    private JPanel taskSettingsPanel;
    private JLabel taskSettingsTitel;
    private ButtonGroup alarmRBGroup;
    private ButtonGroup difficultyGroup;
    private TitledBorder titledBorder;
    private Border loweredetched;
    // End of variables declaration

    /** Creates new form SettingsGUI */
    public SettingsGUINew(Settings settings) {
        this.settings = settings;
        initComponents();
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        soundselect = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Wav Files", "wav");
        soundselect.setFileFilter(filter);
        jTabbedPane1 = new JTabbedPane();
        generalSettingsTap = new JPanel();
        generalTitel = new JLabel();
        alarmSoundLabel = new JLabel();
        jSeparator1 = new JSeparator();
        pathTextF = new JTextField();
        browseForSound = new JButton();
        jSeparator2 = new JSeparator();
        snoozeLabel = new JLabel();
        snoozeSetting = new JLabel();
        snoozeSlider = new JSlider();
            snoozeSlider.setMajorTickSpacing(2);
            snoozeSlider.setMinorTickSpacing(1);
            snoozeSlider.setMaximum(15);
            snoozeSlider.setMinimum(1);
            snoozeSlider.setPaintTicks(true);
            snoozeSlider.setPaintLabels(true);
            snoozeSlider.setSnapToTicks(true);
            if(settings.getSnoozetime()!=-1){
              snoozeSlider.setValue(settings.getSnoozetime());
            }
        snoozeEnable = new JCheckBox();
        snoozeSetting.setText(new Integer(snoozeSlider.getValue()) + " minutes");
        jSeparator3 = new JSeparator();
        alarmPanel = new JPanel();
        dailyAlarmRadioButton = new JRadioButton();
        alarmScheduleRadioButton = new JRadioButton();
        alarmTimeInputField = new JTextField();
        alarmSchedHelpText = new JLabel();
        taskSettingsPanel = new JPanel();
        mathCheck = new JCheckBox();
        taskSettingsTitel = new JLabel();
        mathMultiplyCheck = new JCheckBox();
        mathSubtractionCheck = new JCheckBox();
        mathAdditionCheck = new JCheckBox();
        binaryCheck = new JCheckBox();
        shapesCheck = new JCheckBox();
        oddoneoutCheck = new JCheckBox();
        showExButton = new JButton();
        jSeparator4 = new JSeparator();
        difficultyTitel = new JLabel();
        difEasy = new JCheckBox();
        difNormal = new JCheckBox();
        difHard = new JCheckBox();
        loadButton = new JButton();
        cancelButton = new JButton();
        saveButton = new JButton();
        defaultButton = new JButton();
        alarmScheduleTap = new JPanel();
        alarmShedTitel = new JLabel();
        loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);

        // setDefaultCloseOperation(Settings.saveToFile(settings, null));

        generalTitel.setText("General Settings");
        alarmSoundLabel.setText("Alarm Sound:");
        if(settings.getSoundpath()!=null){
          pathTextF.setText(settings.getSoundpath());
        }else{
          pathTextF.setText("Select path to sound-file");
        }
        browseForSound.setText("Browse");
        browseForSound.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseForSoundActionPerformed(evt);
            }
        });

        snoozeLabel.setText("Snooze time:");

        snoozeEnable.setText("Enable snooze");
        if(settings.getSnoozeState()!=null){
        snoozeEnable.setSelected(settings.getSnoozeState())
        }else{
        snoozeEnable.setSelected(true);
        }
       
        dailyAlarmRadioButton.setText("Daily alarm");

        alarmScheduleRadioButton.setText("Use alarm schedule");

        // Set which alarmtype is chosen from settings
        if(settings.getAlarmState()==1)
            dailyAlarmRadioButton.setSelected(true);
        else
            alarmScheduleRadioButton.setSelected(true);

        alarmRBGroup = new ButtonGroup();
            alarmRBGroup.add(dailyAlarmRadioButton);
            alarmRBGroup.add(alarmScheduleRadioButton);

        dailyAlarmRadioButton.addItemListener(new ItemListener()  {

            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                alarmStateChanged(evt);
            }
        });

        alarmScheduleRadioButton.addItemListener(new ItemListener()  {

            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                alarmStateChanged(evt);
            }
        });

        if(settings.getAlarmTime()!=null){
          alarmTimeInputField.setText(settings.getAlarmTime());
        }else{
          alarmTimeInputField.setText("HH:mm")
        }

        if(settings.getAlarmState()==2) {
            alarmTimeInputField.setEnabled(false);
        } else {
            alarmTimeInputField.setEnabled(true);
        }
        alarmSchedHelpText.setText("To set the alarm schedule, please click on the tap in the top of the window");

        GroupLayout AlarmPanelLayout = new GroupLayout(alarmPanel);
        alarmPanel.setLayout(AlarmPanelLayout);
        titledBorder = BorderFactory.createTitledBorder(loweredetched, "Alarm Settings");
        alarmPanel.setBorder(titledBorder);
        AlarmPanelLayout.setHorizontalGroup(
                AlarmPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(AlarmPanelLayout.createSequentialGroup().addContainerGap().addGroup(AlarmPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(AlarmPanelLayout.createSequentialGroup().
                addComponent(dailyAlarmRadioButton).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).
                addComponent(alarmScheduleRadioButton)).
                addComponent(alarmSchedHelpText).addGroup(AlarmPanelLayout.createSequentialGroup().
                addComponent(alarmTimeInputField, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        AlarmPanelLayout.setVerticalGroup(
                AlarmPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(AlarmPanelLayout.createSequentialGroup().addContainerGap().addGroup(AlarmPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(dailyAlarmRadioButton).
                addComponent(alarmScheduleRadioButton)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(AlarmPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(alarmTimeInputField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE).
                addComponent(alarmSchedHelpText).addContainerGap()));

        mathCheck.setText("Math");
        mathCheck.addItemListener(new ItemListener()  {

            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                taskBoxesStateChanged(evt);
            }
        });

        taskSettingsTitel.setText("Choose which tasks to use");

        mathMultiplyCheck.setText("Multiply");
    
        mathSubtractionCheck.setText("Subtraction");

        mathAdditionCheck.setText("Addition");

        binaryCheck.setText("Binary");
        if(settings.getTaskSettings().getBin()){
          binaryCheck.setSelected(true);
        }
        shapesCheck.setText("Shapes");
        if(settings.getTaskSettings().getShapes()){
          shapesCheck.setSelected(true);
        }
        oddoneoutCheck.setText("OddOneOut");
        if(settings.getTaskSettings().getOdd()){
          oddoneoutCheck.setSelected(true);
        }
        if(settings.getTaskSettings().isMat()){
          mathCheck.setSelected(true);
        }
        if(settings.getTaskSettings().getMath()[0]==1){
          mathAdditionCheck.setSelected(true);
        }
        if(settings.getTaskSettings().getMath()[1]==1){
          mathSubtractionCheck.setSelected(true);
        }
        if(settings.getTaskSettings().getMath()[2]==1){
          mathMultiplyCheck.setSelected(true);
        }
        if(!mathCheck.isSelected()){
            mathAdditionCheck.setEnabled(false);
            mathMultiplyCheck.setEnabled(false);
            mathSubtractionCheck.setEnabled(false);
        }

        showExButton.setText("Show Examples");

        difficultyTitel.setText("Difficulty");

        difEasy.setText("Kiddie");

        difNormal.setText("Normal");

        difHard.setText("You're NEVER turning this off");
        if(settings.getTaskSettings().getDifficulty()==1){
        difEasy.setSelected(true)
        }else if(settings.getTaskSettings().getDifficulty()==2){
          difNormal.setSelected(true)
        }else{
          difHard.setSelected(true);
        }
        difficultyGroup = new ButtonGroup();
        difficultyGroup.add(difEasy);
        difficultyGroup.add(difNormal);
        difficultyGroup.add(difHard);

        GroupLayout taskSettingsPanelLayout = new GroupLayout(taskSettingsPanel);
        taskSettingsPanel.setLayout(taskSettingsPanelLayout);
        titledBorder = BorderFactory.createTitledBorder(loweredetched, "Task settings");
        taskSettingsPanel.setBorder(titledBorder);
        taskSettingsPanelLayout.setHorizontalGroup(
                taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(taskSettingsPanelLayout.createSequentialGroup().addContainerGap().addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(taskSettingsPanelLayout.createSequentialGroup().
                addComponent(difEasy).addGap(18, 18, 18).
                addComponent(difNormal).addGap(18, 18, 18).
                addComponent(difHard)).
                addComponent(taskSettingsTitel).addGroup(taskSettingsPanelLayout.createSequentialGroup().addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(mathCheck).addGroup(taskSettingsPanelLayout.createSequentialGroup().addGap(21, 21, 21).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(mathAdditionCheck).
                addComponent(mathMultiplyCheck).
                addComponent(mathSubtractionCheck)))).addGap(96, 96, 96).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(showExButton).
                addComponent(oddoneoutCheck).
                addComponent(shapesCheck).
                addComponent(binaryCheck))).addGroup(GroupLayout.Alignment.TRAILING, taskSettingsPanelLayout.createSequentialGroup().
                addComponent(difficultyTitel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(jSeparator4, GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE))).addContainerGap()));
        taskSettingsPanelLayout.setVerticalGroup(
                taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(taskSettingsPanelLayout.createSequentialGroup().
                addComponent(taskSettingsTitel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(mathCheck).
                addComponent(binaryCheck)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(mathMultiplyCheck).
                addComponent(shapesCheck)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(mathAdditionCheck).
                addComponent(oddoneoutCheck)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(mathSubtractionCheck).
                addComponent(showExButton)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(jSeparator4, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).
                addComponent(difficultyTitel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(taskSettingsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(difEasy).
                addComponent(difNormal).
                addComponent(difHard)).addGap(15, 15, 15)));

        loadButton.setText("Load");

        cancelButton.setText("Cancel");

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        defaultButton.setText("Default");
        defaultButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultButtonActionPerformed(evt);
            }
        });

        snoozeSlider.addChangeListener(new javax.swing.event.ChangeListener() {

            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                snoozeSliderStateChanged(evt);
            }
        });


        GroupLayout generalSettingsTapLayout = new GroupLayout(generalSettingsTap);
        generalSettingsTap.setLayout(generalSettingsTapLayout);
        generalSettingsTapLayout.setHorizontalGroup(
                generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(generalSettingsTapLayout.createSequentialGroup().addContainerGap().addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(alarmPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).
                addComponent(jSeparator2, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE).
                addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE).
                addComponent(generalTitel).addGroup(generalSettingsTapLayout.createSequentialGroup().
                addComponent(alarmSoundLabel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(pathTextF, GroupLayout.PREFERRED_SIZE, 228, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(browseForSound)).
                addComponent(snoozeEnable).addGroup(generalSettingsTapLayout.createSequentialGroup().
                addComponent(snoozeLabel).addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(generalSettingsTapLayout.createSequentialGroup().addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).
                addComponent(snoozeSlider, GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE)).addGroup(GroupLayout.Alignment.TRAILING, generalSettingsTapLayout.createSequentialGroup().addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 261, Short.MAX_VALUE).
                addComponent(snoozeSetting).addGap(29, 29, 29)))).
                addComponent(jSeparator3, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE).
                addComponent(taskSettingsPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(GroupLayout.Alignment.TRAILING, generalSettingsTapLayout.createSequentialGroup().
                addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(loadButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(defaultButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(cancelButton))).addContainerGap()));
        generalSettingsTapLayout.setVerticalGroup(
                generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(generalSettingsTapLayout.createSequentialGroup().addContainerGap().
                addComponent(generalTitel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addGap(3, 3, 3).addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(alarmSoundLabel).
                addComponent(pathTextF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).
                addComponent(browseForSound)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(jSeparator2, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(snoozeEnable).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(snoozeLabel).
                addComponent(snoozeSetting)).
                addComponent(snoozeSlider, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).
                addComponent(jSeparator3, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).
                addComponent(alarmPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).
                addComponent(taskSettingsPanel, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(generalSettingsTapLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).
                addComponent(cancelButton).
                addComponent(defaultButton).
                addComponent(loadButton).
                addComponent(saveButton)).addContainerGap(13, Short.MAX_VALUE)));

        jTabbedPane1.addTab("General Settings", generalSettingsTap);

        alarmShedTitel.setText("Alarm Schedule");

//        GroupLayout alarmScheduleTapLayout = new GroupLayout(alarmScheduleTap);
//        alarmScheduleTap.setLayout(alarmScheduleTapLayout);
//        alarmScheduleTapLayout.setHorizontalGroup(
//                alarmScheduleTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(alarmScheduleTapLayout.createSequentialGroup().addContainerGap().
//                addComponent(alarmShedTitel).addContainerGap(313, Short.MAX_VALUE)));
//        alarmScheduleTapLayout.setVerticalGroup(
//                alarmScheduleTapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(alarmScheduleTapLayout.createSequentialGroup().addContainerGap().
//                addComponent(alarmShedTitel).addContainerGap(487, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Alarm Schedule", new Schedule());

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING).
                addComponent(jTabbedPane1, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
        layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().
                addComponent(jTabbedPane1, GroupLayout.PREFERRED_SIZE, 645, GroupLayout.PREFERRED_SIZE).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
                                     // Set size of window here        ^^^
        pack();
    }// </editor-fold>

    private void showExActionPerformed(ActionEvent evt) {
        // TODO SHOW WINDOW WITH TASK EXAMPLES
    }

    private void saveButtonActionPerformed(ActionEvent evt) {
        System.out.println("Snooze: "+getSnoozeOn()+". Snoozetime: "+getSnoozeTime()+" minutes");
        System.out.println("Soundfile: "+getSoundFilePath());
        System.out.println("Alarmtype chosen: " + getAlarmState());
        System.out.println("Alarmtid: "+getAlarmTime());
        System.out.println("Tasks chosen: " + getTasks());
        System.out.println("Difficulty: " + getDifficulty());
       
        new File(getSoundFilePath());
        settings.setSoundpath(getSoundFilePath());
       
        settings.setAlarmState(getAlarmState());
//        if (getAlarmTime.)
        settings.setAlarmTime(getAlarmTime());
        settings.setSnoozeState(getSnoozeOn());
        settings.setSnoozetime(getSnoozeTime());
        settings.getTaskSettings().setMat(mathCheck.isSelected());
        int[] math = new int[3]; math[0]=0;math[1]=0;math[2]=0;
        if(mathAdditionCheck.isSelected()){
          math[0]=1;
        }
        if(mathSubtractionCheck.isSelected()){
          math[1]=1;
        }
       
        if(mathMultiplyCheck.isSelected()){
          math[2]=1;
        }
        settings.getTaskSettings().setOdd(oddoneoutCheck.isSelected());
        settings.getTaskSettings().setShapes(shapesCheck.isSelected());
        settings.getTaskSettings().setBin(binaryCheck.isSelected());
        settings.getTaskSettings().setMath(math);
        if(difEasy.isSelected()){
            settings.getTaskSettings().setDifficulty(1);
        }else if(difNormal.isSelected()){
            settings.getTaskSettings().setDifficulty(2);
        }else{
            settings.getTaskSettings().setDifficulty(3);
        }
        Settings.saveToFile(settings, "C:\\sound\\settings.set");
    }

    private void loadButtonActionPerformed(ActionEvent evt) {
        //TODO add popup to select a diffrent settingsfile
        loadSettings();
    }

    private void cancelButtonActionPerformed(ActionEvent evt) {
        // TODO INSERT CODE HERE!!!
    }

    private void defaultButtonActionPerformed(ActionEvent evt) {
        settings.setDefaultSettings();
        loadSettings();
    }

    private void snoozeSliderStateChanged(ChangeEvent e) {
        snoozeSetting.setText(new Integer(snoozeSlider.getValue()) + " minutes");
    }

    private void browseForSoundActionPerformed(ActionEvent evt) {
        int returnVal = soundselect.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            pathTextF.setText(soundselect.getSelectedFile().getAbsolutePath());

        }
    }

    /** Listens to the task select check boxes. */
    public void taskBoxesStateChanged(ItemEvent e) {
//        int index = 0;
//        Object source = e.getItemSelectable();
//
//        if (source == mathCheck) {
//            index = 0;
//        } else if (source == mathAdditionCheck) {
//            index = 1;
//        } else if (source == mathMultiplyCheck) {
//            index = 2;
//        } else if (source == mathSubtractionCheck) {
//            index = 3;
//        } else if (source == oddoneoutCheck) {
//            index = 4;
//        } else if (source == binaryCheck) {
//            index = 5;
//        } else if (source == shapesCheck) {
//            index = 6;
//        }

        //Now that we know which button was pushed, find out
        //whether it was selected or deselected.
        if (e.getStateChange() == ItemEvent.DESELECTED) {
            // Do something if it's unchecked
        }

        if (e.getStateChange() == ItemEvent.SELECTED){
            mathAdditionCheck.setEnabled(true);
            mathMultiplyCheck.setEnabled(true);
            mathSubtractionCheck.setEnabled(true);
        } else if(e.getStateChange() == ItemEvent.DESELECTED){
            mathAdditionCheck.setEnabled(false);
            mathMultiplyCheck.setEnabled(false);
            mathSubtractionCheck.setEnabled(false);
        }
    }

    /** Listens to the task select check boxes. */
    public void alarmStateChanged(ItemEvent e) {

        Object source = e.getItemSelectable();

        if (source == alarmScheduleRadioButton) {
            alarmTimeInputField.setEnabled(false);
        } else if (source == dailyAlarmRadioButton) {
            alarmTimeInputField.setEnabled(true);
        }
    }

    /**
     * Returns whether snooze is on or not
     * @return boolean
     */
    public boolean getSnoozeOn() {
        return snoozeEnable.isSelected();
    }

    /**
     * Returns the time set for snooze on the slider
     * @return int
     */
    public int getSnoozeTime() {
        return snoozeSlider.getValue();
    }

    /**
     * Returns the path to the selected soundfile from the textField
     * @return String
     */
    public String getSoundFilePath() {
        return pathTextF.getText();
    }

    /**
     * Returns whether the alarm is set to daily alarm or should
     * work on a schedule
     * @return int. 1 = Daily alarm, 2 = Alarm schedule. Returns a 0 if none of them is selected.
     */
    public int getAlarmState() {
        if(dailyAlarmRadioButton.isSelected())
            return 1;
        else if(alarmScheduleRadioButton.isSelected())
            return 2;
        else
            return 0;
    }

    public String getAlarmTime() {
        return alarmTimeInputField.getText();
    }

    public int[] getTasks() {
        int[] taskList = new int[6];
        for(int i=0;i<5;i++) {
            taskList[i] =0;
        }
        if (mathMultiplyCheck.isSelected())
            taskList[0] = 1;
        if (mathAdditionCheck.isSelected())
            taskList[1] = 1;
        if (mathSubtractionCheck.isSelected())
            taskList[2] = 1;
        if (binaryCheck.isSelected())
            taskList[3] = 1;
        if (oddoneoutCheck.isSelected())
            taskList[4] = 1;
        if (shapesCheck.isSelected())
            taskList[5] = 1;
        return taskList;
    }

    public int getDifficulty() {
        int diff=2;
        if(difEasy.isSelected())
            diff=1;
        if(difNormal.isSelected())
            diff=2;
        if(difHard.isSelected())
            diff=3;
        return diff;
    }

    public void loadSettings(){
        pathTextF.setText(settings.getSoundpath());
        snoozeSlider.setValue(settings.getSnoozetime());
        snoozeEnable.setSelected(settings.getSnoozeState());
        if(settings.getAlarmState()==1)
            dailyAlarmRadioButton.setSelected(true);
        else
            alarmScheduleRadioButton.setSelected(true);
        alarmTimeInputField.setText(settings.getAlarmTime());
        if(settings.getAlarmState()==2) {
            alarmTimeInputField.setEnabled(false);
        } else {
            alarmTimeInputField.setEnabled(true);
        }
        mathCheck.setSelected(settings.getTaskSettings().isMat());
        if(settings.getTaskSettings().getMath()[0]==1){
            mathAdditionCheck.setSelected(true);
        }else{
            mathAdditionCheck.setSelected(false);
        }
        if(settings.getTaskSettings().getMath()[1]==1){
            mathSubtractionCheck.setSelected(true);
        }else{
            mathSubtractionCheck.setSelected(false);
        }
        if(settings.getTaskSettings().getMath()[2]==1){
            mathMultiplyCheck.setSelected(true);
        }else{
            mathMultiplyCheck.setSelected(false);
        }
        binaryCheck.setSelected(settings.getTaskSettings().getBin());
        shapesCheck.setSelected(settings.getTaskSettings().getShapes());
        oddoneoutCheck.setSelected(settings.getTaskSettings().getOdd());
        if(settings.getTaskSettings().getDifficulty()==1){
            difEasy.setSelected(true);
        }
        else if(settings.getTaskSettings().getDifficulty()==2){
            difNormal.setSelected(true);
        }
        else {
            difHard.setSelected(true);
        }
    }
}
TOP

Related Classes of clockradio.SettingsGUINew

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.