 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.utils;
22 import java.awt.Image;
23 import java.awt.Toolkit;
24 import java.awt.image.FilteredImageSource;
25 import java.awt.image.ImageFilter;
26 import java.awt.image.ImageProducer;
29 import java.util.HashMap;
31 import java.util.MissingResourceException;
32 import javax.swing.ImageIcon;
33 import org.apache.log4j.Category;
34 import org.apache.log4j.Logger;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
51 private static final String
ICON_DIR =
"icons/";
150 private final Map<String, ImageIcon>
imageCache =
new HashMap<>();
168 public ImageIcon
getResourceIcon(@NotNull
final String iconName)
throws MissingResourceException {
170 final ImageIcon imageIcon =
imageCache.get(iconName);
171 if (imageIcon !=
null) {
172 if (
LOG.isDebugEnabled()) {
173 LOG.debug(
"getResourceIcon(" + iconName +
"): return cached");
178 @NotNull
final ImageIcon icon;
180 final URL iconURL =
ResourceIcons.class.getClassLoader().getResource(iconName);
181 if (iconURL ==
null) {
182 final File iconFile =
new File(iconName);
183 if (!iconFile.exists()) {
184 LOG.warn(
"Cannot find icon '" + iconName +
"'");
185 throw new MissingResourceException(
"missing resource: icon " + iconName,
ResourceIcons.class.getName(), iconName);
188 if (
LOG.isDebugEnabled()) {
189 LOG.debug(
"getResourceIcon(" + iconName +
"): loading from file: " + iconFile);
191 icon =
new ImageIcon(iconFile.getAbsolutePath());
193 if (
LOG.isDebugEnabled()) {
194 LOG.debug(
"getResourceIcon(" + iconName +
"): loading from resource: " + iconURL);
196 icon =
new ImageIcon(iconURL);
208 public void addToCache(@NotNull
final String
name, @NotNull
final ImageIcon imageIcon) {
217 final Image image = sysIcon.getImage();
218 final ImageProducer source = image.getSource();
219 final ImageProducer producer =
new FilteredImageSource(source, alphaFilter);
220 final Image image2 = Toolkit.getDefaultToolkit().createImage(producer);
236 final Image image = sysIcon.getImage();
237 final ImageProducer source = image.getSource();
238 final ImageProducer producer =
new FilteredImageSource(source, alphaFilter);
239 final Image image2 = Toolkit.getDefaultToolkit().createImage(producer);
static final String RUN_PLUGIN_SMALL_ICON
static final String SQUARE_PRE_SELECTED_SQUARE
static final String APP_ICON
Application icon definitions (icon-dir).
static final String SQUARE_SELECTED_SQUARE_EAST
static final String ICON_DIR
The directory that contains the common-use icons.
static final String SQUARE_NO_FACE
static final String AUTO_RUN_SMALL_ICON
final Map< String, ImageIcon > imageCache
Caches image icons.
static final String SQUARE_EMPTY
static final String SQUARE_SELECTED_SQUARE_WEST
ImageIcon warningSquareIcon
static final String SQUARE_SELECTED_SQUARE_SOUTH
static final String CLOSE_TAB_SMALL_ICON
static final String DEFAULT_ICON
The default map icon to use if no icon can be created.
static final String TREASURE_LIST
static final String TREASURE_YES
static final ImageFilter ALPHA_FILTER
The singleton AlphaImageFilter instance for creating transparent images.
static final String FILTER_SMALL_ICON
static final String SQUARE_WARNING
static final Category LOG
The Logger for printing log messages.
ImageIcon lightSquareIcon
static final String SQUARE_CURSOR
static final String SQUARE_UNKNOWN
ImageIcon getResourceIcon(@NotNull final String iconName)
Returns the image icon for the given icon name.
static final String TREASUREONE_LIST
static final String DEFAULT_PREVIEW
The default map preview to use if no icon can be created.
static final String TREASURE_NO
void addToCache(@NotNull final String name, @NotNull final ImageIcon imageIcon)
Add an image to the cache.
ImageIcon getWarningSquareIcon()
static final String SQUARE_SELECTED_SQUARE_NORTH
ImageIcon getLightSquareIcon()
Returns the ImageIcon for highlighting map squares that are affected by nearby light emitting game ob...
Creates ImageIcon instances from resources.
static final String SQUARE_LIGHT
The name of the image for highlighting map squares that are affected by nearby light emitting game ob...
static final String SYSTEM_DIR
The directory that contains the system icons.
Utility class holding the singleton AlphaImageFilter instance.
static final String SQUARE_NO_ARCH
static final String SQUARE_SELECTED_SQUARE