20 package net.sf.gridarta.gui.dialog.prefs;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.GridBagLayout;
25 import java.util.Arrays;
26 import java.util.Comparator;
27 import java.util.Locale;
28 import java.util.prefs.Preferences;
29 import javax.swing.AbstractButton;
30 import javax.swing.Box;
31 import javax.swing.JCheckBox;
32 import javax.swing.JComboBox;
33 import javax.swing.JComponent;
34 import javax.swing.JPanel;
35 import javax.swing.border.Border;
36 import javax.swing.border.CompoundBorder;
37 import javax.swing.border.TitledBorder;
43 import net.
sf.japi.swing.action.ActionBuilder;
44 import net.
sf.japi.swing.action.ActionBuilderFactory;
45 import net.
sf.japi.swing.misc.LocaleListCellRenderer;
46 import net.
sf.japi.swing.prefs.AbstractPrefs;
47 import net.
sf.japi.util.LocaleComparator;
48 import org.jetbrains.annotations.NotNull;
71 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
113 private final Comparator<Locale>
comp =
new LocaleComparator();
123 setListLabelIcon(ACTION_BUILDER.getIcon(
"prefsGUI.icon"));
127 add(Box.createVerticalGlue());
142 final Locale loc = (Locale) localeBox.getSelectedItem();
144 PREFERENCES.put(PREFERENCES_LANGUAGE, loc.getLanguage());
146 PREFERENCES.remove(PREFERENCES_LANGUAGE);
153 final String current = PREFERENCES.get(PREFERENCES_LANGUAGE, null);
154 localeBox.setSelectedIndex(Arrays.binarySearch(locales, current != null ?
new Locale(current) : null, comp));
160 localeBox.setSelectedIndex(Arrays.binarySearch(locales, null, comp));
166 final Locale loc = (Locale) localeBox.getSelectedItem();
167 final String currentName = PREFERENCES.get(PREFERENCES_LANGUAGE, null);
168 final Locale current = currentName != null ?
new Locale(currentName) : null;
169 return !((loc == null ? current == null : loc.equals(current)) && showMainToolbar.isSelected() == editorSettings.
isShowMainToolbar());
178 final Container lineLayout = Box.createHorizontalBox();
180 final CharSequence availableLocales = ACTION_BUILDER.getString(
"availableLocales");
182 locales =
new Locale[locNames.length + 1];
184 for (
int i = 0; i < locNames.length; i++) {
185 locales[i + 1] =
new Locale(locNames[i]);
187 Arrays.sort(locales, comp);
191 localeBox =
new JComboBox<>(
locales);
192 localeBox.setRenderer(
new LocaleListCellRenderer());
194 final String current = PREFERENCES.get(PREFERENCES_LANGUAGE, null);
195 localeBox.setSelectedIndex(Arrays.binarySearch(locales, current != null ?
new Locale(current) : null, comp));
197 lineLayout.add(localeBox);
207 final JComponent panel =
new JPanel(
new GridBagLayout());
222 final JComponent panel =
new JPanel(
new GridBagLayout());
226 showMainToolbar =
new JCheckBox(ACTION_BUILDER.createAction(
false,
"optionsShowMainToolbar"));
static final Preferences PREFERENCES
Preferences.
static final String PREFERENCES_LANGUAGE
Preferences key for language.
Utility class for string manipulation.
static Border createTitledBorder(@NotNull final String titleKey)
Creates a titled border.
Graphical User Interface of Gridarta.
AbstractButton showMainToolbar
Whether to show the main window's toolbar.
final EditorSettings editorSettings
The EditorSettings to use.
void addComponent(@NotNull final Component component)
Adds a component to the container.
static final long serialVersionUID
The serial version UID.
Locale [] locales
Locale[].
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
boolean SHOW_MAIN_TOOLBAR_DEFAULT
Default value for whether the main window's toolbar is shown.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Interface used as preferences location.
boolean isShowMainToolbar()
Returns whether the main toolbar should be shown.
Helper class for preference panes.
GUIPreferences(@NotNull final EditorSettings editorSettings)
Creates a new instance.
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
Utility class for ActionBuilder related functions.
Component buildLocaleBox()
Constructs the combo box for the selection of locales.
final Comparator< Locale > comp
LocaleComparator.
Component createLayoutPanel()
Creates the sub-panel with the layout settings.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static final String [] EMPTY_STRING_ARRAY
An empty.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
JComboBox< Locale > localeBox
/** ComboBox for choosing the locale.
Settings that apply to the editor.
void setShowMainToolbar(boolean selected)
Sets whether the main toolbar should be shown.
Component createGlobalPanel()
Creates the sub-panel with the editor settings.
Defines common UI constants used in different dialogs.
Preferences Module for user interface preferences.