From: <aki...@us...> - 2008-08-16 07:34:40
|
Revision: 4880 http://gridarta.svn.sourceforge.net/gridarta/?rev=4880&view=rev Author: akirschbaum Date: 2008-08-16 07:34:47 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Move FileControl to common code base. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/crossfire/src/cfeditor/messages_fr.properties trunk/crossfire/src/cfeditor/messages_sv.properties trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties trunk/daimonin/src/daieditor/messages_fr.properties trunk/daimonin/src/daieditor/messages_sv.properties trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Added Paths: ----------- trunk/src/app/net/sf/gridarta/FileControl.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/FileControl.java trunk/daimonin/src/daieditor/FileControl.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2008-08-16 07:34:47 UTC (rev 4880) @@ -52,6 +52,7 @@ import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.EditTypes; +import net.sf.gridarta.FileControl; import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MainControl; @@ -203,7 +204,7 @@ * The file control instance. */ @NotNull - private final FileControl fileControl; + private final FileControl<GameObject, MapArchObject, Archetype, CMapViewBasic> fileControl; /** * Constructs the main controller and its model and view. @@ -368,7 +369,7 @@ } recentManager.initRecent(); new AutoValidator<GameObject, MapArchObject, Archetype, CMapViewBasic>(validators, mapManager, PREFS_VALIDATOR_AUTO_DEFAULT); - fileControl = new FileControl(globalSettings, archetypeSet, mapPreviewAccessory, mapManager, mainView, mapFileFilter, pythonFileFilter, newMapDialogFactory); + fileControl = new FileControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(globalSettings, archetypeSet, mapPreviewAccessory, mapManager, mainView, mapFileFilter, pythonFileFilter, newMapDialogFactory, ".py"); } /** Deleted: trunk/crossfire/src/cfeditor/FileControl.java =================================================================== --- trunk/crossfire/src/cfeditor/FileControl.java 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/FileControl.java 2008-08-16 07:34:47 UTC (rev 4880) @@ -1,232 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package cfeditor; - -import cfeditor.gameobject.Archetype; -import cfeditor.gameobject.GameObject; -import cfeditor.gui.map.CMapViewBasic; -import cfeditor.map.MapArchObject; -import java.awt.Component; -import java.io.File; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.filechooser.FileFilter; -import net.sf.gridarta.GlobalSettings; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.gameobject.ArchetypeSet; -import net.sf.gridarta.gui.map.MapPreviewAccessory; -import net.sf.gridarta.gui.newmap.NewMapDialogFactory; -import net.sf.gridarta.map.MapControl; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class FileControl { - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - /** - * The global settings instance. - */ - @NotNull - private final GlobalSettings globalSettings; - - /** - * The archetype set. - */ - @NotNull - private final ArchetypeSet<?, ?, ?> archetypeSet; - - /** - * The map preview accessory. - */ - @NotNull - private final MapPreviewAccessory mapPreviewAccessory; - - /** - * The map manager. - */ - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - - /** - * The parent component for showing dialog boxes. - */ - @NotNull - private final Component parent; - - /** - * The map file filter. - */ - @NotNull - private final FileFilter mapFileFilter; - - /** - * The script file filter. - */ - @NotNull - private final FileFilter scriptFileFilter; - - /** - * The new map dialog factory. - */ - @NotNull - private final NewMapDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapDialogFactory; - - /** JFileChooser for opening a file. */ - private JFileChooser fileChooser; - - /** - * Creates a new instance. - * @param globalSettings the global settings instance - * @param archetypeSet the archetype set - * @param mapPreviewAccessory the map preview accessory - * @param mapManager the map manager - * @param parent the parent component for showing dialog boxes - * @param mapFileFilter the map file filter - * @param scriptFileFilter the script file filter - * @param newMapDialogFactory the new map dialog factory - */ - public FileControl(@NotNull final GlobalSettings globalSettings, @NotNull final ArchetypeSet<?, ?, ?> archetypeSet, @NotNull final MapPreviewAccessory mapPreviewAccessory, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final Component parent, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final NewMapDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapDialogFactory) { - this.globalSettings = globalSettings; - this.archetypeSet = archetypeSet; - this.mapPreviewAccessory = mapPreviewAccessory; - this.mapManager = mapManager; - this.parent = parent; - this.mapFileFilter = mapFileFilter; - this.scriptFileFilter = scriptFileFilter; - this.newMapDialogFactory = newMapDialogFactory; - } - - /** Create the JFileChooser for opening a file. */ - private void createFileChooser() { - fileChooser = new JFileChooser(); - fileChooser.setDialogTitle(ACTION_FACTORY.getString("fileDialog.title")); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setMultiSelectionEnabled(true); - fileChooser.addChoosableFileFilter(scriptFileFilter); - fileChooser.addChoosableFileFilter(mapFileFilter); - if (globalSettings.getMapDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getMapDir()); - } - mapPreviewAccessory.attachTo(fileChooser); - } - - /** - * The user wants to open a file. The filefilters and preselected filefilter - * are set accordingly to <var>mapFilter</var>. - * @param mapFilter set to <code>true</code> if the user probably wants to - * open a map, <code>false</code> otherwise - */ - public void openFileWanted(final boolean mapFilter) { - if (fileChooser == null) { - createFileChooser(); - } - if (mapFilter) { - fileChooser.setFileFilter(mapFileFilter); - } else { - fileChooser.setFileFilter(scriptFileFilter); - } - final int returnVal = fileChooser.showOpenDialog(parent); - if (returnVal == JFileChooser.APPROVE_OPTION) { - if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { - // ArchStack is empty -> abort! - ACTION_FACTORY.showMessageDialog(parent, "openFileWantedNoArches"); - return; - } - - globalSettings.setChangedDir(true); // user has chosen an active dir - openFiles(fileChooser.getCurrentDirectory(), fileChooser.getSelectedFiles()); - } - } - - /** - * Invoked when user wants to save a map to certain file. - * @param mapControl the map to be saved - * @return <code>true</code> if the user confirmed saving the map and the - * map was saved successfully, otherwise <code>false</code> - */ - public boolean saveLevelAsWanted(@NotNull final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl) { - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Save Map Or Script As"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.resetChoosableFileFilters(); - fileChooser.addChoosableFileFilter(scriptFileFilter); - fileChooser.setFileFilter(mapFileFilter); - - // default folder is the map-folder at first time, then the active folder - if (!globalSettings.hasChangedDir() && globalSettings.getMapDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getMapDir()); - } else if (globalSettings.getCurrentDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getCurrentDir()); - } - - // if file already exists, select it - final File mapFile = mapControl.getMapFile(); - if (mapFile != null && mapFile.exists()) { - fileChooser.setSelectedFile(mapFile); - } else { - fileChooser.setSelectedFile(new File(globalSettings.getMapDir(), mapControl.getMapFileName())); - } - - final int returnVal = fileChooser.showSaveDialog(parent); - if (returnVal != JFileChooser.APPROVE_OPTION) { - return false; - } - - globalSettings.setChangedDir(true); // user has chosen an active dir - final File file = fileChooser.getSelectedFile(); - if (!file.exists() || ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_CANCEL_OPTION, "overwriteOtherFile", file.getName()) == JOptionPane.OK_OPTION) { - mapControl.saveAs(file); - - globalSettings.setCurrentDir(fileChooser.getCurrentDirectory()); - } - return true; - } - - /** - * Load an array of files. - * @param dir directory to load files from - * @param files array of files to load - */ - private void openFiles(final File dir, final File... files) { - for (final File file : files) { - final boolean isScriptFile = file.getName().toLowerCase().endsWith(".py"); - if (file.isFile()) { - if (isScriptFile) { - ScriptEditControlInstance.getInstance().openScriptFile(file.getAbsolutePath()); - } else { - globalSettings.setCurrentDir(dir); - mapManager.openMapFileWithView(file, null); - } - } else if (!file.exists()) { - if (isScriptFile) { - // TODO: pass filename - ScriptEditControlInstance.getInstance().openScriptNew(); - } else { - newMapDialogFactory.showNewMapDialog(file.getName()); - } - } // If neither branch matches, it's a directory - what to do with directories? - } - } - -} // class FileControl Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/messages.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -39,8 +39,6 @@ closeLevelNullLevel.title=Close map closeLevelNullLevel.message=Map does not exist: {1}; number of existing maps: {0}. -openFileWantedNoArches.title=Cannot open map -openFileWantedNoArches.message=There are currently no arches available!\nYou need to have arches loaded before opening a map. openFileLoadMap.title=Cannot open map openFileLoadMap.message=An I/O error occurred while loading {0}:\n{1} openFileOutOfMapBoundsDeleted.title=Loading mapfile {0} @@ -134,7 +132,6 @@ file.text=File file.mnemonic=F -fileDialog.title=Open map or script files createNew.text=New... createNew.shortdescription=Create new map Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -35,8 +35,6 @@ closeLevelNullLevel.title=Kann Karte nicht schlie\xDFen closeLevelNullLevel.message=Die Karte {1} existiert nicht; Anzahl existierender Karten: {0}. -openFileWantedNoArches.title=Kann Karte nicht \xF6ffnen -openFileWantedNoArches.message=Es sind keine Archetypen verf\xFCgbar.\nDiese werden ben\xF6tigt, um eine Karte zu \xF6ffnen. openFileLoadMap.title=Kann Karte nicht \xF6ffnen openFileLoadMap.message=Beim \xD6ffnen der Datei {0} ist ein Ein-/Ausgabefehler aufgetreten:\n{1} openFileOutOfMapBoundsDeleted.title=Karte {0} laden @@ -130,7 +128,6 @@ file.text=Datei file.mnemonic=D -fileDialog.title=Karten- oder Script-Dateien \xF6ffnen createNew.text=Neu... createNew.shortdescription=Erzeuge neue Karte Modified: trunk/crossfire/src/cfeditor/messages_fr.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_fr.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/messages_fr.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -36,8 +36,6 @@ #closeLevelNullLevel.title= #closeLevelNullLevel.message= -#openFileWantedNoArches.title= -#openFileWantedNoArches.message= #openFileLoadMap.title= #openFileLoadMap.message= #openFileOutOfMapBoundsDeleted.title= @@ -131,7 +129,6 @@ file.text=Fichier file.mnemonic=F -fileDialog.title=Ouvrir fichier carte ou script createNew.text=Nouveau createNew.shortdescription=Cr\xE9er une nouvelle carte Modified: trunk/crossfire/src/cfeditor/messages_sv.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_sv.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/crossfire/src/cfeditor/messages_sv.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -34,8 +34,6 @@ closeLevelNullLevel.title=St\xE4ng niv\xE5 closeLevelNullLevel.message=FIND NULL LEVEL : {0} v\xE5r karta: {1}. -openFileWantedNoArches.title=Kan inte \xF6ppna karta -openFileWantedNoArches.message=Det finns inga arketyper (arches) tillg\xE4ngliga!\nDu m\xE5ste ha arketyperna innan du kan \xF6ppna en karta.\nL\xE4s i online-dokumentationen hur du kan skaffa Daimonins arketypfiler.. openFileLoadMap.title=Kunde inte \xF6ppna kartan #openFileLoadMap.message= openFileOutOfMapBoundsDeleted.title=Laddar kartfil {0} @@ -129,7 +127,6 @@ file.text=Arkiv file.mnemonic=A -fileDialog.title=\xD6ppna kart- eller scriptfiler createNew.text=Ny createNew.shortdescription=Ny karta Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-08-16 07:34:47 UTC (rev 4880) @@ -58,6 +58,7 @@ import net.sf.gridarta.AbstractMainControl; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.EditTypes; +import net.sf.gridarta.FileControl; import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.GridartaObjectsFactory; import net.sf.gridarta.MainControl; @@ -259,7 +260,7 @@ * The file control instance. */ @NotNull - private final FileControl fileControl; + private final FileControl<GameObject, MapArchObject, Archetype, CMapViewBasic> fileControl; /** * Constructs the main controller and its model and view. @@ -441,7 +442,7 @@ } recentManager.initRecent(); new AutoValidator<GameObject, MapArchObject, Archetype, CMapViewBasic>(validators, mapManager, PREFS_VALIDATOR_AUTO_DEFAULT); - fileControl = new FileControl(globalSettings, archetypeSet, mapPreviewAccessory, mapManager, mainView, mapFileFilter, luaFileFilter, newMapDialogFactory); + fileControl = new FileControl<GameObject, MapArchObject, Archetype, CMapViewBasic>(globalSettings, archetypeSet, mapPreviewAccessory, mapManager, mainView, mapFileFilter, luaFileFilter, newMapDialogFactory, ".lua"); } /** Deleted: trunk/daimonin/src/daieditor/FileControl.java =================================================================== --- trunk/daimonin/src/daieditor/FileControl.java 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/FileControl.java 2008-08-16 07:34:47 UTC (rev 4880) @@ -1,232 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package daieditor; - -import daieditor.gameobject.Archetype; -import daieditor.gameobject.GameObject; -import daieditor.gui.map.CMapViewBasic; -import daieditor.map.MapArchObject; -import java.awt.Component; -import java.io.File; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.filechooser.FileFilter; -import net.sf.gridarta.GlobalSettings; -import net.sf.gridarta.MapManager; -import net.sf.gridarta.gameobject.ArchetypeSet; -import net.sf.gridarta.gui.map.MapPreviewAccessory; -import net.sf.gridarta.gui.newmap.NewMapDialogFactory; -import net.sf.gridarta.map.MapControl; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; -import net.sf.japi.swing.ActionFactory; -import org.jetbrains.annotations.NotNull; - -public class FileControl { - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - /** - * The global settings instance. - */ - @NotNull - private final GlobalSettings globalSettings; - - /** - * The archetype set. - */ - @NotNull - private final ArchetypeSet<?, ?, ?> archetypeSet; - - /** - * The map preview accessory. - */ - @NotNull - private final MapPreviewAccessory mapPreviewAccessory; - - /** - * The map manager. - */ - @NotNull - private final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager; - - /** - * The parent component for showing dialog boxes. - */ - @NotNull - private final Component parent; - - /** - * The map file filter. - */ - @NotNull - private final FileFilter mapFileFilter; - - /** - * The script file filter. - */ - @NotNull - private final FileFilter scriptFileFilter; - - /** - * The new map dialog factory. - */ - @NotNull - private final NewMapDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapDialogFactory; - - /** JFileChooser for opening a file. */ - private JFileChooser fileChooser; - - /** - * Creates a new instance. - * @param globalSettings the global settings instance - * @param archetypeSet the archetype set - * @param mapPreviewAccessory the map preview accessory - * @param mapManager the map manager - * @param parent the parent component for showing dialog boxes - * @param mapFileFilter the map file filter - * @param scriptFileFilter the script file filter - * @param newMapDialogFactory the new map dialog factory - */ - public FileControl(@NotNull final GlobalSettings globalSettings, @NotNull final ArchetypeSet<?, ?, ?> archetypeSet, @NotNull final MapPreviewAccessory mapPreviewAccessory, @NotNull final MapManager<GameObject, MapArchObject, Archetype, CMapViewBasic> mapManager, @NotNull final Component parent, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final NewMapDialogFactory<GameObject, MapArchObject, Archetype, CMapViewBasic> newMapDialogFactory) { - this.globalSettings = globalSettings; - this.archetypeSet = archetypeSet; - this.mapPreviewAccessory = mapPreviewAccessory; - this.mapManager = mapManager; - this.parent = parent; - this.mapFileFilter = mapFileFilter; - this.scriptFileFilter = scriptFileFilter; - this.newMapDialogFactory = newMapDialogFactory; - } - - /** Create the JFileChooser for opening a file. */ - private void createFileChooser() { - fileChooser = new JFileChooser(); - fileChooser.setDialogTitle(ACTION_FACTORY.getString("fileDialog.title")); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setMultiSelectionEnabled(true); - fileChooser.addChoosableFileFilter(scriptFileFilter); - fileChooser.addChoosableFileFilter(mapFileFilter); - if (globalSettings.getMapDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getMapDir()); - } - mapPreviewAccessory.attachTo(fileChooser); - } - - /** - * The user wants to open a file. The filefilters and preselected filefilter - * are set accordingly to <var>mapFilter</var>. - * @param mapFilter set to <code>true</code> if the user probably wants to - * open a map, <code>false</code> otherwise - */ - public void openFileWanted(final boolean mapFilter) { - if (fileChooser == null) { - createFileChooser(); - } - if (mapFilter) { - fileChooser.setFileFilter(mapFileFilter); - } else { - fileChooser.setFileFilter(scriptFileFilter); - } - final int returnVal = fileChooser.showOpenDialog(parent); - if (returnVal == JFileChooser.APPROVE_OPTION) { - if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { - // ArchStack is empty -> abort! - ACTION_FACTORY.showMessageDialog(parent, "openFileWantedNoArches"); - return; - } - - globalSettings.setChangedDir(true); // user has chosen an active dir - openFiles(fileChooser.getCurrentDirectory(), fileChooser.getSelectedFiles()); - } - } - - /** - * Invoked when user wants to save a map to certain file. - * @param mapControl the map to be saved - * @return <code>true</code> if the user confirmed saving the map and the - * map was saved successfully, otherwise <code>false</code> - */ - public boolean saveLevelAsWanted(@NotNull final MapControl<GameObject, MapArchObject, Archetype, CMapViewBasic> mapControl) { - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Save Map Or Script As"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.resetChoosableFileFilters(); - fileChooser.addChoosableFileFilter(scriptFileFilter); - fileChooser.setFileFilter(mapFileFilter); - - // default folder is the map-folder at first time, then the active folder - if (!globalSettings.hasChangedDir() && globalSettings.getMapDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getMapDir()); - } else if (globalSettings.getCurrentDir().exists()) { - fileChooser.setCurrentDirectory(globalSettings.getCurrentDir()); - } - - // if file already exists, select it - final File mapFile = mapControl.getMapFile(); - if (mapFile != null && mapFile.exists()) { - fileChooser.setSelectedFile(mapFile); - } else { - fileChooser.setSelectedFile(new File(globalSettings.getMapDir(), mapControl.getMapFileName())); - } - - final int returnVal = fileChooser.showSaveDialog(parent); - if (returnVal != JFileChooser.APPROVE_OPTION) { - return false; - } - - globalSettings.setChangedDir(true); // user has chosen an active dir - final File file = fileChooser.getSelectedFile(); - if (!file.exists() || ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_CANCEL_OPTION, "overwriteOtherFile", file.getName()) == JOptionPane.OK_OPTION) { - mapControl.saveAs(file); - - globalSettings.setCurrentDir(fileChooser.getCurrentDirectory()); - } - return true; - } - - /** - * Load an array of files. - * @param dir directory to load files from - * @param files array of files to load - */ - private void openFiles(final File dir, final File... files) { - for (final File file : files) { - final boolean isScriptFile = file.getName().toLowerCase().endsWith(".lua"); - if (file.isFile()) { - if (isScriptFile) { - ScriptEditControlInstance.getInstance().openScriptFile(file.getAbsolutePath()); - } else { - globalSettings.setCurrentDir(dir); - mapManager.openMapFileWithView(file, null); - } - } else if (!file.exists()) { - if (isScriptFile) { - // TODO: pass filename - ScriptEditControlInstance.getInstance().openScriptNew(); - } else { - newMapDialogFactory.showNewMapDialog(file.getName()); - } - } // If neither branch matches, it's a directory - what to do with directories? - } - } - -} // class FileControl Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/messages.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -39,8 +39,6 @@ closeLevelNullLevel.title=Close map closeLevelNullLevel.message=Map does not exist: {1}; number of existing maps: {0}. -openFileWantedNoArches.title=Cannot open map -openFileWantedNoArches.message=There are currently no arches available!\nYou need to have arches loaded before opening a map.\nLook into the online help on how to get Daimonin archfiles. openFileLoadMap.title=Cannot open map openFileLoadMap.message=An I/O error occurred while loading {0}:\n{1} openFileOutOfMapBoundsDeleted.title=Loading mapfile {0} @@ -120,14 +118,6 @@ file.text=File file.mnemonic=F -fileDialog.title=Open map or script files -fileDialog.filter.lua=Lua Scripts -fileDialog.filter.arc=Archetype definitions -fileDialog.filter.anim=Animation definitions -fileDialog.filter.txt=Text Files -fileDialog.filter.text=Text Files -fileDialog.filter.py=Python Scripts -fileDialog.filter.unignored=All supported file types createNew.text=New... createNew.shortdescription=Create new map Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/messages_de.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -39,8 +39,6 @@ closeLevelNullLevel.title=Kann Karte nicht schlie\xDFen closeLevelNullLevel.message=Die Karte {1} existiert nicht; Anzahl existierender Karten: {0}. -openFileWantedNoArches.title=Kann Karte nicht \xF6ffnen -openFileWantedNoArches.message=Es sind keine Archetypen verf\xFCgbar.\nDiese werden ben\xF6tigt, um eine Karte zu \xF6ffnen. openFileLoadMap.title=Kann Karte nicht \xF6ffnen openFileLoadMap.message=Beim \xD6ffnen der Datei {0} ist ein Ein-/Ausgabefehler aufgetreten:\n{1} openFileOutOfMapBoundsDeleted.title=Karte {0} laden @@ -120,14 +118,6 @@ file.text=Datei file.mnemonic=D -fileDialog.title=Karten- oder Script-Dateien \xF6ffnen -fileDialog.filter.lua=Lua-Skripte -fileDialog.filter.arc=Archetypdefinitionen -fileDialog.filter.anim=Animationsdefinitionen -fileDialog.filter.txt=Text-Dateien -fileDialog.filter.text=Text-Dateien -fileDialog.filter.py=Python-Skripte -fileDialog.filter.unignored=Alle Dateien createNew.text=Neu... createNew.shortdescription=Erzeuge neue Karte Modified: trunk/daimonin/src/daieditor/messages_fr.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_fr.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/messages_fr.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -39,8 +39,6 @@ #closeLevelNullLevel.title= #closeLevelNullLevel.message= -#openFileWantedNoArches.title= -#openFileWantedNoArches.message= #openFileLoadMap.title= #openFileLoadMap.message= #openFileOutOfMapBoundsDeleted.title= @@ -121,11 +119,6 @@ file.text=Fichier file.mnemonic=F -fileDialog.title=Ouvrir fichier carte ou script -fileDialog.filter.lua=Scripts lua -#fileDialog.filter.arc= -#fileDialog.filter.anim= -#fileDialog.filter.unignored= createNew.text=Nouveau createNew.shortdescription=Cr\xE9er une nouvelle carte Modified: trunk/daimonin/src/daieditor/messages_sv.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_sv.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/daimonin/src/daieditor/messages_sv.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -39,8 +39,6 @@ closeLevelNullLevel.title=St\xE4ng niv\xE5 closeLevelNullLevel.message=FIND NULL LEVEL : {0} v\xE5r karta: {1}. -openFileWantedNoArches.title=Kan inte \xF6ppna karta -openFileWantedNoArches.message=Det finns inga arketyper (arches) tillg\xE4ngliga!\nDu m\xE5ste ha arketyperna innan du kan \xF6ppna en karta.\nL\xE4s i online-dokumentationen hur du kan skaffa Daimonins arketypfiler.. openFileLoadMap.title=Kunde inte \xF6ppna kartan #openFileLoadMap.message= openFileOutOfMapBoundsDeleted.title=Laddar kartfil {0} @@ -122,11 +120,6 @@ file.text=Arkiv file.mnemonic=A -fileDialog.title=\xD6ppna kart- eller scriptfiler -fileDialog.filter.lua=Luascript -fileDialog.filter.arc=Arketypdefinitioner -fileDialog.filter.anim=Animationdefinitioner -#fileDialog.filter.unignored= createNew.text=Ny createNew.shortdescription=Ny karta Added: trunk/src/app/net/sf/gridarta/FileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/FileControl.java (rev 0) +++ trunk/src/app/net/sf/gridarta/FileControl.java 2008-08-16 07:34:47 UTC (rev 4880) @@ -0,0 +1,238 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta; + +import java.awt.Component; +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileFilter; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gui.map.MapPreviewAccessory; +import net.sf.gridarta.gui.map.MapViewBasic; +import net.sf.gridarta.gui.newmap.NewMapDialogFactory; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControl; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControlInstance; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; + +public class FileControl<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V extends MapViewBasic<G, A, R, V>> { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + + /** + * The global settings instance. + */ + @NotNull + private final GlobalSettings globalSettings; + + /** + * The archetype set. + */ + @NotNull + private final ArchetypeSet<G, A, R> archetypeSet; + + /** + * The map preview accessory. + */ + @NotNull + private final MapPreviewAccessory mapPreviewAccessory; + + /** + * The map manager. + */ + @NotNull + private final MapManager<G, A, R, V> mapManager; + + /** + * The parent component for showing dialog boxes. + */ + @NotNull + private final Component parent; + + /** + * The map file filter. + */ + @NotNull + private final FileFilter mapFileFilter; + + /** + * The script file filter. + */ + @NotNull + private final FileFilter scriptFileFilter; + + /** + * The new map dialog factory. + */ + @NotNull + private final NewMapDialogFactory<G, A, R, V> newMapDialogFactory; + + /** + * The file extension for script files. + */ + @NotNull + private final String scriptExtension; + + /** JFileChooser for opening a file. */ + private JFileChooser fileChooser; + + /** + * Creates a new instance. + * @param globalSettings the global settings instance + * @param archetypeSet the archetype set + * @param mapPreviewAccessory the map preview accessory + * @param mapManager the map manager + * @param parent the parent component for showing dialog boxes + * @param mapFileFilter the map file filter + * @param scriptFileFilter the script file filter + * @param newMapDialogFactory the new map dialog factory + * @param scriptExtension the file extension for script files + */ + public FileControl(@NotNull final GlobalSettings globalSettings, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapPreviewAccessory mapPreviewAccessory, @NotNull final MapManager<G, A, R, V> mapManager, @NotNull final Component parent, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final NewMapDialogFactory<G, A, R, V> newMapDialogFactory, @NotNull final String scriptExtension) { + this.globalSettings = globalSettings; + this.archetypeSet = archetypeSet; + this.mapPreviewAccessory = mapPreviewAccessory; + this.mapManager = mapManager; + this.parent = parent; + this.mapFileFilter = mapFileFilter; + this.scriptFileFilter = scriptFileFilter; + this.newMapDialogFactory = newMapDialogFactory; + this.scriptExtension = scriptExtension; + } + + /** Create the JFileChooser for opening a file. */ + private void createFileChooser() { + fileChooser = new JFileChooser(); + fileChooser.setDialogTitle(ACTION_FACTORY.getString("fileDialog.title")); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setMultiSelectionEnabled(true); + fileChooser.addChoosableFileFilter(scriptFileFilter); + fileChooser.addChoosableFileFilter(mapFileFilter); + if (globalSettings.getMapDir().exists()) { + fileChooser.setCurrentDirectory(globalSettings.getMapDir()); + } + mapPreviewAccessory.attachTo(fileChooser); + } + + /** + * The user wants to open a file. The filefilters and preselected filefilter + * are set accordingly to <var>mapFilter</var>. + * @param mapFilter set to <code>true</code> if the user probably wants to + * open a map, <code>false</code> otherwise + */ + public void openFileWanted(final boolean mapFilter) { + if (fileChooser == null) { + createFileChooser(); + } + if (mapFilter) { + fileChooser.setFileFilter(mapFileFilter); + } else { + fileChooser.setFileFilter(scriptFileFilter); + } + final int returnVal = fileChooser.showOpenDialog(parent); + if (returnVal == JFileChooser.APPROVE_OPTION) { + if (archetypeSet.getLoadStatus() == ArchetypeSet.LoadStatus.EMPTY) { + // ArchStack is empty -> abort! + ACTION_FACTORY.showMessageDialog(parent, "openFileWantedNoArches"); + return; + } + + globalSettings.setChangedDir(true); // user has chosen an active dir + openFiles(fileChooser.getCurrentDirectory(), fileChooser.getSelectedFiles()); + } + } + + /** + * Invoked when user wants to save a map to certain file. + * @param mapControl the map to be saved + * @return <code>true</code> if the user confirmed saving the map and the + * map was saved successfully, otherwise <code>false</code> + */ + public boolean saveLevelAsWanted(@NotNull final MapControl<G, A, R, V> mapControl) { + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Save Map Or Script As"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.resetChoosableFileFilters(); + fileChooser.addChoosableFileFilter(scriptFileFilter); + fileChooser.setFileFilter(mapFileFilter); + + // default folder is the map-folder at first time, then the active folder + if (!globalSettings.hasChangedDir() && globalSettings.getMapDir().exists()) { + fileChooser.setCurrentDirectory(globalSettings.getMapDir()); + } else if (globalSettings.getCurrentDir().exists()) { + fileChooser.setCurrentDirectory(globalSettings.getCurrentDir()); + } + + // if file already exists, select it + final File mapFile = mapControl.getMapFile(); + if (mapFile != null && mapFile.exists()) { + fileChooser.setSelectedFile(mapFile); + } else { + fileChooser.setSelectedFile(new File(globalSettings.getMapDir(), mapControl.getMapFileName())); + } + + final int returnVal = fileChooser.showSaveDialog(parent); + if (returnVal != JFileChooser.APPROVE_OPTION) { + return false; + } + + globalSettings.setChangedDir(true); // user has chosen an active dir + final File file = fileChooser.getSelectedFile(); + if (!file.exists() || ACTION_FACTORY.showConfirmDialog(parent, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_CANCEL_OPTION, "overwriteOtherFile", file.getName()) == JOptionPane.OK_OPTION) { + mapControl.saveAs(file); + + globalSettings.setCurrentDir(fileChooser.getCurrentDirectory()); + } + return true; + } + + /** + * Load an array of files. + * @param dir directory to load files from + * @param files array of files to load + */ + private void openFiles(final File dir, final File... files) { + for (final File file : files) { + final boolean isScriptFile = file.getName().toLowerCase().endsWith(scriptExtension); + if (file.isFile()) { + if (isScriptFile) { + ScriptEditControlInstance.getInstance().openScriptFile(file.getAbsolutePath()); + } else { + globalSettings.setCurrentDir(dir); + mapManager.openMapFileWithView(file, null); + } + } else if (!file.exists()) { + if (isScriptFile) { + // TODO: pass filename + ScriptEditControlInstance.getInstance().openScriptNew(); + } else { + newMapDialogFactory.showNewMapDialog(file.getName()); + } + } // If neither branch matches, it's a directory - what to do with directories? + } + } + +} // class FileControl Property changes on: trunk/src/app/net/sf/gridarta/FileControl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/src/app/net/sf/gridarta/messages.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -988,3 +988,17 @@ #################### # Archetype Chooser editPopup.text=Edit Archetype + + +############## +# File Control +fileDialog.title=Open map or script files +fileDialog.filter.lua=Lua Scripts +fileDialog.filter.arc=Archetype definitions +fileDialog.filter.anim=Animation definitions +fileDialog.filter.txt=Text Files +fileDialog.filter.text=Text Files +fileDialog.filter.py=Python Scripts +fileDialog.filter.unignored=All supported file types +openFileWantedNoArches.title=Cannot open map +openFileWantedNoArches.message=There are currently no archetypes available!\nYou need to have archetypes loaded before opening a map. Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -850,3 +850,17 @@ #################### # Archetype Chooser editPopup.text=Archetyp bearbeiten + + +############## +# File Control +fileDialog.title=Karten- oder Script-Dateien \xF6ffnen +fileDialog.filter.lua=Lua-Skripte +fileDialog.filter.arc=Archetypdefinitionen +fileDialog.filter.anim=Animationsdefinitionen +fileDialog.filter.txt=Text-Dateien +fileDialog.filter.text=Text-Dateien +fileDialog.filter.py=Python-Skripte +fileDialog.filter.unignored=Alle Dateien +openFileWantedNoArches.title=Kann Karte nicht \xF6ffnen +openFileWantedNoArches.message=Es sind keine Archetypen verf\xFCgbar.\nDiese werden ben\xF6tigt, um eine Karte zu \xF6ffnen. Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -849,3 +849,14 @@ #################### # Archetype Chooser #editPopup.text= + + +############## +# File Control +fileDialog.title=Ouvrir fichier carte ou script +fileDialog.filter.lua=Scripts lua +#fileDialog.filter.arc= +#fileDialog.filter.anim= +#fileDialog.filter.unignored= +#openFileWantedNoArches.title= +#openFileWantedNoArches.message= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-08-16 07:12:25 UTC (rev 4879) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2008-08-16 07:34:47 UTC (rev 4880) @@ -853,3 +853,14 @@ #################### # Archetype Chooser #editPopup.text= + + +############## +# File Control +fileDialog.title=\xD6ppna kart- eller scriptfiler +fileDialog.filter.lua=Luascript +fileDialog.filter.arc=Arketypdefinitioner +fileDialog.filter.anim=Animationdefinitioner +#fileDialog.filter.unignored= +openFileWantedNoArches.title=Kan inte \xF6ppna karta +openFileWantedNoArches.message=Det finns inga arketyper (arches) tillg\xE4ngliga!\nDu m\xE5ste ha arketyperna innan du kan \xF6ppna en karta.\nL\xE4s i online-dokumentationen hur du kan skaffa arketypfiler.. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |