/** * 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. */ /** * Dialog for preferences. * * @author HÃ¥vard Wigtil <havardw at pvv.org> */ package org.pegadi.client; import org.pegadi.swing.AbstractPreferencesDialog; import javax.swing.*; import java.awt.*; import java.util.Properties; import java.util.ResourceBundle; public class PreferencesDialog extends AbstractPreferencesDialog { /** * UI strings. */ protected ResourceBundle strings; /** * Array of available languages. */ protected String[] languages; /** * Array of available Look&Feels. */ protected String[] themes; /** * Combo box for choosing locale. */ protected JComboBox localeCombo; /** * Combo box for choosing Look&Feel. */ protected JComboBox themeCombo; /** * Cretes a new dialog. This implementation only calls the super * constructor. */ public PreferencesDialog(JFrame parent, Properties preferences) { super(parent, preferences); } /** * This method will be called to create the body of the dialog, * the part added above the buttons. * * @return The component that will be added. */ protected Component createPreferencesPane() { strings = ResourceBundle.getBundle("org.pegadi.client.PreferencesDialogStrings"); languages = new String[4]; languages[0] = strings.getString("locale_english"); languages[1] = strings.getString("locale_bokmaal"); languages[2] = strings.getString("locale_nynorsk"); languages[3] = strings.getString("locale_le"); themes = new String[3]; themes[0] = strings.getString("theme_system"); themes[1] = strings.getString("theme_swing"); themes[2] = strings.getString("theme_gtk"); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); panel.add(new JLabel(strings.getString("locale_label")), c); c.gridy = 1; //feature disable //panel.add(new JLabel(strings.getString("theme_label")), c); c.gridx = 1; c.gridy = 0; c.fill = GridBagConstraints.HORIZONTAL; localeCombo = new JComboBox(languages); panel.add(localeCombo, c); c.gridy = 1; themeCombo = new JComboBox(themes); //feature disabled //panel.add(themeCombo, c); return panel; } /** * Set preferences controls according to this <code>Properties</code>. * The <code>Properties</code> object will also be set as the new * <code>prefs</code> variable. */ public void setPreferences(Properties preferences) { prefs = preferences; String locale = prefs.getProperty("Locale", ""); if (locale.equals("en")) { localeCombo.setSelectedIndex(0); } else if (locale.equals("no_NO")) { localeCombo.setSelectedIndex(1); } else if (locale.equals("no_NO_NY")) { localeCombo.setSelectedIndex(2); } else if (locale.equals("le")) { localeCombo.setSelectedIndex(3); } String theme = prefs.getProperty("Theme", ""); if (theme.equals("system")) { themeCombo.setSelectedIndex(0); } else if (theme.equals("swing")) { themeCombo.setSelectedIndex(1); } else if (theme.equals("gtk")) { themeCombo.setSelectedIndex(2); } } /** * 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(); String oldLocale = prefs.getProperty("Locale", ""); String newLocale = null; int localeIndex = localeCombo.getSelectedIndex(); switch (localeIndex) { case 0: newLocale = "en"; break; case 1: newLocale = "no_NO"; break; case 2: newLocale = "no_NO_NY"; break; case 3: newLocale = "le"; break; } if (!oldLocale.equals(newLocale)) { changedPrefs.put("Locale", newLocale); } String oldTheme = prefs.getProperty("Theme", ""); String newTheme; if (themeCombo.getSelectedIndex() == 0) { newTheme = "system"; } else if (themeCombo.getSelectedIndex() == 1) { newTheme = "swing"; } else { newTheme = "gtk"; } if (!oldTheme.equals(newTheme)) { changedPrefs.put("Theme", newTheme); } } }