From: <aki...@us...> - 2008-08-01 19:53:17
|
Revision: 4650 http://gridarta.svn.sourceforge.net/gridarta/?rev=4650&view=rev Author: akirschbaum Date: 2008-08-01 19:53:02 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Remove MainControl.getGlobalSettings(). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/GlobalSettingsImpl.java trunk/crossfire/src/cfeditor/MapActions.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java trunk/crossfire/src/cfeditor/gui/map/MapTilePane.java trunk/crossfire/src/cfeditor/gui/prefs/ResPrefs.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/GlobalSettingsImpl.java trunk/daimonin/src/daieditor/MapActions.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java trunk/daimonin/src/daieditor/gui/map/MapTilePane.java trunk/daimonin/src/daieditor/gui/prefs/ResPrefs.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/GlobalSettings.java trunk/src/app/net/sf/gridarta/GlobalSettingsImpl.java trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/gameobject/scripts/AbstractScriptArchEditor.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptUtils.java trunk/src/app/net/sf/gridarta/gameobject/scripts/ScriptedEventEditor.java trunk/src/app/net/sf/gridarta/gui/map/AbstractMapTilePane.java trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObject; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gameobject.scripts.ScriptArchEditor; import cfeditor.gameobject.scripts.ScriptArchUtils; import cfeditor.gameobject.scripts.ScriptedEvent; import cfeditor.gui.GameObjectAttributesPanel; @@ -63,6 +64,7 @@ import net.sf.gridarta.gameobject.match.GameObjectMatchers; import net.sf.gridarta.gameobject.match.GameObjectMatchersInstance; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gui.About; import net.sf.gridarta.gui.DefaultObjectChooser; import net.sf.gridarta.gui.HideFileFilterProxy; @@ -183,8 +185,6 @@ /** The current script controller. */ private final ScriptController scriptControl; - private final GlobalSettingsImpl globalSettings = new GlobalSettingsImpl(); - /** The list of archtype-data (loaded from "types.xml"). */ private final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet; @@ -223,11 +223,13 @@ * @throws RuntimeException If the controller cannot be initialized. */ public CMainControl() { - super(new CrossfireObjectsFactory(), "cfeditor"); + super(new CrossfireObjectsFactory(), "cfeditor", new GlobalSettingsImpl()); CMainControlInstance.instance = this; globalSettings.readGlobalSettings(); + ScriptArchEditor.setGlobalSettings(globalSettings); + ScriptedEventEditor.setGlobalSettings(globalSettings); animationObjects = new cfeditor.gameobject.anim.AnimationObjects(); - archetypeSet = new ArchetypeSet(this, editTypes, animationObjects, faceObjects, globalSettings.getImageSet()); + archetypeSet = new ArchetypeSet(this, globalSettings, editTypes, animationObjects, faceObjects, ((GlobalSettingsImpl) globalSettings).getImageSet()); GameObject.setArchetypeSet(archetypeSet); ScriptedEvent.setArchetypeSet(archetypeSet); final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, MainView.MAP_TILE_LIST_BOTTOM_DEFAULT); @@ -293,7 +295,7 @@ log.fatal("GameObjectMatcher 'exit' does not exist"); throw new MissingResourceException("GameObjectMatcher 'exit' does not exist", null, null); } - final MapActions mapActions = new MapActions(mainView, this, mapManager, exitMatcher, mapFileFilter, selectedSquareView); + final MapActions mapActions = new MapActions(mainView, this, globalSettings, mapManager, exitMatcher, mapFileFilter, selectedSquareView); archetypeTypeSet.getListTable().put("event", ScriptArchUtils.getEventTypes()); Map<String, TreasureTreeNode> specialTreasureLists; try { @@ -319,7 +321,7 @@ log.error("Cannot read " + CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } - AbstractScriptArchEditor.initEventTypeBoxes(".py", "Python", ScriptArchUtils.createEventTypeBox(), pythonFileFilter); + AbstractScriptArchEditor.initEventTypeBoxes(".py", "Python", ScriptArchUtils.createEventTypeBox(), pythonFileFilter, globalSettings); // Initialize the main view final LockedItemsControl<GameObject, MapArchObject, Archetype, CMapViewBasic> lockedItemsControl = new LockedItemsControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager, Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_TRIGGER_ALTAR, Archetype.TYPE_DETECTOR, Archetype.TYPE_TRIGGER_MARKER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_CONTAINER); @@ -474,11 +476,6 @@ /** Swing FileFilter for Python scripts. */ public static final FileFilter pythonFileFilter = new HideFileFilterProxy(new EndingFileFilter(true, ACTION_FACTORY.getString("fileDialog.filter.python"), ".py")); - /** {@inheritDoc} */ - public GlobalSettingsImpl getGlobalSettings() { - return globalSettings; - } - /** * Returns the main view. * @return the main view @@ -653,7 +650,7 @@ if (prefsGroup == null) { prefsGroup = new PreferencesGroup( "Gridarta for Crossfire", - new ResPrefs(this), + new ResPrefs((GlobalSettingsImpl) globalSettings), new GUIPrefs(), new MiscPrefs(), new UpdatePrefs(), Modified: trunk/crossfire/src/cfeditor/GlobalSettingsImpl.java =================================================================== --- trunk/crossfire/src/cfeditor/GlobalSettingsImpl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/GlobalSettingsImpl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -51,15 +51,17 @@ return imageSet; } + /** {@inheritDoc} */ public boolean isAutoPopupDocu() { return autoPopupDocu; } + /** {@inheritDoc} */ public void setAutoPopupDocu(final boolean autoPopupDocu) { this.autoPopupDocu = autoPopupDocu; } - /** Set all global settings from the preferences. */ + /** {@inheritDoc} */ public void readGlobalSettings() { imageSet = prefs.get(USE_IMAGESET, "base"); if (imageSet.equalsIgnoreCase("none")) { Modified: trunk/crossfire/src/cfeditor/MapActions.java =================================================================== --- trunk/crossfire/src/cfeditor/MapActions.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/MapActions.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -36,6 +36,7 @@ import javax.swing.filechooser.FileFilter; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.CurrentMapListener; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.MainControl; import net.sf.gridarta.MapManager; import net.sf.gridarta.gameobject.match.GameObjectMatcher; @@ -110,6 +111,10 @@ /** The main control to use. */ private final CMainControl mainControl; + /** The global settings instance. */ + @NotNull + private final GlobalSettings globalSettings; + /** The map manager. */ private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; @@ -132,14 +137,16 @@ * Create a new instance. * @param parent the component for showing dialog boxes * @param mainControl the main control to use + * @param globalSettings the global settings instance * @param mapManager the map manager * @param exitMatcher the game object matcher selecting exit objects * @param mapFileFilter the Swing file filter to use * @param selectedSquareView the selected square vuew to use */ - public MapActions(@NotNull final Component parent, final CMainControl mainControl, final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final GameObjectMatcher exitMatcher, final FileFilter mapFileFilter, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { + public MapActions(@NotNull final Component parent, final CMainControl mainControl, @NotNull final GlobalSettings globalSettings,final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final GameObjectMatcher exitMatcher, final FileFilter mapFileFilter, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { this.parent = parent; this.mainControl = mainControl; + this.globalSettings = globalSettings; this.mapManager = mapManager; this.exitMatcher = exitMatcher; this.mapFileFilter = mapFileFilter; @@ -235,7 +242,7 @@ public void mapProperties() { final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = getMapPropertiesEnabled(); if (mapView != null) { - MapPropertiesDialog.showDialog(mapView.getComponent(), mainControl, mapView.getMapControl(), mapFileFilter); + MapPropertiesDialog.showDialog(mapView.getComponent(), mainControl, globalSettings, mapView.getMapControl(), mapFileFilter); } } @@ -366,11 +373,11 @@ ACTION_FACTORY.showMessageDialog(parent, "enterExitRandomDestination"); return; } - newfile = new File(mainControl.getGlobalSettings().getMapDir().getAbsolutePath(), destinationMap); + newfile = new File(globalSettings.getMapDir().getAbsolutePath(), destinationMap); } else if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { // we have an absolute path: - newfile = new File(mainControl.getGlobalSettings().getMapDir().getAbsolutePath(), path.substring(1)); + newfile = new File(globalSettings.getMapDir().getAbsolutePath(), path.substring(1)); } else { // we have a relative path: if (currentMap.getMapFile() == null) { Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -38,6 +38,7 @@ import java.util.List; import javax.swing.ImageIcon; import net.sf.gridarta.EditTypes; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.AbstractArchetypeSet; import net.sf.gridarta.gameobject.anim.AnimationObjects; @@ -70,6 +71,12 @@ private final CMainControl mainControl; + /** + * The global settings instance. + */ + @NotNull + private final GlobalSettings globalSettings; + private final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes; @NotNull @@ -88,14 +95,16 @@ /** * Create the ArchetypeSet. * @param mainControl reference to CMainControl + * @param globalSettings the global settigns instance * @param editTypes the edit types instance * @param animationObjects the animations to use * @param faceObjects the FaceObjects instance to use * @param imageSet the image set to use */ - public ArchetypeSet(final CMainControl mainControl, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final AnimationObjects<AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects, @Nullable final String imageSet) { + public ArchetypeSet(@NotNull final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final AnimationObjects<AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects, @Nullable final String imageSet) { super(mainControl.getGridartaObjectsFactory()); this.mainControl = mainControl; + this.globalSettings = globalSettings; this.editTypes = editTypes; this.animationObjects = animationObjects; this.faceObjects = faceObjects; @@ -127,13 +136,13 @@ final List<GameObject> invObjects = new ArrayList<GameObject>(); final String fname; // here we go... - if (mainControl.getGlobalSettings().isArchLoadedFromCollection()) { + if (globalSettings.isArchLoadedFromCollection()) { loadArchFromCollected(archetypeParser, invObjects); // load arches & images from collection fname = IGUIConstants.ARCH_FILE; } else { FaceObjectProviders.setNormal(new ArchFaceProvider()); setLoadedFromArchive(false); // don't load from the collected files - fname = mainControl.getGlobalSettings().getArchDefaultFolder(); + fname = globalSettings.getArchDefaultFolder(); loadArchetypesFromFiles(archetypeParser, new File(fname), "/", 0, "default", "default", invObjects); // load arches & images from individual files } reportErrors(mainControl.getMainView()); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchEditor.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -25,11 +25,14 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ScriptArchEditor extends AbstractScriptArchEditor { @@ -39,6 +42,16 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + /** + * The global settings instance. + */ + @Nullable + private static GlobalSettings globalSettings = null; + + public static void setGlobalSettings(@NotNull final GlobalSettings globalSettings) { + ScriptArchEditor.globalSettings = globalSettings; + } + public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); @@ -64,7 +77,7 @@ String absScriptPath; if (scriptPath.startsWith("/")) { // script path is absolute - final File mapDir = new File(AbstractMainControl.getInstance().getGlobalSettings().getMapDefaultFolder()); // global map directory + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory if (!mapDir.exists()) { // if map dir doesn't exist, this is not going to work frame.setVisible(false); Modified: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -40,10 +40,12 @@ import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import javax.swing.filechooser.FileFilter; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.Size2D; import net.sf.gridarta.help.Help; import net.sf.gridarta.map.MapControl; import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; /** * A dialog to change the properties of a map, like several flags and settings @@ -167,10 +169,11 @@ /** * Creates a map-options dialog. * @param mainControl The controller of this dialog. + * @param globalSettings the global settings instance * @param mapControl The level whose properties are shown/edited. * @param mapFileFilter the Swing file filter to use */ - private MapPropertiesDialog(final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { + private MapPropertiesDialog(final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { okButton.setDefaultCapable(true); setOptions(new Object[] {helpButton, okButton, restoreButton, cancelButton}); @@ -214,7 +217,7 @@ final JPanel weatherPanel = createWeatherPanel(map); tabs.add(ACTION_FACTORY.getString("mapWeatherTabTitle"), weatherPanel); - mapTilePane = new MapTilePane(mainControl, mapControl, mapFileFilter); + mapTilePane = new MapTilePane(mainControl, globalSettings, mapControl, mapFileFilter); final JPanel tilePanel = createTilePathPanel(mapTilePane); tabs.add(ACTION_FACTORY.getString("mapTilesTabTitle"), tilePanel); @@ -624,11 +627,12 @@ * Show a dialog querying the user for map properties. * @param parent the parent component to show dialog on * @param mainControl CMainControl with information + * @param globalSettings the global settings instance * @param level map to show dialog about * @param mapFileFilter the Swing file filter to use */ - public static void showDialog(final Component parent, final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> level, final FileFilter mapFileFilter) { - final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, level, mapFileFilter); + public static void showDialog(final Component parent, final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> level, final FileFilter mapFileFilter) { + final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, globalSettings, level, mapFileFilter); final JDialog dialog = pane.createDialog(parent, ACTION_FACTORY.format("mapTitle", level.getMapModel().getMapArchObject().getMapDisplayName(), level.getMapFileName())); pane.dialog = dialog; dialog.getRootPane().setDefaultButton(pane.okButton); Modified: trunk/crossfire/src/cfeditor/gui/map/MapTilePane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapTilePane.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/gui/map/MapTilePane.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -24,9 +24,11 @@ import cfeditor.gameobject.GameObject; import cfeditor.map.MapArchObject; import javax.swing.filechooser.FileFilter; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gui.DirectionLayout; import net.sf.gridarta.gui.map.AbstractMapTilePane; import net.sf.gridarta.map.MapControl; +import org.jetbrains.annotations.NotNull; /** * A Panel for managing the tiling of maps. Implementation for 4 tile paths. @@ -56,12 +58,13 @@ * Create a MapTilePane. * @param mainControl CMainControl to use for displaying dialogs, getting * paths etc.. + * @param globalSettings the global settings instance * @param mapControl MapControl of the map that's tiles are to be viewed / * controlled * @param mapFileFilter the Swing file filter to use */ - public MapTilePane(final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { - super(mainControl, mapControl, tileLink, directionMapping, nextFocus, mapFileFilter); + public MapTilePane(final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { + super(mainControl, globalSettings, mapControl, tileLink, directionMapping, nextFocus, mapFileFilter); } } // class MapTilePane Modified: trunk/crossfire/src/cfeditor/gui/prefs/ResPrefs.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/prefs/ResPrefs.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/crossfire/src/cfeditor/gui/prefs/ResPrefs.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -19,7 +19,7 @@ package cfeditor.gui.prefs; -import cfeditor.CMainControl; +import cfeditor.GlobalSettingsImpl; import cfeditor.ResourceFileManager; import java.awt.Component; import java.awt.Container; @@ -58,8 +58,8 @@ /** Preferences. */ private static final Preferences prefs = Preferences.userNodeForPackage(MainControl.class); - /** Main Control. */ - private final CMainControl mainControl; + /** The global settings instance to use. */ + private final GlobalSettingsImpl globalSettings; /** TextField for arch directory path. */ private JFileField archField; @@ -81,12 +81,12 @@ /** * Create a ResPrefs pane. - * @param mainControl The controller of this dialog. + * @param globalSettings the global settings instance to use */ - public ResPrefs(final CMainControl mainControl) { + public ResPrefs(final GlobalSettingsImpl globalSettings) { setListLabelText(ACTION_FACTORY.getString("prefsRes.title")); setListLabelIcon(ACTION_FACTORY.getIcon("prefsRes.icon")); - this.mainControl = mainControl; + this.globalSettings = globalSettings; add(createResourcePanel()); add(createGlobalPanel()); @@ -112,16 +112,16 @@ final String imageSet = (String) imageSetBox.getSelectedItem(); prefs.put(GlobalSettings.USE_IMAGESET, imageSet == null || imageSet.equals("disabled") ? "none" : imageSet); - mainControl.getGlobalSettings().readGlobalSettings(); + globalSettings.readGlobalSettings(); ACTION_FACTORY.showOnetimeMessageDialog(this, JOptionPane.WARNING_MESSAGE, "optionsRestart"); } /** {@inheritDoc} */ public void revert() { - archField.setText(mainControl.getGlobalSettings().getArchDefaultFolder()); - mapField.setText(mainControl.getGlobalSettings().getMapDefaultFolder()); - scriptField.setText(mainControl.getGlobalSettings().getScriptDefaultFolder()); - loadArches.setSelected(mainControl.getGlobalSettings().isArchLoadedFromCollection()); + archField.setText(globalSettings.getArchDefaultFolder()); + mapField.setText(globalSettings.getMapDefaultFolder()); + scriptField.setText(globalSettings.getScriptDefaultFolder()); + loadArches.setSelected(globalSettings.isArchLoadedFromCollection()); imageSetBox.setSelectedIndex(linearSearch(imageSets, getCurrentImageSet())); } @@ -139,10 +139,10 @@ final String selectedimageSet = (String) imageSetBox.getSelectedItem(); final String imageSet = selectedimageSet == null ? "disabled" : selectedimageSet; return !( - archField.getText().equals(mainControl.getGlobalSettings().getArchDefaultFolder()) - && mapField.getText().equals(mainControl.getGlobalSettings().getMapDefaultFolder()) - && scriptField.getText().equals(mainControl.getGlobalSettings().getScriptDefaultFolder()) - && loadArches.isSelected() == prefs.getBoolean(GlobalSettings.LOAD_ARCH_COLL, mainControl.getGlobalSettings().isArchLoadedFromCollection()) + archField.getText().equals(globalSettings.getArchDefaultFolder()) + && mapField.getText().equals(globalSettings.getMapDefaultFolder()) + && scriptField.getText().equals(globalSettings.getScriptDefaultFolder()) + && loadArches.isSelected() == prefs.getBoolean(GlobalSettings.LOAD_ARCH_COLL, globalSettings.isArchLoadedFromCollection()) && imageSet.equals(getCurrentImageSet()) ); } @@ -170,9 +170,9 @@ private Component createResourcePanel() { final Box resourcePanel = Box.createVerticalBox(); resourcePanel.setBorder(createTitledBorder("optionsResPaths")); - archField = createFileField(resourcePanel, "optionsResArch", mainControl.getGlobalSettings().getArchDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); - mapField = createFileField(resourcePanel, "optionsResMaps", mainControl.getGlobalSettings().getMapDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); - scriptField = createFileField(resourcePanel, "optionsResScripts", mainControl.getGlobalSettings().getScriptDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + archField = createFileField(resourcePanel, "optionsResArch", globalSettings.getArchDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + mapField = createFileField(resourcePanel, "optionsResMaps", globalSettings.getMapDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + scriptField = createFileField(resourcePanel, "optionsResScripts", globalSettings.getScriptDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); return resourcePanel; } @@ -185,9 +185,9 @@ globalPanel.setBorder(createTitledBorder("optionsGlobal")); loadArches = new JCheckBox(ACTION_FACTORY.createToggle(false, "optionsLoadArchColl", this)); - loadArches.setSelected(mainControl.getGlobalSettings().isArchLoadedFromCollection()); + loadArches.setSelected(globalSettings.isArchLoadedFromCollection()); globalPanel.add(loadArches); - if (mainControl.getGlobalSettings().isArchLoadedFromCollection()) { + if (globalSettings.isArchLoadedFromCollection()) { archField.setEnabled(false); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -25,6 +25,7 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.anim.AnimationObject; import daieditor.gameobject.face.FaceObjects; +import daieditor.gameobject.scripts.ScriptArchEditor; import daieditor.gameobject.scripts.ScriptArchUtils; import daieditor.gameobject.scripts.ScriptedEvent; import daieditor.gui.GameObjectAttributesPanel; @@ -70,6 +71,7 @@ import net.sf.gridarta.gameobject.match.MutableOrGameObjectMatcher; import net.sf.gridarta.gameobject.match.ViewGameObjectMatcherManager; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; +import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gui.About; import net.sf.gridarta.gui.DefaultObjectChooser; import net.sf.gridarta.gui.GUIUtils; @@ -223,8 +225,6 @@ /** Whether to display double arches like stacked walls in stacked version. */ private boolean drawDouble; - private final GlobalSettingsImpl globalSettings = new GlobalSettingsImpl(); - /** The list of archtype-data (loaded from "types.xml"). */ private final ArchetypeTypeSet<GameObject, MapArchObject, Archetype> archetypeTypeSet; @@ -278,12 +278,14 @@ * @throws RuntimeException If the controller cannot be initialized. */ public CMainControl() { - super(new DaimoninObjectsFactory(), "daieditor"); + super(new DaimoninObjectsFactory(), "daieditor", new GlobalSettingsImpl()); CMainControlInstance.instance = this; globalSettings.readGlobalSettings(); + ScriptArchEditor.setGlobalSettings(globalSettings); + ScriptedEventEditor.setGlobalSettings(globalSettings); animationObjects = new daieditor.gameobject.anim.AnimationObjects(); GameObject.setAnimationObjects(animationObjects); - archetypeSet = new ArchetypeSet(this, editTypes, animationObjects, faceObjects); + archetypeSet = new ArchetypeSet(this, globalSettings, editTypes, animationObjects, faceObjects); GameObject.setArchetypeSet(archetypeSet); ScriptedEvent.setArchetypeSet(archetypeSet); final boolean mapTileListBottom = prefs.getBoolean(MainView.MAP_TILE_LIST_BOTTOM_KEY, MainView.MAP_TILE_LIST_BOTTOM_DEFAULT); @@ -354,7 +356,7 @@ log.fatal("GameObjectMatcher 'exit' does not exist"); throw new MissingResourceException("GameObjectMatcher 'exit' does not exist", null, null); } - final MapActions mapActions = new MapActions(mainView, this, mapManager, exitMatcher, mapFileFilter, selectedSquareView); + final MapActions mapActions = new MapActions(mainView, this, (GlobalSettingsImpl) globalSettings, mapManager, exitMatcher, mapFileFilter, selectedSquareView); Map<String, TreasureTreeNode> specialTreasureLists; try { final Document specialTreasureListsDocument = xmlHelper.getDocumentBuilder().parse(IOUtils.getResourceURLAsString(getConfigurationDirectory(), "TreasureLists.xml")); @@ -380,7 +382,7 @@ log.error("Cannot read " + CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage()); } - AbstractScriptArchEditor.initEventTypeBoxes(".lua", "Lua", ScriptArchUtils.createEventTypeBox(), luaFileFilter); + AbstractScriptArchEditor.initEventTypeBoxes(".lua", "Lua", ScriptArchUtils.createEventTypeBox(), luaFileFilter, globalSettings); // Initialize the main view final LockedItemsControl<GameObject, MapArchObject, Archetype, CMapViewBasic> lockedItemsControl = new LockedItemsControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(mapManager, Archetype.TYPE_LOCKED_DOOR, Archetype.TYPE_SPECIAL_KEY, Archetype.TYPE_ALTAR_TRIGGER, Archetype.TYPE_MARKER, Archetype.TYPE_INVENTORY_CHECKER, Archetype.TYPE_SPAWN_POINT, Archetype.TYPE_CONTAINER); @@ -655,11 +657,6 @@ /** Swing FileFilter for all unignored files. */ public static final FileFilter unignoredFilter = new HideFileFilterProxy(new EndingFileFilter(true, ACTION_FACTORY.getString("fileDialog.filter.unignored"), "")); - /** {@inheritDoc} */ - public GlobalSettingsImpl getGlobalSettings() { - return globalSettings; - } - /** * Returns the main view. * @return the main view @@ -837,7 +834,7 @@ if (prefsGroup == null) { prefsGroup = new PreferencesGroup( "Gridarta for Daimonin", - new ResPrefs(this), + new ResPrefs((GlobalSettingsImpl) globalSettings), new AppPrefs(), new NetPrefs(), new GUIPrefs(), Modified: trunk/daimonin/src/daieditor/GlobalSettingsImpl.java =================================================================== --- trunk/daimonin/src/daieditor/GlobalSettingsImpl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/GlobalSettingsImpl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -47,15 +47,17 @@ return mediaDir; } + /** {@inheritDoc} */ public boolean isAutoPopupDocu() { return autoPopupDocu; } + /** {@inheritDoc} */ public void setAutoPopupDocu(final boolean autoPopupDocu) { this.autoPopupDocu = autoPopupDocu; } - /** Set all global settings from the preferences. */ + /** {@inheritDoc} */ public void readGlobalSettings() { initDirs(); Modified: trunk/daimonin/src/daieditor/MapActions.java =================================================================== --- trunk/daimonin/src/daieditor/MapActions.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/MapActions.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -106,6 +106,10 @@ /** The main control to use. */ private final CMainControl mainControl; + /** The global settings instance. */ + @NotNull + private final GlobalSettingsImpl globalSettings; + /** The map manager. */ private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; @@ -128,14 +132,16 @@ * Create a new instance. * @param parent the component for showing dialog boxes * @param mainControl the main control to use + * @param globalSettings the global settings instance * @param mapManager the map manager * @param exitMatcher the game object matcher selecting exit objects * @param mapFileFilter the Swing file filter to use * @param selectedSquareView the selected square vuew to use */ - public MapActions(@NotNull final Component parent, final CMainControl mainControl, final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final GameObjectMatcher exitMatcher, final FileFilter mapFileFilter, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { + public MapActions(@NotNull final Component parent, final CMainControl mainControl, @NotNull final GlobalSettingsImpl globalSettings, final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, final GameObjectMatcher exitMatcher, final FileFilter mapFileFilter, @NotNull final SelectedSquareView<GameObject, MapArchObject, Archetype, CMapViewBasic> selectedSquareView) { this.parent = parent; this.mainControl = mainControl; + this.globalSettings = globalSettings; this.mapManager = mapManager; this.exitMatcher = exitMatcher; this.mapFileFilter = mapFileFilter; @@ -231,7 +237,7 @@ public void mapProperties() { final MapView<GameObject, MapArchObject, Archetype, CMapViewBasic> mapView = getMapPropertiesEnabled(); if (mapView != null) { - MapPropertiesDialog.showDialog(mapView.getComponent(), mainControl, mapView.getMapControl(), mapFileFilter); + MapPropertiesDialog.showDialog(mapView.getComponent(), mainControl, globalSettings, mapView.getMapControl(), mapFileFilter); } } @@ -340,7 +346,7 @@ @NotNull final File newfile; // new mapfile to open if (path.startsWith(File.pathSeparator) || path.startsWith("/")) { // we have an absolute path: - newfile = new File(mainControl.getGlobalSettings().getMapDir().getAbsolutePath(), path.substring(1)); + newfile = new File(globalSettings.getMapDir().getAbsolutePath(), path.substring(1)); } else { // we have a relative path: if (currentMap.getMapFile() == null) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -39,6 +39,7 @@ import java.util.List; import javax.swing.ImageIcon; import net.sf.gridarta.EditTypes; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gameobject.AbstractArchetypeParser; import net.sf.gridarta.gameobject.AbstractArchetypeSet; import net.sf.gridarta.gameobject.anim.AnimationObjects; @@ -72,6 +73,12 @@ private final CMainControl mainControl; + /** + * The global settings instance. + */ + @NotNull + private final GlobalSettings globalSettings; + /** The edit types instance. */ @NotNull private final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes; @@ -93,13 +100,15 @@ /** * Create the ArchetypeSet. * @param mainControl reference to CMainControl + * @param globalSettings the global settings instance * @param editTypes the edit types instance * @param animationObjects the animations to use * @param faceObjects the FaceObjects instance to use */ - public ArchetypeSet(final CMainControl mainControl, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final AnimationObjects<AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects) { + public ArchetypeSet(@NotNull final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, @NotNull final EditTypes<GameObject, MapArchObject, Archetype, CMapViewBasic> editTypes, @NotNull final AnimationObjects<AnimationObject> animationObjects, @NotNull final FaceObjects faceObjects) { super(mainControl.getGridartaObjectsFactory()); this.mainControl = mainControl; + this.globalSettings = globalSettings; this.editTypes = editTypes; this.animationObjects = animationObjects; this.faceObjects = faceObjects; @@ -159,22 +168,22 @@ final List<GameObject> invObjects = new ArrayList<GameObject>(); final String fname; // here we go... - if (mainControl.getGlobalSettings().isArchLoadedFromCollection()) { + if (globalSettings.isArchLoadedFromCollection()) { loadArchFromCollected(archetypeParser, invObjects); // load arches & images from collection fname = IGUIConstants.ARCH_FILE; } else { FaceObjectProviders.setNormal(new ArchFaceProvider()); setLoadedFromArchive(false); // don't load from the collected files animFiles = new ArrayList<File>(); - addPNGFace(new File(mainControl.getGlobalSettings().getArchDefaultFolder(), "dev/editor/bug.101.png").getAbsolutePath(), "bug.101.png"); - fname = mainControl.getGlobalSettings().getArchDefaultFolder(); + addPNGFace(new File(globalSettings.getArchDefaultFolder(), "dev/editor/bug.101.png").getAbsolutePath(), "bug.101.png"); + fname = globalSettings.getArchDefaultFolder(); loadArchetypesFromFiles(archetypeParser, new File(fname), 0, "default", "default", false, invObjects); // load arches & images from individual files loadAnimsFromFiles(); } reportErrors(mainControl.getMainView()); loadArchesFromArtifacts(archetypeParser, mainControl.getCollectedDirectory() + "/" + IGUIConstants.ARTIFACTS_FILE, "Artifacts", "artifacts", invObjects); - loadArchesFromArtifacts(archetypeParser, mainControl.getGlobalSettings().getMapDefaultFolder(), "Artifacts", "maps", invObjects); + loadArchesFromArtifacts(archetypeParser, globalSettings.getMapDefaultFolder(), "Artifacts", "maps", invObjects); mainControl.getGridartaObjectsFactory().newGameObjectParser().collectTempList(mainControl.getMainView(), this, editTypes, invObjects, fname, true); connectFaces(); // attach faces to arches Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchEditor.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -25,11 +25,14 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.UndefinedEventArchetypeException; import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ScriptArchEditor extends AbstractScriptArchEditor { @@ -39,6 +42,16 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + /** + * The global settings instance. + */ + @Nullable + private static GlobalSettings globalSettings = null; + + public static void setGlobalSettings(@NotNull final GlobalSettings globalSettings) { + ScriptArchEditor.globalSettings = globalSettings; + } + public static boolean createNewEvent(final JDialog frame, final ScriptArchData scriptArchData) { String scriptPath = inputScriptPath.getText().trim(); final String options = inputOptions.getText().trim(); @@ -64,7 +77,7 @@ String absScriptPath; if (scriptPath.startsWith("/")) { // script path is absolute - final File mapDir = new File(AbstractMainControl.getInstance().getGlobalSettings().getMapDefaultFolder()); // global map directory + final File mapDir = new File(globalSettings.getMapDefaultFolder()); // global map directory if (!mapDir.exists()) { // if map dir doesn't exist, this is not going to work frame.setVisible(false); Modified: trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -20,6 +20,7 @@ package daieditor.gui.map; import daieditor.CMainControl; +import daieditor.GlobalSettingsImpl; import daieditor.gameobject.Archetype; import daieditor.gameobject.GameObject; import daieditor.map.MapArchObject; @@ -56,6 +57,7 @@ import net.sf.gridarta.map.MapControl; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.misc.JFileChooserButton; +import org.jetbrains.annotations.NotNull; /** * A dialog to change the properties of a map, like several flags and settings @@ -75,6 +77,12 @@ private final CMainControl mainControl; + /** + * The global settings instance. + */ + @NotNull + private final GlobalSettingsImpl globalSettings; + private final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl; private JDialog dialog = null; @@ -147,14 +155,16 @@ /** * Creates a map-options dialog. * @param mainControl The controller of this dialog. + * @param globalSettings the global settings instance * @param mapControl The level whose properties are shown/edited. * @param mapFileFilter the Swing file filter to use */ - private MapPropertiesDialog(final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { + private MapPropertiesDialog(final CMainControl mainControl, @NotNull final GlobalSettingsImpl globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { okButton.setDefaultCapable(true); setOptions(new Object[] {helpButton, okButton, restoreButton, cancelButton}); this.mainControl = mainControl; + this.globalSettings = globalSettings; this.mapControl = mapControl; final MapArchObject map = mapControl.getMapModel().getMapArchObject(); @@ -164,7 +174,7 @@ final JPanel mainPanel = createMainPanel(map); tabs.add(ACTION_FACTORY.getString("mapMapTabTitle"), mainPanel); - mapTilePane = new MapTilePane(mainControl, mapControl, mapFileFilter); + mapTilePane = new MapTilePane(mainControl, globalSettings, mapControl, mapFileFilter); final JPanel tilePanel = createTilePathPanel(mapTilePane); tabs.add(ACTION_FACTORY.getString("mapTilesTabTitle"), tilePanel); @@ -283,7 +293,7 @@ mapSound.setText(map.getBackgroundMusic()); final JPanel mapSoundPanel = new JPanel(new BorderLayout()); mapSoundPanel.add(mapSound); - mapSoundPanel.add(new JFileChooserButton(new File(mainControl.getGlobalSettings().getMediaDefaultFolder()), mapSound, JFileChooser.FILES_ONLY), BorderLayout.EAST); + mapSoundPanel.add(new JFileChooserButton(new File(globalSettings.getMediaDefaultFolder()), mapSound, JFileChooser.FILES_ONLY), BorderLayout.EAST); mapPanel.add(mapSoundPanel, gbc); mapPanel.add(new JLabel(ACTION_FACTORY.getString("mapWidth")), labelGbc); @@ -548,11 +558,12 @@ * Show a dialog querying the user for map properties. * @param parent the parent component to show dialog on * @param mainControl CMainControl with information + * @param globalSettings the global settings instance * @param level map to show dialog about * @param mapFileFilter the Swing file filter to use */ - public static void showDialog(final Component parent, final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> level, final FileFilter mapFileFilter) { - final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, level, mapFileFilter); + public static void showDialog(final Component parent, final CMainControl mainControl, @NotNull final GlobalSettingsImpl globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> level, final FileFilter mapFileFilter) { + final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, globalSettings, level, mapFileFilter); final JDialog dialog = pane.createDialog(parent, ACTION_FACTORY.format("mapTitle", level.getMapModel().getMapArchObject().getMapDisplayName(), level.getMapFileName())); pane.dialog = dialog; dialog.getRootPane().setDefaultButton(pane.okButton); Modified: trunk/daimonin/src/daieditor/gui/map/MapTilePane.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -25,9 +25,11 @@ import daieditor.map.MapArchObject; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.CommonConstants; +import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.gui.DirectionLayout; import net.sf.gridarta.gui.map.AbstractMapTilePane; import net.sf.gridarta.map.MapControl; +import org.jetbrains.annotations.NotNull; /** * A Panel for managing the tiling of maps. Implementation for 8 tile paths. @@ -104,12 +106,13 @@ * Create a MapTilePane. * @param mainControl CMainControl to use for displaying dialogs, getting * paths etc.. + * @param globalSettings the global settings instance * @param mapControl MapControl of the map that's tiles are to be viewed / * controlled * @param mapFileFilter the Swing file filter to use */ - public MapTilePane(final CMainControl mainControl, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { - super(mainControl, mapControl, tileLink, directionMapping, nextFocus, mapFileFilter); + public MapTilePane(final CMainControl mainControl, @NotNull final GlobalSettings globalSettings, final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl, final FileFilter mapFileFilter) { + super(mainControl, globalSettings, mapControl, tileLink, directionMapping, nextFocus, mapFileFilter); } } // class MapTilePane Modified: trunk/daimonin/src/daieditor/gui/prefs/ResPrefs.java =================================================================== --- trunk/daimonin/src/daieditor/gui/prefs/ResPrefs.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/daimonin/src/daieditor/gui/prefs/ResPrefs.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -19,7 +19,7 @@ package daieditor.gui.prefs; -import daieditor.CMainControl; +import daieditor.GlobalSettingsImpl; import daieditor.ResourceFileManager; import java.awt.Component; import java.awt.Container; @@ -55,8 +55,8 @@ /** Preferences. */ private static final Preferences prefs = Preferences.userNodeForPackage(MainControl.class); - /** Main Control. */ - private final CMainControl mainControl; + /** The global settings instance. */ + private final GlobalSettingsImpl globalSettings; /** TextField for arch directory path. */ private JFileField archField; @@ -75,12 +75,12 @@ /** * Create a ResPrefs pane. - * @param mainControl The controller of this dialog. + * @param globalSettings the global settings instance */ - public ResPrefs(final CMainControl mainControl) { + public ResPrefs(final GlobalSettingsImpl globalSettings) { setListLabelText(ACTION_FACTORY.getString("prefsRes.title")); setListLabelIcon(ACTION_FACTORY.getIcon("prefsRes.icon")); - this.mainControl = mainControl; + this.globalSettings = globalSettings; add(createResourcePanel()); add(createGlobalPanel()); @@ -103,17 +103,17 @@ prefs.put(ResourceFileManager.SCRIPT_DIR_KEY, PathManager.path(scriptField.getText())); prefs.put(ResourceFileManager.MEDIA_DIR_KEY, PathManager.path(mediaField.getText())); prefs.putBoolean(GlobalSettings.LOAD_ARCH_COLL, loadArches.isSelected()); - mainControl.getGlobalSettings().initDirs(); + globalSettings.initDirs(); ACTION_FACTORY.showOnetimeMessageDialog(this, JOptionPane.WARNING_MESSAGE, "optionsRestart"); } /** {@inheritDoc} */ public void revert() { - archField.setText(mainControl.getGlobalSettings().getArchDefaultFolder()); - mapField.setText(mainControl.getGlobalSettings().getMapDefaultFolder()); - scriptField.setText(mainControl.getGlobalSettings().getScriptDefaultFolder()); - mediaField.setText(mainControl.getGlobalSettings().getMediaDefaultFolder()); - loadArches.setSelected(mainControl.getGlobalSettings().isArchLoadedFromCollection()); + archField.setText(globalSettings.getArchDefaultFolder()); + mapField.setText(globalSettings.getMapDefaultFolder()); + scriptField.setText(globalSettings.getScriptDefaultFolder()); + mediaField.setText(globalSettings.getMediaDefaultFolder()); + loadArches.setSelected(globalSettings.isArchLoadedFromCollection()); } /** {@inheritDoc} */ @@ -127,11 +127,11 @@ /** {@inheritDoc} */ public boolean isChanged() { return !( - archField.getText().equals(mainControl.getGlobalSettings().getArchDefaultFolder()) - && mapField.getText().equals(mainControl.getGlobalSettings().getMapDefaultFolder()) - && scriptField.getText().equals(mainControl.getGlobalSettings().getScriptDefaultFolder()) - && mediaField.getText().equals(mainControl.getGlobalSettings().getMediaDefaultFolder()) - && loadArches.isSelected() == prefs.getBoolean(GlobalSettings.LOAD_ARCH_COLL, mainControl.getGlobalSettings().isArchLoadedFromCollection()) + archField.getText().equals(globalSettings.getArchDefaultFolder()) + && mapField.getText().equals(globalSettings.getMapDefaultFolder()) + && scriptField.getText().equals(globalSettings.getScriptDefaultFolder()) + && mediaField.getText().equals(globalSettings.getMediaDefaultFolder()) + && loadArches.isSelected() == prefs.getBoolean(GlobalSettings.LOAD_ARCH_COLL, globalSettings.isArchLoadedFromCollection()) ); } @@ -158,10 +158,10 @@ private Component createResourcePanel() { final Box resourcePanel = Box.createVerticalBox(); resourcePanel.setBorder(createTitledBorder("optionsResPaths")); - archField = createFileField(resourcePanel, "optionsResArch", mainControl.getGlobalSettings().getArchDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); - mapField = createFileField(resourcePanel, "optionsResMaps", mainControl.getGlobalSettings().getMapDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); - scriptField = createFileField(resourcePanel, "optionsResScripts", mainControl.getGlobalSettings().getScriptDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); - mediaField = createFileField(resourcePanel, "optionsResMedia", mainControl.getGlobalSettings().getMediaDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + archField = createFileField(resourcePanel, "optionsResArch", globalSettings.getArchDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + mapField = createFileField(resourcePanel, "optionsResMaps", globalSettings.getMapDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + scriptField = createFileField(resourcePanel, "optionsResScripts", globalSettings.getScriptDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); + mediaField = createFileField(resourcePanel, "optionsResMedia", globalSettings.getMediaDefaultFolder(), JFileChooser.DIRECTORIES_ONLY); return resourcePanel; } @@ -174,9 +174,9 @@ globalPanel.setBorder(createTitledBorder("optionsGlobal")); loadArches = new JCheckBox(ACTION_FACTORY.createToggle(false, "optionsLoadArchColl", this)); - loadArches.setSelected(mainControl.getGlobalSettings().isArchLoadedFromCollection()); + loadArches.setSelected(globalSettings.isArchLoadedFromCollection()); globalPanel.add(loadArches); - if (mainControl.getGlobalSettings().isArchLoadedFromCollection()) { + if (globalSettings.isArchLoadedFromCollection()) { archField.setEnabled(false); } return globalPanel; Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -76,6 +76,12 @@ /** The edit types instance. */ protected final EditTypes<G, A, R, V> editTypes; + /** + * The global settings instance. + */ + @NotNull + protected final GlobalSettings globalSettings; + /** Buffer managing copy data. */ private final CopyBuffer<G, A, R, V> copyBuffer; @@ -101,8 +107,10 @@ * Creates a new instance. * @param gridartaObjectsFactory the gridarta objects factory * @param key The action factory key + * @param globalSettings the global settings instance */ - protected AbstractMainControl(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final String key) { + protected AbstractMainControl(@NotNull final GridartaObjectsFactory<G, A, R, V> gridartaObjectsFactory, @NotNull final String key, @NotNull final GlobalSettings globalSettings) { + this.globalSettings = globalSettings; final DefaultMapManager<G, A, R, V> tmpMapManager = new DefaultMapManager<G, A, R, V>(this, key); editTypes = new EditTypes(tmpMapManager); tmpMapManager.setEditTypes(editTypes); @@ -186,13 +194,13 @@ public File getLocalMapDir() { final MapControl<G, A, R, V> mapControl = mapManager.getCurrentMap(); if (mapControl == null) { - return getGlobalSettings().getMapDir(); + return globalSettings.getMapDir(); } final File mapFile = mapControl.getMapFile(); if (mapFile == null) { ACTION_FACTORY.showMessageDialog(getMainView(), "createNewEventNoMapPath"); - return getGlobalSettings().getMapDir(); + return globalSettings.getMapDir(); } return mapFile.getParentFile(); @@ -208,12 +216,12 @@ /** {@inheritDoc} */ public void createImage(@NotNull final MapView<G, A, R, V> mapView) { - if (getGlobalSettings().getImageDir() == null) { - getGlobalSettings().setImageDir(getGlobalSettings().getMapDir().getAbsolutePath()); + if (globalSettings.getImageDir() == null) { + globalSettings.setImageDir(globalSettings.getMapDir().getAbsolutePath()); } - final File file = new File(getGlobalSettings().getImageDir(), mapView.getMapControl().getMapFileName() + ".png"); - final JFileChooser fileChooser = new JFileChooser(getGlobalSettings().getImageDir()); + final File file = new File(globalSettings.getImageDir(), mapView.getMapControl().getMapFileName() + ".png"); + final JFileChooser fileChooser = new JFileChooser(globalSettings.getImageDir()); fileChooser.setDialogTitle("Save Image As"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); @@ -228,7 +236,7 @@ if (!imageFile.getName().endsWith(".png")) { imageFile = new File(imageFile.getParentFile(), imageFile.getName() + ".png"); } - getGlobalSettings().setImageDir(imageFile.getParentFile().getAbsolutePath()); + globalSettings.setImageDir(imageFile.getParentFile().getAbsolutePath()); if (!imageFile.exists() || ACTION_FACTORY.showConfirmDialog(getMainView(), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, "overwriteOtherFile", imageFile) == JOptionPane.YES_OPTION) { try { mapView.getMapViewBasic().getRenderer().printFullImage(imageFile); Modified: trunk/src/app/net/sf/gridarta/GlobalSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/GlobalSettings.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/src/app/net/sf/gridarta/GlobalSettings.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -63,4 +63,19 @@ void setChangedDir(boolean hasChangedDir); + /** + * Set all global settings from the preferences. + */ + void readGlobalSettings(); + + boolean isAutoPopupDocu(); + + /** {@inheritDoc} */ + void setAutoPopupDocu(boolean autoPopupDocu); + + File getCurrentDir(); + + /** {@inheritDoc} */ + void setCurrentDir(File currentDir); + } // interface GlobalSettings Modified: trunk/src/app/net/sf/gridarta/GlobalSettingsImpl.java =================================================================== --- trunk/src/app/net/sf/gridarta/GlobalSettingsImpl.java 2008-07-31 23:09:40 UTC (rev 4649) +++ trunk/src/app/net/sf/gridarta/GlobalSettingsImpl.java 2008-08-01 19:53:02 UTC (rev 4650) @@ -26,7 +26,7 @@ * Default implementation of {@link GlobalSettings}. * @author Andreas Kirschbaum */ -public class GlobalSettingsImpl implements GlobalSettings { +public abstract class GlobalSettingsImpl implements GlobalSettings { private String archDefaultFolder; @@ -88,10 +88,12 @@ this.scriptDefaultFolder = scriptDefaultFolder; } + /** {@inheritDoc} */ public File getCurrentDir() { return currentDir; } + /** {@inheritDoc} */ public void setCurrentDir(final File currentDir) { ... [truncated message content] |