20 package net.sf.gridarta.gui.map.renderer;
22 import java.awt.Component;
24 import java.io.IOException;
25 import javax.swing.JFileChooser;
26 import javax.swing.JOptionPane;
35 import net.
sf.japi.swing.action.ActionBuilder;
36 import net.
sf.japi.swing.action.ActionBuilderFactory;
37 import org.jetbrains.annotations.NotNull;
49 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
81 final MapFile mapFile = mapModel.getMapFile();
82 final File file =
new File(volatileSettings.
getImageDirectory(), mapFile == null ?
"image" : mapFile.
getFile().getName() +
".png");
83 final JFileChooser fileChooser =
new JFileChooser(volatileSettings.
getImageDirectory());
84 fileChooser.setDialogTitle(
"Save Image As");
85 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
86 fileChooser.setMultiSelectionEnabled(
false);
87 fileChooser.setSelectedFile(file);
92 final int returnVal = fileChooser.showSaveDialog(component);
93 if (returnVal == JFileChooser.APPROVE_OPTION) {
95 File imageFile = fileChooser.getSelectedFile();
96 if (!imageFile.getName().endsWith(
".png")) {
97 imageFile =
new File(imageFile.getParentFile(), imageFile.getName() +
".png");
100 if (!imageFile.exists() || ACTION_BUILDER.showConfirmDialog(component, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
"overwriteOtherFile", imageFile) == JOptionPane.YES_OPTION) {
103 }
catch (
final IOException ex) {
104 ACTION_BUILDER.showMessageDialog(component,
"createImageIOException", imageFile, ex.getMessage());
A MapModel reflects the data of a map.
Utility class for JFileChooser related functions.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
final ImageCreator< G, A, R > imageCreator
The ImageCreator to forward to.
Base package of all Gridarta classes.
Utility class defining FileFilters.
static final FileFilter PNG_FILE_FILTER
Swing FileFilter for png graphics.
Reflects a game object (object on a map).
GameObjects are the objects based on Archetypes found on maps.
Creates images from map instances.
void setImageDirectory(@NotNull File imageDirectory)
Sets the directory to save created image to.
void createImage(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Component component)
Create an image of a map and save it as a file.
File getImageDirectory()
Returns the directory to save images to.
File getFile()
Returns a File for this map file.
static void sanitizeCurrentDirectory(@NotNull final JFileChooser fileChooser)
Makes sure the current directory of a JFileChooser is valid.
void createImage(@NotNull final MapModel< G, A, R > mapModel, @NotNull final File file)
final VolatileSettings volatileSettings
The VolatileSettings to use.
The location of a map file with a map directory.
Interface for MapArchObjects.
ImageCreator2(@NotNull final VolatileSettings volatileSettings, @NotNull final ImageCreator< G, A, R > imageCreator)
Creates a new instance.
Settings that are not retained across editor restarts.