Package org.jadice.util.swing.icon
Class IconManager
- java.lang.Object
-
- org.jadice.util.swing.icon.IconManager
-
public class IconManager extends Object
TheIconManagermanages a set ofIcons. Icon sets consist of an icon property file in conjunction with an icon image. The icon image may contain a large number of icons in one convenient and efficient image file. The icons may be arranged in a grid-fashion within the image file, but this is not a requirement. The position and size of the icons within the image file is specified through the icon properties.The icon properties file consists of two types of entries:
- extension=png
- image.foo.rectangle=0,0,32,32
The second type of entry specifies the position of a single icon within the icon image as a tuple of coordinates. The coordinates are specified in the format
x, y, width, height. An application may use any number of icon sets. For eact icon set an instance ofIconManagermust be used. The instances of icon managers are managed statically by this class. Individual instances must be retrieved using thegetInstance(Class, String)method.- Author:
- jh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classIconManager.IconManagerIconTheIconimplementation used for icons created by the icon manager.
-
Field Summary
Fields Modifier and Type Field Description static intAUTO_DISABLEFlag indicating that the Icon should automatically draw itself disabled when its enclosing component is disabledstatic intAUTO_ROLLOVERFlag indicating that the Icon should automatically produce a rollover version of itself.static intEFFECT_ALPHA50PIcon effect: make icon 50% transparentstatic intEFFECT_DARKERIcon effect draw icon darkerstatic intEFFECT_GRAYIcon effect: convert to gray (desaturate)static intEFFECT_GRAY50PIcon effect: convert to gray (desaturate) partially (50%)static intEFFECT_LIGHTERIcon effect: draw icon lighterstatic intEFFECT_MORECONTRASTIcon effect: make icon 50% transparentstatic intROTATE_180Rotate the icon by 180 degreesstatic intROTATE_270Rotate the icon by 270 degreesstatic intROTATE_90Rotate the icon by 90 degrees
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BufferedImageapplyOp(BufferedImage src, BufferedImageOp op)Collection<String>getAllKeys()Return all icon keys.intgetAutoDisableFlags()intgetAutoRolloverFlags()IcongetCompositeIcon(String[] layers)Get theIconfor a given set of layers (names of icons representing the layers).IcongetCompositeIcon(String[] layers, int effectFlags, Dimension targetSize)Get theIconfor a given set of layers (names of icons representing the layers) and a set of effect flags scaled to a given dimension.intgetDefaultEffects()IcongetIcon(String name)Get theIconfor a given name.IcongetIcon(String name, int effectFlags)Get theIconfor a given name.IcongetIcon(String name, int effectFlags, Dimension targetSize)Get theIconfor a given name and a set of effect flags scaled to a given dimension.ImagegetImage(String name)Get theImageof an icon instead of the icon itself.ImagegetImage(String name, int effectFlags)Get theImageof an icon instead of the icon itself.protected ImagegetImageForEffect(int effect)Get the image instance for a particular set of effect flags.static IconManagergetInstance(Class<?> loadClass, String iconSetName)Factory method: get an IconManager instance for the specified icon set name.static IconManagergetInstance(String iconSetName)Factory method: get an IconManager instance for the specified icon set name.voidsetAutoDisableFlags(int autoDisableFlags)voidsetAutoRolloverFlags(int autoRolloverFlags)voidsetDefaultEffects(int defaultEffects)
-
-
-
Field Detail
-
AUTO_DISABLE
public static final int AUTO_DISABLE
Flag indicating that the Icon should automatically draw itself disabled when its enclosing component is disabled- See Also:
- Constant Field Values
-
AUTO_ROLLOVER
public static final int AUTO_ROLLOVER
Flag indicating that the Icon should automatically produce a rollover version of itself.- See Also:
- Constant Field Values
-
EFFECT_GRAY
public static final int EFFECT_GRAY
Icon effect: convert to gray (desaturate)- See Also:
- Constant Field Values
-
EFFECT_GRAY50P
public static final int EFFECT_GRAY50P
Icon effect: convert to gray (desaturate) partially (50%)- See Also:
- Constant Field Values
-
EFFECT_LIGHTER
public static final int EFFECT_LIGHTER
Icon effect: draw icon lighter- See Also:
- Constant Field Values
-
EFFECT_DARKER
public static final int EFFECT_DARKER
Icon effect draw icon darker- See Also:
- Constant Field Values
-
EFFECT_ALPHA50P
public static final int EFFECT_ALPHA50P
Icon effect: make icon 50% transparent- See Also:
- Constant Field Values
-
EFFECT_MORECONTRAST
public static final int EFFECT_MORECONTRAST
Icon effect: make icon 50% transparent- See Also:
- Constant Field Values
-
ROTATE_90
public static final int ROTATE_90
Rotate the icon by 90 degrees- See Also:
- Constant Field Values
-
ROTATE_180
public static final int ROTATE_180
Rotate the icon by 180 degrees- See Also:
- Constant Field Values
-
ROTATE_270
public static final int ROTATE_270
Rotate the icon by 270 degrees- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static IconManager getInstance(String iconSetName)
Factory method: get an IconManager instance for the specified icon set name. The icon properties and image are searched for relative to a specified class. The icon set name is supposed to be specified as an absolute name, as no search class name is given with this method.- Parameters:
iconSetName- the name of the icon set- Returns:
- the IconManager or
nullif the icon manager could not be instantiated (e.g. because the file could not be found)
-
getInstance
public static IconManager getInstance(Class<?> loadClass, String iconSetName)
Factory method: get an IconManager instance for the specified icon set name. The set name is extended by an optional theme name retrieved byJadiceThemes.getIconThemeIdentifier(). The icon properties and image are searched for relative to a specified class.- Parameters:
loadClass- the class relative to which to look for the icon properties and image file.iconSetName- the name of the icon set- Returns:
- the IconManager or
nullif the icon manager could not be instantiated (e.g. because the file could not be found)
-
getIcon
public Icon getIcon(String name)
Get theIconfor a given name. The Icon will have no SFX.- Parameters:
name- the icon's name.- Returns:
- the icon or
nullif the icon wasn't found.
-
getIcon
public Icon getIcon(String name, int effectFlags)
Get theIconfor a given name. The Icon will have the specified effects.- Parameters:
name- the icon's name.effectFlags- an ORed combination of a set of effect flags.- Returns:
- the icon or
nullif the icon wasn't found. - See Also:
AUTO_DISABLE,AUTO_ROLLOVER,EFFECT_ALPHA50P,EFFECT_DARKER,EFFECT_LIGHTER,EFFECT_GRAY
-
getIcon
public Icon getIcon(String name, int effectFlags, Dimension targetSize)
Get theIconfor a given name and a set of effect flags scaled to a given dimension.- Parameters:
name- the icon's name.effectFlags- an ORed combination of a set of effect flags.targetSize- the size of the resulting icon- Returns:
- the icon or
nullif the icon wasn't found. - See Also:
AUTO_DISABLE,AUTO_ROLLOVER,EFFECT_ALPHA50P,EFFECT_DARKER,EFFECT_LIGHTER,EFFECT_GRAY
-
getAllKeys
public Collection<String> getAllKeys()
Return all icon keys.- Returns:
- all icon keys
-
getCompositeIcon
public Icon getCompositeIcon(String[] layers, int effectFlags, Dimension targetSize)
Get theIconfor a given set of layers (names of icons representing the layers) and a set of effect flags scaled to a given dimension. The Icon will be composited of the given layers with the first layer specified being the first to be painted, i.e. the layers are specified in back-to-front order.In order to facilitate the usage, entries of the layers array may be
nullin order to leave the layer blank.- Parameters:
layers- the icon's layers.effectFlags- an ORed combination of a set of effect flags.targetSize- the size of the resulting icon- Returns:
- the icon or
nullif the icon wasn't found. - See Also:
AUTO_DISABLE,AUTO_ROLLOVER,EFFECT_ALPHA50P,EFFECT_DARKER,EFFECT_LIGHTER,EFFECT_GRAY
-
getCompositeIcon
public Icon getCompositeIcon(String[] layers)
Get theIconfor a given set of layers (names of icons representing the layers). The Icon will be composited of the given layers with the first layer specified being the first to be painted, i.e. the layers are specified in back-to-front order.In order to facilitate the usage, entries of the layers array may be
nullin order to leave the layer blank.- Parameters:
layers- the icon's layers.- Returns:
- the icon or
nullif the icon wasn't found.
-
getImage
public Image getImage(String name, int effectFlags)
Get theImageof an icon instead of the icon itself.- Parameters:
name- the icon's name.effectFlags- an ORed combination of a set of effect flags.- Returns:
- the image or
nullif the icon wasn't found. - See Also:
AUTO_DISABLE,AUTO_ROLLOVER,EFFECT_ALPHA50P,EFFECT_DARKER,EFFECT_LIGHTER,EFFECT_GRAY
-
getImage
public Image getImage(String name)
Get theImageof an icon instead of the icon itself.- Parameters:
name- the icon's name.- Returns:
- the image or
nullif the icon wasn't found.
-
getImageForEffect
protected Image getImageForEffect(int effect)
Get the image instance for a particular set of effect flags.- Parameters:
effect- an ORed combination of a set of effect flags- Returns:
- the image instance
- See Also:
EFFECT_ALPHA50P,EFFECT_DARKER,EFFECT_LIGHTER,EFFECT_GRAY
-
applyOp
protected BufferedImage applyOp(BufferedImage src, BufferedImageOp op)
-
getAutoDisableFlags
public int getAutoDisableFlags()
-
setAutoDisableFlags
public void setAutoDisableFlags(int autoDisableFlags)
-
getAutoRolloverFlags
public int getAutoRolloverFlags()
-
setAutoRolloverFlags
public void setAutoRolloverFlags(int autoRolloverFlags)
-
getDefaultEffects
public int getDefaultEffects()
-
setDefaultEffects
public void setDefaultEffects(int defaultEffects)
-
-