/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.lister; import org.pegadi.swing.AbstractPreferencesDialog; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; import java.util.Properties; import java.util.ResourceBundle; class PrefsDialog extends AbstractPreferencesDialog { /** * UI strings. */ protected ResourceBundle str; protected JRadioButton lastRadio; protected JRadioButton defaultRadio; protected ButtonGroup selectionGroup; /** * Create a new dialog with parent and preferences set. */ public PrefsDialog(JFrame parent, Properties preferences) { super(parent, preferences); } /** * Creates the main pane of the dialog. */ protected Component createPreferencesPane() { str = ResourceBundle.getBundle("org.pegadi.lister.PrefsDialogStrings"); Box pane = new Box(BoxLayout.Y_AXIS); Border b; JPanel selectionPane = new JPanel(); selectionPane.setLayout(new BoxLayout(selectionPane, BoxLayout.Y_AXIS)); ButtonGroup selectionGroup = new ButtonGroup(); b = BorderFactory.createTitledBorder(str.getString("selection_title")); selectionPane.setBorder(b); lastRadio = new JRadioButton(str.getString("selection_last")); selectionGroup.add(lastRadio); selectionPane.add(lastRadio); defaultRadio = new JRadioButton(str.getString("selection_default")); selectionGroup.add(defaultRadio); selectionPane.add(defaultRadio); pane.add(selectionPane); /****************************************************************** JPanel scorePanel = new JPanel(new GridBagLayout()); b = BorderFactory.createTitledBorder(str.getString("score_title")); scorePanel.setBorder(b); scoreCheck = new JCheckBox(str.getString("score_label")); scorePanel.add(scoreCheck, new GridBagConstraints2(0, 0, 2, 1, 1.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); scorePanel.add(new JLabel(str.getString("score_hi_label")), new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); topScoreField = new JTextField(4); scorePanel.add(topScoreField, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); scorePanel.add(new JLabel(str.getString("score_day_label")), new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); dayScoreField = new JTextField(4); scorePanel.add(dayScoreField, new GridBagConstraints2(1, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); scorePanel.add(new JLabel(str.getString("score_pers_label")), new GridBagConstraints2(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); personalScoreField = new JTextField(4); scorePanel.add(personalScoreField, new GridBagConstraints2(1, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); pane.add(scorePanel); *****************************************************************/ return pane; } /** * Set preferences controls according to this <code>Properties</code>. */ public void setPreferences(Properties preferences) { prefs = preferences; if (prefs.getProperty(Lister.PREFS_SEL_REMEMBER).equals("true")) { lastRadio.setSelected(true); } else { defaultRadio.setSelected(true); } } /** * Called when "OK" is pressed to determine which preferences are changed. * All changed preferences will be placed in <code>changedPrefs</code>, which * prior to this call will be <code>null</code>. */ protected void findChangedPreferences() { changedPrefs = new Properties(); if (prefs.getProperty(Lister.PREFS_SEL_REMEMBER).equals("true")) { if (defaultRadio.isSelected()) { changedPrefs.put(Lister.PREFS_SEL_REMEMBER, "false"); } } else { if (lastRadio.isSelected()) { changedPrefs.put(Lister.PREFS_SEL_REMEMBER, "true"); } } } }