* @see de.ailis.xadrian.support.ModalDialog#open()
*/
@Override
public Result open()
{
final Config config = Config.getInstance();
// Load preference values
for (final Map.Entry<Race, JCheckBox> entry : this.racesCheckBoxes
.entrySet())
{
final Race race = entry.getKey();
final JCheckBox checkBox = entry.getValue();
checkBox.setSelected(!config.isRaceIgnored(race));
}
this.showFactoryResourcesCheckBox.setSelected(config
.isShowFactoryResources());
this.nightModeCheckBox.setSelected(config
.isNightMode());
this.themeComboBox.setSelectedItem(ThemeFactory.getInstance().getTheme(
UIManager.getLookAndFeel().getClass().getName()));
this.localeComboBox.setSelectedItem(new ComboBoxEntry(null,
config.getLocale()));
this.prodStatsComboBox.setSelectedItem(new ComboBoxEntry(null,
config.isProdStatsPerMinute()));
this.x3tcPlayerSectorComboBox.setSelectedIndex(config.getX3TCPlayerSector());
this.x3apPlayerSectorComboBox.setSelectedIndex(config.getX3APPlayerSector());
final String defaultGameId = config.getDefaultGame();
final GameFactory gameFactory = GameFactory.getInstance();
if (defaultGameId == null || !gameFactory.hasGame(defaultGameId))
this.gamesComboBox.setSelectedIndex(0);
else
this.gamesComboBox.setSelectedItem(GameFactory.getInstance()
.getGame(defaultGameId));
final Result result = super.open();
if (result == Result.OK)
{
// Save preference values
for (final Map.Entry<Race, JCheckBox> entry : this.racesCheckBoxes
.entrySet())
{
final Race race = entry.getKey();
final JCheckBox checkBox = entry.getValue();
config.setRaceIgnored(race, !checkBox.isSelected());
}
for (final Game game : GameFactory.getInstance().getGames())
{
game.getAddFactoryDialog().resetFactoriesTreeModel();
}
config.setShowFactoryResources(this.showFactoryResourcesCheckBox
.isSelected());
config.setNightMode(this.nightModeCheckBox.isSelected());
config.setX3TCPlayerSector(
this.x3tcPlayerSectorComboBox.getSelectedIndex());
config.setX3APPlayerSector(
this.x3apPlayerSectorComboBox.getSelectedIndex());
config.setTheme(((Theme) this.themeComboBox.getSelectedItem())
.getClassName());
config.setLocale((String) ((ComboBoxEntry)
this.localeComboBox.getSelectedItem()).getValue());
config.setProdStatsPerMinute((Boolean) ((ComboBoxEntry)
this.prodStatsComboBox.getSelectedItem()).getValue());
if (this.gamesComboBox.getSelectedIndex() == 0)
config.setDefaultGame(null);
else
config.setDefaultGame(((Game) this.gamesComboBox
.getSelectedItem()).getId());
}
return result;
}