package org.matveev.pomodoro4nb.prefs;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import static org.matveev.pomodoro4nb.prefs.DefaultPreferencesProvider.*;
/**
*
* @author Alexey Matveev
*/
public class PreferencesDialog extends javax.swing.JPanel {
private final PreferencesProvider provider;
/** Creates new form PreferencesDialog */
public PreferencesDialog(PreferencesProvider provider) {
this.provider = provider;
initComponents();
updateComponentsWithPrefs();
}
public static void createPreferencesDialog(PreferencesProvider provider) {
PreferencesDialog dialog = new PreferencesDialog(provider);
NotifyDescriptor descriptor = new NotifyDescriptor(
dialog,
NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.title"),
NotifyDescriptor.OK_CANCEL_OPTION,
NotifyDescriptor.PLAIN_MESSAGE,
null,
NotifyDescriptor.OK_OPTION);
if (DialogDisplayer.getDefault().notify(descriptor) == NotifyDescriptor.OK_OPTION) {
dialog.updatePreferences();
}
}
private void updateComponentsWithPrefs() {
pomodoroLengthSpinner.setValue(provider.getInteger(POMODORO_LENGTH_KEY,
DefaultPreferencesProvider.DEFAULT_POMODORO_LENGTH));
shortBreakLengthSpinner.setValue(provider.getInteger(SHORT_BREAK_LENGTH_KEY,
DefaultPreferencesProvider.DEFAULT_SHORT_BREAK_LENGTH));
longBreakLengthSpinner.setValue(provider.getInteger(LONG_BREAK_LENGTH_KEY,
DefaultPreferencesProvider.DEFAULT_LONG_BREAK_LENGTH));
longBreakIntervalSpinner.setValue(provider.getInteger(LONG_BREAK_INTERVAL_KEY,
DefaultPreferencesProvider.DEFAULT_LONG_BREAK_INTERVAL));
enableSoundCheckBox.setSelected(provider.getBoolean(ENABLE_SOUNDS_KEY, true));
}
protected void updatePreferences() {
provider.setInteger(POMODORO_LENGTH_KEY, (Integer) pomodoroLengthSpinner.getValue());
provider.setInteger(SHORT_BREAK_LENGTH_KEY, (Integer) shortBreakLengthSpinner.getValue());
provider.setInteger(LONG_BREAK_LENGTH_KEY, (Integer) longBreakLengthSpinner.getValue());
provider.setInteger(LONG_BREAK_INTERVAL_KEY, (Integer) longBreakIntervalSpinner.getValue());
provider.setBoolean(ENABLE_SOUNDS_KEY, enableSoundCheckBox.isSelected());
}
/** 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;
timingOuterPanel = new javax.swing.JPanel();
timingInnerPanel = new javax.swing.JPanel();
pomodoroLengthLabel = new javax.swing.JLabel();
shortBreakLabel = new javax.swing.JLabel();
longBreakLabel = new javax.swing.JLabel();
longBreakInterval = new javax.swing.JLabel();
pomodoroLengthSpinner = new javax.swing.JSpinner();
shortBreakLengthSpinner = new javax.swing.JSpinner();
longBreakLengthSpinner = new javax.swing.JSpinner();
longBreakIntervalSpinner = new javax.swing.JSpinner();
soundPanel = new javax.swing.JPanel();
enableSoundCheckBox = new javax.swing.JCheckBox();
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
setLayout(new java.awt.GridBagLayout());
timingOuterPanel.setLayout(new java.awt.GridBagLayout());
timingInnerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.timingInnerPanel.border.title"))); // NOI18N
timingInnerPanel.setLayout(new java.awt.GridBagLayout());
pomodoroLengthLabel.setText(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.pomodoroLengthLabel.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(pomodoroLengthLabel, gridBagConstraints);
shortBreakLabel.setText(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.shortBreakLabel.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(shortBreakLabel, gridBagConstraints);
longBreakLabel.setText(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.longBreakLabel.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(longBreakLabel, gridBagConstraints);
longBreakInterval.setText(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.longBreakInterval.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(longBreakInterval, gridBagConstraints);
pomodoroLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 60, 1));
pomodoroLengthSpinner.setPreferredSize(new java.awt.Dimension(50, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(pomodoroLengthSpinner, gridBagConstraints);
shortBreakLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 60, 1));
shortBreakLengthSpinner.setPreferredSize(new java.awt.Dimension(50, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(shortBreakLengthSpinner, gridBagConstraints);
longBreakLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 60, 1));
longBreakLengthSpinner.setPreferredSize(new java.awt.Dimension(50, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(longBreakLengthSpinner, gridBagConstraints);
longBreakIntervalSpinner.setModel(new javax.swing.SpinnerNumberModel(4, 4, 10, 1));
longBreakIntervalSpinner.setPreferredSize(new java.awt.Dimension(50, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
timingInnerPanel.add(longBreakIntervalSpinner, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
gridBagConstraints.weighty = 1.0;
timingOuterPanel.add(timingInnerPanel, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(timingOuterPanel, gridBagConstraints);
soundPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.soundPanel.border.title"))); // NOI18N
soundPanel.setLayout(new java.awt.GridBagLayout());
enableSoundCheckBox.setText(org.openide.util.NbBundle.getMessage(PreferencesDialog.class, "PreferencesDialog.enableSoundCheckBox.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.weighty = 1.0;
soundPanel.add(enableSoundCheckBox, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
add(soundPanel, gridBagConstraints);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox enableSoundCheckBox;
private javax.swing.JLabel longBreakInterval;
private javax.swing.JSpinner longBreakIntervalSpinner;
private javax.swing.JLabel longBreakLabel;
private javax.swing.JSpinner longBreakLengthSpinner;
private javax.swing.JLabel pomodoroLengthLabel;
private javax.swing.JSpinner pomodoroLengthSpinner;
private javax.swing.JLabel shortBreakLabel;
private javax.swing.JSpinner shortBreakLengthSpinner;
private javax.swing.JPanel soundPanel;
private javax.swing.JPanel timingInnerPanel;
private javax.swing.JPanel timingOuterPanel;
// End of variables declaration//GEN-END:variables
}