 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.misc;
22 import java.awt.Component;
24 import java.io.IOException;
25 import javax.swing.JFileChooser;
26 import javax.swing.JOptionPane;
27 import javax.swing.filechooser.FileFilter;
46 import net.
sf.japi.swing.action.ActionBuilder;
47 import net.
sf.japi.swing.action.ActionBuilderFactory;
48 import org.jetbrains.annotations.NotNull;
49 import org.jetbrains.annotations.Nullable;
61 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
157 public DefaultFileControl(@NotNull
final ProjectSettings projectSettings, @NotNull
final VolatileSettings volatileSettings, @NotNull
final MapImageCache<G, A, R> mapImageCache, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final MapViewsManager<G, A, R> mapViewsManager, @NotNull
final Component
parent, @NotNull
final FileFilter
mapFileFilter, @NotNull
final FileFilter
scriptFileFilter, @NotNull
final NewMapDialogFactory<G, A, R> newMapDialogFactory, @NotNull
final String
scriptExtension, @NotNull
final ScriptEditControl scriptEditControl, @NotNull
final PathManager pathManager) {
178 final JFileChooser tmpFileChooser =
new JFileChooser();
180 tmpFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
181 tmpFileChooser.setMultiSelectionEnabled(
true);
188 return tmpFileChooser;
199 final int returnVal = tmpFileChooser.showOpenDialog(
parent);
200 if (returnVal != JFileChooser.APPROVE_OPTION) {
204 final File[]
files = tmpFileChooser.getSelectedFiles();
205 for (
final File file :
files) {
206 final boolean isScriptFile = file.getName().toLowerCase().endsWith(
scriptExtension);
213 }
catch (
final IOException ex) {
217 }
else if (!file.exists()) {
229 final MapFile mapFile = mapControl.getMapModel().getMapFile();
230 if (mapFile !=
null) {
233 }
catch (
final IOException ex) {
240 return saveAs(mapControl);
246 if (mapControl.getMapModel().isModified() && !
save(mapControl)) {
256 if (mapControl ==
null) {
279 }
catch (
final IOException ex) {
294 final JFileChooser saveFileChooser =
new JFileChooser();
295 saveFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
296 saveFileChooser.setDialogTitle(
"Save Map Or Script As");
297 saveFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
298 saveFileChooser.setMultiSelectionEnabled(
false);
299 saveFileChooser.resetChoosableFileFilters();
303 final MapFile mapFile = mapControl.getMapModel().getMapFile();
304 final File defaultDir = mapFile ==
null ? null : mapFile.
getFile().getParentFile();
305 if (defaultDir !=
null && defaultDir.exists()) {
307 saveFileChooser.setSelectedFile(mapFile.
getFile());
314 final int returnVal = saveFileChooser.showSaveDialog(
parent);
315 if (returnVal != JFileChooser.APPROVE_OPTION) {
320 final File file = saveFileChooser.getSelectedFile();
321 if (file.exists() &&
ACTION_BUILDER.showConfirmDialog(
parent, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_CANCEL_OPTION,
"overwriteOtherFile", file.getName()) != JOptionPane.OK_OPTION) {
330 if (mapControl.getMapModel().isModified()) {
331 final int result =
ACTION_BUILDER.showConfirmDialog(
parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE,
"confirmSaveChanges", mapControl.getMapModel().getMapArchObject().getMapName());
332 if (result == JOptionPane.YES_OPTION) {
333 if (!
save(mapControl)) {
336 }
else if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
346 final MapFile mapFile = mapControl.getMapModel().getMapFile();
347 assert mapFile !=
null;
352 public void reportSaveError(@NotNull
final File mapFile, @NotNull
final String message) {
357 public void reportLoadError(@Nullable
final File file, @NotNull
final String message) {
358 ACTION_BUILDER.showMessageDialog(
parent,
"openFileLoadMap", file ==
null ?
"<unknown>" : file, message);
362 public void reportOutOfMapBoundsDeleted(@NotNull
final File file,
final int outOfMapBoundsDeleted, @NotNull
final StringBuilder outOfMapBoundsObjects) {
363 ACTION_BUILDER.showMessageDialog(
parent,
"openFileOutOfMapBoundsDeleted", file, outOfMapBoundsDeleted, outOfMapBoundsObjects);
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
Classes for the script editor used within the editor to create and modify Python and Lua scripts.
A MapManager manages all opened maps.
boolean closeAllMaps()
Invoked when the user wants to close all maps.
Base package of all Gridarta classes.
static void setCurrentDirectory(@NotNull final JFileChooser fileChooser, @Nullable final File dir)
Calls JFileChooser#setCurrentDirectory(File).
Abstract base class for MapPreviewAccessories which are used for previewing maps in JFileChoosers.
Standard Edition Runtime Environment README Import and export control rules on cryptographic software vary from country to country The Java Cryptography Java provides two different sets of cryptographic policy files
void openFile(final boolean mapFile)
The user wants to edit a file.
final VolatileSettings volatileSettings
The VolatileSettings.
final MapImageCache< G, A, R > mapImageCache
The MapImageCache.
This class contains methods for converting relative map paths to absolute map paths and vice versa.
Class with constants used in Gridarta and derivates.
final FileFilter scriptFileFilter
The FileFilter for selecting script files.
static void sanitizeCurrentDirectory(@NotNull final JFileChooser fileChooser)
Makes sure the current directory of a JFileChooser is valid.
Reflects a game object (object on a map).
Graphical User Interface of Gridarta.
final ProjectSettings projectSettings
The ProjectSettings.
void reportTeleportCharacterError(@NotNull final String mapPath, @NotNull final String message)
Reports an error while teleporting a character to the current map.
List< MapControl< G, A, R > > getOpenedMaps()
Returns all opened maps.
final PathManager pathManager
The PathManager for creating MapFile instances.
void reportSaveError(@NotNull final MapControl< G, A, R > mapControl, @NotNull final String message)
Reports an error while saving a map file to the user.
final String scriptExtension
The file extension for script files.
final NewMapDialogFactory< G, A, R > newMapDialogFactory
The NewMapDialogFactory.
Caches icon and preview images for map files.
GameObjects are the objects based on Archetypes found on maps.
void showNewMapDialog()
Shows a dialog for creating a new map.
final ScriptEditControl scriptEditControl
The ScriptEditControl to forward to.
File saveMapAs(@NotNull final MapControl< G, A, R > mapControl)
Displays a "save as" dialog.
boolean confirmSaveChanges(@NotNull final MapControl< G, A, R > mapControl)
Asks the user whether to save changes of a map.
boolean save(@NotNull final MapControl< G, A, R > mapControl)
Save one map.
Interface for MapArchObjects.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
File getFile()
Returns a File for this map file.
final FileFilter mapFileFilter
The FileFilter for selecting map files.
boolean saveAs(@NotNull final MapControl< G, A, R > mapControl)
Asks the user for a filename, then saves the map.
JFileChooser fileChooser
The JFileChooser for opening a file.
Utility class to create NewMapDialog instances.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
JFileChooser createFileChooser()
Creates the JFileChooser for opening a file.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
The location of a map file with a map directory.
void openScriptFile(@NotNull final File file)
Opens a script file.
Reading and writing of maps, handling of paths.
Settings that apply to a project.
final MapManager< G, A, R > mapManager
The MapManager.
ScriptEditControl - Manages events and data flow for the script editor entity.
void reportSaveError(@NotNull final File mapFile, @NotNull final String message)
Reports an error while saving a map file to the user.
Settings that are not retained across editor restarts.
Base classes for rendering maps.
Utility class for JFileChooser related functions.
void setCurrentSaveMapDirectory(@NotNull File currentSaveMapDirectory)
Sets the default directory for saving maps.
DefaultFileControl(@NotNull final ProjectSettings projectSettings, @NotNull final VolatileSettings volatileSettings, @NotNull final MapImageCache< G, A, R > mapImageCache, @NotNull final MapManager< G, A, R > mapManager, @NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final Component parent, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final NewMapDialogFactory< G, A, R > newMapDialogFactory, @NotNull final String scriptExtension, @NotNull final ScriptEditControl scriptEditControl, @NotNull final PathManager pathManager)
Creates a new instance.
void reportOutOfMemory(@NotNull final File file)
MapControl< G, A, R > getOpenMap()
Returns one open map.
Currently nothing more than a marker interface for unification.
Utility class for ActionBuilder related functions.
Default FileControl implementation.
static final String DEFAULT_MAP_FILENAME
Default file name for new maps.
void saveAllMaps()
Saves all maps.
final Component parent
The parent component for showing dialog boxes.
File getMapsDirectory()
Returns the default maps directory.
MapView< G, A, R > openMapFileWithView(@NotNull final MapFile mapFile, @Nullable final Point viewPosition)
Loads a map file and creates a map view.
void reportLoadError(@Nullable final File file, @NotNull final String message)
Stores all existing MapViews.
File getCurrentSaveMapDirectory()
Returns the default directory for saving maps.
void reportOutOfMapBoundsDeleted(@NotNull final File file, final int outOfMapBoundsDeleted, @NotNull final StringBuilder outOfMapBoundsObjects)
void newScript()
Open a new empty script document.
void closeMap(@NotNull MapControl< G, A, R > mapControl)
Closes the given map, ignoring modified status.