20 package net.sf.gridarta.gui.dialog.prefs;
22 import java.awt.Component;
23 import java.awt.GridBagLayout;
24 import java.awt.event.ItemEvent;
25 import java.awt.event.ItemListener;
27 import java.util.Arrays;
28 import javax.swing.Box;
29 import javax.swing.JComboBox;
30 import javax.swing.JComponent;
31 import javax.swing.JFileChooser;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.border.Border;
35 import javax.swing.border.CompoundBorder;
36 import javax.swing.border.TitledBorder;
45 import net.
sf.japi.swing.action.ActionBuilder;
46 import net.
sf.japi.swing.action.ActionBuilderFactory;
47 import net.
sf.japi.swing.prefs.AbstractPrefs;
48 import net.
sf.japi.util.Arrays2;
49 import org.jetbrains.annotations.NotNull;
50 import org.jetbrains.annotations.Nullable;
69 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
132 public void itemStateChanged(
final ItemEvent e) {
133 if (e.getStateChange() == ItemEvent.SELECTED) {
152 setListLabelIcon(ACTION_BUILDER.getIcon(
"prefsRes.icon"));
156 add(Box.createVerticalGlue());
174 assert mediaField != null;
180 assert imageSetBox != null;
181 final String imageSet = (String) imageSetBox.getSelectedItem();
182 projectSettings.
setImageSet(imageSet == null || imageSet.equals(
"disabled") ?
"none" : imageSet);
185 ACTION_BUILDER.showOnetimeMessageDialog(
this, JOptionPane.WARNING_MESSAGE,
"optionsRestart");
194 assert mediaField != null;
195 mediaField.
setFile(mediaDirectory);
200 assert imageSets != null;
201 final int index = Arrays2.linearEqualitySearch(imageSet, imageSets);
202 assert imageSetBox != null;
203 imageSetBox.setSelectedIndex(index);
213 assert mediaField != null;
214 mediaField.
setFile(mediaDirectory);
218 assert imageSets != null;
219 final int index = Arrays2.linearEqualitySearch(
"disabled", imageSets);
220 assert imageSetBox != null;
221 imageSetBox.setSelectedIndex(index);
227 final String imageSet;
229 assert imageSetBox != null;
239 assert mediaField != null;
253 final JComponent panel =
new JPanel(
new GridBagLayout());
265 assert mediaField != null;
277 final JComponent panel =
new JPanel(
new GridBagLayout());
281 configSourceComboBox =
new JComboBox<>(configSourceFactory.
getConfigSources());
283 configSourceComboBox.setSelectedItem(configSource);
284 configSourceComboBox.addItemListener(itemListener);
287 archField.setEnabled(configSource.isArchDirectoryInputFieldEnabled());
304 Arrays.sort(imageSetNames);
305 imageSets =
new String[imageSetNames.length + 1];
306 imageSets[0] =
"disabled";
307 System.arraycopy(imageSetNames, 0, imageSets, 1, imageSetNames.length);
309 imageSetBox =
new JComboBox<>(
imageSets);
311 assert imageSets != null;
312 final int index = Arrays2.linearEqualitySearch(imageSet, imageSets);
313 assert imageSetBox != null;
314 imageSetBox.setSelectedIndex(index);
316 assert imageSetBox != null;
336 return imageSet == null || imageSet.isEmpty() || imageSet.equals(
"none") ?
"disabled" : imageSet;
final ConfigSourceFactory configSourceFactory
The ConfigSourceFactory to use.
Component createResourcePanel()
Creates the sub-panel with the resource paths.
Utility class for string manipulation.
String getImageSet()
Returns the image set.
final EditorSettings editorSettings
The editor settings instance.
Graphical User Interface of Gridarta.
Settings that apply to a project.
static final long serialVersionUID
The serial version UID.
void setMediaDirectory(@NotNull File mediaDirectory)
Sets the media directory.
A component for selecting files.
void setConfigSourceName(@NotNull String configSourceName)
Sets the name of the configuration source.
ResPreferences(@NotNull final ProjectSettings projectSettings, @NotNull final EditorSettings editorSettings, @NotNull final ConfigSourceFactory configSourceFactory)
Create a ResPreferences pane.
static String convertImageSet(@Nullable final String imageSet)
Returns a human readable name for a given image set.
void addComponent(@NotNull final Component component)
Adds a component to the container.
File getMediaDirectoryDefault()
Returns the default media directory.
ConfigSource getDefaultConfigSource()
Returns the default ConfigSource.
JFileField mediaField
TextField for media directory path.
File getMapsDirectoryDefault()
Returns the default maps directory.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
ConfigSource [] getConfigSources()
Returns all defined configuration sources.
Base package of all Gridarta classes.
static Border createTitledBorder(final String titleKey)
Creates a titled border.
A factory for creating ConfigSources.
Possible source locations for configuration files.
String [] imageSets
Contains all supported image sets.
boolean hasMediaDirectory()
Returns whether a media directory is used.
Component buildImageSetBox()
Constructs the combo box for the selection of image sets.
JFileField mapField
TextField for map directory path.
JComboBox< String > imageSetBox
ComboBox for choosing the image set.
boolean hasImageSet()
Returns whether an image set is used.
final ProjectSettings projectSettings
The project settings instance.
void setArchDirectory(@NotNull File archDirectory)
Sets the archetype directory.
void setMapsDirectory(@NotNull File mapsDirectory)
Sets the default maps directory.
JComboBox< ConfigSource > configSourceComboBox
ComboBox for choosing the configuration source.
String getConfigSourceName()
Returns the name of the configuration source.
void setFile(@NotNull final File file)
Sets the currently selected file.
Helper class for preference panes.
final ItemListener itemListener
The ItemListener attached to configSourceComboBox.
boolean isArchDirectoryInputFieldEnabled()
Whether the "archetype directory" input field in the settings dialog should be enabled.
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
String getCurrentImageSet()
Returns the name of the currently selected image set.
Utility class for ActionBuilder related functions.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
ConfigSource getConfigSource(@NotNull String name)
Returns a ConfigSource by name.
File getArchDirectory()
Returns the archetype directory.
File getMapsDirectory()
Returns the default maps directory.
void setImageSet(@NotNull String imageSet)
Sets the image set.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
File getMediaDirectory()
Returns the media directory.
File getArchDirectoryDefault()
Returns the default archetype directory.
static final ActionBuilder ACTION_BUILDER
Action Builder.
JFileField archField
TextField for arch directory path.
File getFile()
Returns the currently selected file.
Component createGlobalPanel()
Creates the sub-panel with the editor settings.
Settings that apply to the editor.
Preferences Module for resource preferences.
Defines common UI constants used in different dialogs.