 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.map;
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.Image;
25 import java.beans.PropertyChangeListener;
27 import java.util.prefs.Preferences;
28 import javax.swing.Action;
29 import javax.swing.Icon;
30 import javax.swing.ImageIcon;
31 import javax.swing.JButton;
32 import javax.swing.JComponent;
33 import javax.swing.JFileChooser;
34 import javax.swing.JLabel;
35 import javax.swing.JScrollPane;
36 import javax.swing.SwingConstants;
37 import javax.swing.filechooser.FileView;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import net.
sf.japi.swing.action.ActionMethod;
43 import net.
sf.japi.swing.action.ToggleAction;
44 import org.jetbrains.annotations.NotNull;
45 import org.jetbrains.annotations.Nullable;
63 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
87 private final JLabel
preview =
new JLabel();
129 final PropertyChangeListener propertyChangeListener = evt -> {
130 final String prop = evt.getPropertyName();
131 if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
133 }
else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
134 final File selectedFile = (File) evt.getNewValue();
135 if (selectedFile ==
null) {
139 if (previewImage ==
null) {
145 }
else if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals(prop)) {
149 fileChooser.addPropertyChangeListener(propertyChangeListener);
158 setPreferredSize(
new Dimension(240, 115));
159 setLayout(
new BorderLayout());
161 add(
new JButton(
genPreview), BorderLayout.SOUTH);
162 preview.setHorizontalAlignment(SwingConstants.CENTER);
163 add(
new JScrollPane(
preview), BorderLayout.CENTER);
171 preview.setIcon(image ==
null ?
null :
new ImageIcon(image));
220 for (
final File file :
files) {
259 final Image image =
fileChooser.getCurrentDirectory().equals(f.getParentFile()) ?
getMapIcon(f) :
null;
260 return image ==
null ? super.getIcon(f) :
new ImageIcon(image);
static final Preferences PREFERENCES
Preferences.
Base package of all Gridarta classes.
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
Image getMapIcon(@NotNull final File mapFile)
Get an icon.
final MapImageCache<?, ?, ?> mapImageCache
The cache for map images.
void setAutoGeneratePreviews(final boolean autoGeneratePreviews)
Switch automatic preview generation.
Graphical User Interface of Gridarta.
Image getIcon(@NotNull final File mapFile)
Returns the icon Image for a given map file.
final ToggleAction autoGeneratePreview
ToggleAction for auto-generate preview.
Caches icon and preview images for map files.
boolean isAutoGeneratePreviews()
Get whether to automatically generate previews.
Image getOrCreateIcon(@NotNull final File mapFile)
Returns an icon Image for a given map file.
void setPreview(@Nullable final Image image)
Updates the text and icon of preview.
final JLabel preview
The preview label.
void flush(@NotNull final File mapFile)
Removes the cached images for a map file.
boolean autoGeneratePreviews
Whether previews should be auto-generated.
void setPreview(@NotNull final String text)
Updates the text and icon of preview.
Image getOrCreatePreview(@NotNull final File mapFile)
Returns a preview Image for a given map file.
final JFileChooser fileChooser
The file chooser instance.
void genPreview()
Generate a preview.
FileView for giving icons to map files.
final Action genPreview
Action for generating preview.
static final long serialVersionUID
The serial version UID.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Image getPreview(@NotNull final File mapFile)
Returns a preview Image for a given map file.
MapPreviewAccessory(@NotNull final MapImageCache<?, ?, ?> mapImageCache, @NotNull final JFileChooser fileChooser)
Creates an MapPreviewAccessory.
Image getMapPreview(@NotNull final File mapFile)
Get a preview.
void buildUI()
Build the user interface.
static final String PREFERENCES_AUTO_GENERATE_PREVIEW
Preferences key for automatic preview generation.
File[] selectedFiles
The currently selected files, or.
Icon getIcon(@NotNull final File f)
Interface used as preferences location.