Gridarta Editor
MiscPreferences.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.prefs;
21 
22 import java.awt.Component;
23 import java.awt.GridBagLayout;
24 import javax.swing.AbstractButton;
25 import javax.swing.Box;
26 import javax.swing.JCheckBox;
27 import javax.swing.JComponent;
28 import javax.swing.JPanel;
29 import javax.swing.JTextField;
30 import javax.swing.border.Border;
31 import javax.swing.border.CompoundBorder;
32 import javax.swing.border.TitledBorder;
33 import javax.swing.event.ChangeEvent;
34 import javax.swing.event.ChangeListener;
35 import javax.swing.text.JTextComponent;
42 import net.sf.japi.swing.action.ActionBuilder;
43 import net.sf.japi.swing.action.ActionBuilderFactory;
44 import net.sf.japi.swing.prefs.AbstractPrefs;
45 import org.jetbrains.annotations.NotNull;
46 
52 public class MiscPreferences extends AbstractPrefs {
53 
57  private static final long serialVersionUID = 1L;
58 
62  @NotNull
63  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
64 
68  @NotNull
70 
74  @NotNull
76 
80  @NotNull
82 
86  private JTextComponent userField;
87 
91  @NotNull
92  private AbstractButton checkMaps;
93 
98  @NotNull
99  private AbstractButton pasteExitName;
100 
104  @NotNull
105  private AbstractButton autoCreateExit;
106 
110  @NotNull
111  private JTextComponent exitArchetypeName;
112 
119  public MiscPreferences(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ProjectSettings projectSettings, @NotNull final EditorSettings editorSettings) {
120  this.exitConnectorModel = exitConnectorModel;
121  this.projectSettings = projectSettings;
122  this.editorSettings = editorSettings;
123 
124  setListLabelText(ActionBuilderUtils.getString(ACTION_BUILDER, "prefsMisc.title"));
125  setListLabelIcon(ACTION_BUILDER.getIcon("prefsMisc.icon"));
126 
127  add(createUserPanel());
128  add(createCheckMapsPanel());
130  add(Box.createVerticalGlue());
131  }
132 
138  @NotNull
139  private static Border createTitledBorder(@NotNull final String title) {
140  return new CompoundBorder(new TitledBorder(title), GUIConstants.DIALOG_BORDER);
141  }
142 
143  @Override
144  public void apply() {
145  projectSettings.setUserName(userField.getText());
146  MapFileFilter.setPerformingRealChecks(checkMaps.isSelected());
147  exitConnectorModel.setAutoCreateExit(autoCreateExit.isSelected());
148  exitConnectorModel.setPasteExitName(pasteExitName.isSelected());
149  exitConnectorModel.setExitArchetypeName(exitArchetypeName.getText());
150  }
151 
152  @Override
153  public void revert() {
154  userField.setText(projectSettings.getUserName());
155  checkMaps.setSelected(MapFileFilter.isPerformingRealChecks());
156  autoCreateExit.setSelected(exitConnectorModel.isAutoCreateExit());
157  pasteExitName.setSelected(exitConnectorModel.isPasteExitName());
158  exitArchetypeName.setText(exitConnectorModel.getExitArchetypeName());
159  }
160 
161  @Override
162  public void defaults() {
163  userField.setText(editorSettings.getUserNameDefault());
164  checkMaps.setSelected(true);
165  autoCreateExit.setSelected(ExitConnectorModel.AUTO_CREATE_EXIT_DEFAULT);
166  pasteExitName.setSelected(ExitConnectorModel.PASTE_EXIT_NAME_DEFAULT);
167  exitArchetypeName.setText(ExitConnectorModel.EXIT_ARCHETYPE_NAME_DEFAULT);
168  }
169 
170  @Override
171  public boolean isChanged() {
172  return !(userField.getText().equals(projectSettings.getUserName()) && checkMaps.isSelected() == MapFileFilter.isPerformingRealChecks() && autoCreateExit.isSelected() == exitConnectorModel.isAutoCreateExit() && pasteExitName.isSelected() == exitConnectorModel.isPasteExitName() && exitArchetypeName.getText().equals(exitConnectorModel.getExitArchetypeName()));
173  }
174 
179  @NotNull
180  private Component createUserPanel() {
181  final JComponent panel = new JPanel(new GridBagLayout());
182  final PreferencesHelper preferencesHelper = new PreferencesHelper(panel);
183  panel.setBorder(createTitledBorder(ActionBuilderUtils.getString(ACTION_BUILDER, "optionsUser")));
184  userField = new JTextField(projectSettings.getUserName());
185  preferencesHelper.addComponent(userField);
186  return panel;
187  }
188 
193  @NotNull
194  private Component createCheckMapsPanel() {
195  final JComponent panel = new JPanel(new GridBagLayout());
196  final PreferencesHelper preferencesHelper = new PreferencesHelper(panel);
197  panel.setBorder(createTitledBorder(ActionBuilderUtils.getString(ACTION_BUILDER, "optionsMisc")));
198  checkMaps = new JCheckBox(ACTION_BUILDER.createAction(false, "optionsCheckMaps"));
199  checkMaps.setSelected(MapFileFilter.isPerformingRealChecks());
200  preferencesHelper.addComponent(checkMaps);
201  return panel;
202  }
203 
208  @NotNull
209  private Component createExitConnectorPanel() {
210  final JComponent panel = new JPanel(new GridBagLayout());
211  final PreferencesHelper preferencesHelper = new PreferencesHelper(panel);
212  panel.setBorder(createTitledBorder(ActionBuilderUtils.getString(ACTION_BUILDER, "optionsExitConnector")));
213 
214  pasteExitName = new JCheckBox(ACTION_BUILDER.createAction(false, "optionsExitConnectorPasteExitName"));
215  pasteExitName.setSelected(exitConnectorModel.isPasteExitName());
216  preferencesHelper.addComponent(pasteExitName);
217 
218  autoCreateExit = new JCheckBox(ACTION_BUILDER.createAction(false, "optionsExitConnectorAutoCreateExit"));
219  autoCreateExit.setSelected(exitConnectorModel.isAutoCreateExit());
220  preferencesHelper.addComponent(autoCreateExit);
221 
222  preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsExitConnectorExitArchetypeName.text"));
223  exitArchetypeName = new JTextField(exitConnectorModel.getExitArchetypeName());
224  preferencesHelper.addComponent(exitArchetypeName);
225 
226  autoCreateExit.addChangeListener(new ChangeListener() {
227 
228  @Override
229  public void stateChanged(final ChangeEvent e) {
230  exitArchetypeName.setEnabled(autoCreateExit.isSelected());
231  }
232 
233  });
234  exitArchetypeName.setEnabled(autoCreateExit.isSelected());
235 
236  return panel;
237  }
238 
239 }
static final ActionBuilder ACTION_BUILDER
Action Builder.
Component createUserPanel()
Creates the sub-panel with the user settings.
Graphical User Interface of Gridarta.
Settings that apply to a project.
static Border createTitledBorder(@NotNull final String title)
Create a titled border.
final ProjectSettings projectSettings
The ProjectSettings to affect.
void setUserName(@NotNull String userName)
Sets the user name.
static boolean isPerformingRealChecks()
Get whether to actually perform real checks or just file endings.
static void setPerformingRealChecks(final boolean performingRealChecks)
Set whether to actually perform real checks or just file endings.
void addComponent(@NotNull final Component component)
Adds a component to the container.
void setExitArchetypeName(@NotNull String exitArchetypeName)
Sets the archetype name for creating exit game objects.
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 isAutoCreateExit()
Returns whether exit game objects should be auto-created when needed.
Swing FileFilter implementation that filters Daimonin map files.
final EditorSettings editorSettings
The EditorSettings to affect.
AbstractButton autoCreateExit
Check box to set whether exit game objects should be auto-created.
JTextComponent exitArchetypeName
The archetype name for auto-creating exits.
String getUserName()
Returns the user name.
Preferences Module for miscellaneous preferences.
String getUserNameDefault()
Returns the default user name.
Component createExitConnectorPanel()
Creates the sub-panel with the exit connector settings.
final ExitConnectorModel exitConnectorModel
The ExitConnectorModel to affect.
AbstractButton pasteExitName
Check box to set whether the map name should be pasted into exit game objects.
MiscPreferences(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ProjectSettings projectSettings, @NotNull final EditorSettings editorSettings)
Creates a new instance.
void setAutoCreateExit(boolean autoCreateExit)
Sets whether exit game objects should be auto-created when needed.
String getExitArchetypeName()
Returns the archetype name when creating exit game objects.
Utility class for ActionBuilder related functions.
Stores information needed by the exit connector.
boolean isPasteExitName()
Returns whether the exit name should be updated.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
AbstractButton checkMaps
Check box to set whether map files should be really checked.
static final long serialVersionUID
The serial version UID.
boolean AUTO_CREATE_EXIT_DEFAULT
The default value for isAutoCreateExit().
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
String EXIT_ARCHETYPE_NAME_DEFAULT
The default value for getExitArchetypeName().
void setPasteExitName(boolean pasteExitName)
Sets whether the exit name should be updated.
Settings that apply to the editor.
boolean PASTE_EXIT_NAME_DEFAULT
The default value for isPasteExitName().
JTextComponent userField
TextField for user / artist name.
Defines common UI constants used in different dialogs.
Component createCheckMapsPanel()
Creates the sub-panel with the check maps settings.