org.base.apps.util.view.swing
Class ImageCreator

java.lang.Object
  extended by org.base.apps.util.view.swing.ImageCreator

public class ImageCreator
extends Object

Provides utility functions for creating ImageIcon s and BufferedImage s for the GUI.

This class is an adapted version of the ImageCreator utility from the JAXB-Workshop Project (and originally found on Kirill Grouchnikov's blog). It is licensed under a Creative Commons License.

This class has been augmented with a couple additional utility functions to indicate status and some javadoc tags for outdated libraries have been commented out.

Author:
Kirill Grouchnikov, Kevan Simpson

Field Summary
static int CLOSE_DIMENSION
           
static int CUBE_DIMENSION
          The dimension of cube in getGradientCubesImage(int, int, Color, Color, int, int)
static Color errorLightColor
          The color for arrows on icons.
static int ICON_DIMENSION
          The default dimension for icons (both width and height).
static Color iconAnnotationColor
          The color for icons that represent Annotation entities.
static Color iconArrowColor
          The color for arrows on icons.
static Color iconClassColor
          The color for icons that represent Class entities.
static Color iconFieldMethodColor
          The color for icons that represent Field or Method entities.
static Color mainDarkColor
          The main dark color for the backgrounds.
static Color mainLightColor
          The main light color for the backgrounds.
static Color mainMidColor
          The main medium color for the backgrounds.
static Color mainUltraDarkColor
          The main ultra-dark color for the backgrounds.
static Color mainUltraLightColor
          The main light color for the backgrounds.
static Color mainUUltraLightColor
          The main light color for the backgrounds.
 
Constructor Summary
ImageCreator()
           
 
Method Summary
static BufferedImage createGradientLine(int width, Color leftColor, Color rightColor, double opacity)
          Creates a one-pixel high gradient image of specified width, opacity and colors of the starting pixel and the ending pixel.
static BufferedImage getArrowImage(Color arrowColor, Color haloColor, int width, boolean isArrowToRight)
          Returns an image that contains an arrow of specified width, direction and color.
static BufferedImage getBackgroundImage(int width, int height, boolean hasStripeTop)
          Returns an image of specified dimensions that has gradient background and an optional gradient separator stripe on its upper border.
static BufferedImage getBackgroundStripedImage(int width, int height, Color lightColor, Color midColor, Color darkColor)
          Returns an image of specified dimensions that has gradient striped background.
static BufferedImage getBlankImage(int width, int height)
          Returns a completely transparent image of specified dimensions.
static Icon getCheckIcon(int dimension)
          Draws a green check in an oval, to use to indicate OK status.
static Icon getCloseIcon(int dimension)
          Creates close image icon of specified dimension.
static Icon getCloseIcon(int dimension, char letter)
          Creates close image icon of specified dimension.
static Icon getColorIcon(int width, int height, Color c)
          Returns a colored image of specified dimensions.
static Icon getEditIcon(int dimension, char letter)
          Creates edit image icon of specified dimension.
static Icon getErrorIcon(int dimension)
          Draws a red error icon in an oval background.
static BufferedImage getGradientCubesImage(int width, int height, Color leftColor, Color rightColor, int transitionStart, int transitionEnd)
          Creates an image with transition area between two colors.
static BufferedImage getGutterMarker(Color themeColor, int width, int height)
          Returns a gutter marker of specified dimensions and theme color.
static BufferedImage getGutterStatusImage(Color themeColor, int dimension)
          Returns a square gutter status image of specified dimensions and theme color.
static Icon getIconChangeFont(Font font1, char letter)
          Retrieves an icon for Change font menu item.
static Icon getIconFontBigger(Font font, char letter)
          Retrieves an icon for Increase font size menu item.
static Icon getIconFontPaint(Font font, char letter)
          Retrieves an icon for Paint in color menu item.
static Icon getIconFontSmaller(Font font, char letter)
          Retrieves an icon for Decrease font size menu item.
static Image getIconImage()
           
static BufferedImage getLeftArrow(Color arrowColor, Color haloColor, int width)
          Returns an image that contains a left-pointing arrow of specified width and color.
static Icon getLetterIconWithArrow(char letter, boolean isCollection, Color backgroundColor, boolean isArrowToRight, Color arrowColor)
          Returns an icon image with specified background that contains a single letter in its center, an arrow in the bottom portion of the icon and an optional marker sign that is shown when isCollection parameter is true.
static Icon getMultiline(String str, int width, Color foregroundColor, Color shadowColor)
          Returns an image of specified width that contains (possibly) multilined representation of the input string.
static BufferedImage getRightArrow(Color color, Color haloColor, int width)
          Returns an image that contains a right-pointing arrow of specified width and color.
static Polygon getRoundedRectangle(Rectangle rect)
          Computes rounded version of the specified rectangle.
static Icon getSingleLetterIcon(char letter, boolean isCollection, Color backgroundColor)
          Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.
static Icon getSingleLetterIcon(char letter, Color foregroundColor, boolean isCollection, Color backgroundColor)
          Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.
static BufferedImage getSingleLetterImage(char letter, boolean isCollection, Color backgroundColor)
          Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.
static BufferedImage getSingleLetterImage(char letter, Color foregroundColor, boolean isCollection, Color backgroundColor)
          Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.
static Icon getTitleImage(int width, int height, String title, Color foregroundColor, Color shadowColor)
          Returns an image of specified dimensions that contains the specified string in big letters.
static Icon overlay(Icon icon1, Icon icon2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainUUltraLightColor

public static final Color mainUUltraLightColor
The main light color for the backgrounds.


mainUltraLightColor

public static final Color mainUltraLightColor
The main light color for the backgrounds.


mainLightColor

public static final Color mainLightColor
The main light color for the backgrounds.


mainMidColor

public static final Color mainMidColor
The main medium color for the backgrounds.


mainDarkColor

public static final Color mainDarkColor
The main dark color for the backgrounds.


mainUltraDarkColor

public static final Color mainUltraDarkColor
The main ultra-dark color for the backgrounds.


iconClassColor

public static final Color iconClassColor
The color for icons that represent Class entities.


iconAnnotationColor

public static final Color iconAnnotationColor
The color for icons that represent Annotation entities.


iconFieldMethodColor

public static final Color iconFieldMethodColor
The color for icons that represent Field or Method entities.


iconArrowColor

public static final Color iconArrowColor
The color for arrows on icons.


errorLightColor

public static final Color errorLightColor
The color for arrows on icons.


ICON_DIMENSION

public static final int ICON_DIMENSION
The default dimension for icons (both width and height).

See Also:
Constant Field Values

CUBE_DIMENSION

public static final int CUBE_DIMENSION
The dimension of cube in getGradientCubesImage(int, int, Color, Color, int, int)

See Also:
Constant Field Values

CLOSE_DIMENSION

public static final int CLOSE_DIMENSION
See Also:
Constant Field Values
Constructor Detail

ImageCreator

public ImageCreator()
Method Detail

getBlankImage

public static BufferedImage getBlankImage(int width,
                                          int height)
Returns a completely transparent image of specified dimensions.

Parameters:
width - Image width.
height - Image height.
Returns:
Completely transparent image of specified dimensions.

getColorIcon

public static Icon getColorIcon(int width,
                                int height,
                                Color c)
Returns a colored image of specified dimensions.

Parameters:
width - Image width.
height - Image height.
Returns:
Completely transparent image of specified dimensions.

getTitleImage

public static Icon getTitleImage(int width,
                                 int height,
                                 String title,
                                 Color foregroundColor,
                                 Color shadowColor)
Returns an image of specified dimensions that contains the specified string in big letters. The resulting image will have gradient background and semi-transparent background for the title. The title will be centered in the center of the image.

Parameters:
width - The width of the output image.
height - The height of the output image.
title - Title string to write on the output image.
Returns:
The resulting image.

getBackgroundStripedImage

public static BufferedImage getBackgroundStripedImage(int width,
                                                      int height,
                                                      Color lightColor,
                                                      Color midColor,
                                                      Color darkColor)
Returns an image of specified dimensions that has gradient striped background.

Parameters:
width - The width of the output image.
height - The height of the output image.
lightColor - The color of the left side of the even stripes.
midColor - The color of the right side of the even stripes and the left side of the odd stripes.
darkColor - The color of the right side of the odd stripes.
Returns:
The resulting image.

getBackgroundImage

public static BufferedImage getBackgroundImage(int width,
                                               int height,
                                               boolean hasStripeTop)
Returns an image of specified dimensions that has gradient background and an optional gradient separator stripe on its upper border.

Parameters:
width - The width of the output image.
height - The height of the output image.
hasStripeTop - if true, a gradient stripe few pixels high is added on the upper border of this image.
Returns:
The resulting image.

getMultiline

public static Icon getMultiline(String str,
                                int width,
                                Color foregroundColor,
                                Color shadowColor)
Returns an image of specified width that contains (possibly) multilined representation of the input string. The resulting image will have a gradient background and semi-transparent background for the text. The input string is broken into a sequence of lines. Each line does not exceed the specified width of the resulting image. The height of the resulting image is computed according to the number of lines.

Parameters:
str - The input string to be shown,.
width - The width of the output image.
Returns:
The resulting image.

getSingleLetterImage

public static BufferedImage getSingleLetterImage(char letter,
                                                 boolean isCollection,
                                                 Color backgroundColor)
Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

Parameters:
letter - The letter to show in the center of the icon. This letter is capitalized if it was not capitalized.
isCollection - If true, a special marker sign is shown in the upper-right portion of the resulting image icon.
backgroundColor - The background color for the resulting image icon.
Returns:
An icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

getSingleLetterImage

public static BufferedImage getSingleLetterImage(char letter,
                                                 Color foregroundColor,
                                                 boolean isCollection,
                                                 Color backgroundColor)
Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

Parameters:
letter - The letter to show in the center of the icon. This letter is capitalized if it was not capitalized.
foregroundColor - The foreground color for drawing the letter.
isCollection - If true, a special marker sign is shown in the upper-right portion of the resulting image icon.
backgroundColor - The background color for the resulting image icon.
Returns:
An icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

getSingleLetterIcon

public static Icon getSingleLetterIcon(char letter,
                                       boolean isCollection,
                                       Color backgroundColor)
Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

Parameters:
letter - The letter to show in the center of the icon. This letter is capitalized if it was not capitalized.
isCollection - If true, a special marker sign is shown in the upper-right portion of the resulting image icon.
backgroundColor - The background color for the resulting image icon.
Returns:
An icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

getSingleLetterIcon

public static Icon getSingleLetterIcon(char letter,
                                       Color foregroundColor,
                                       boolean isCollection,
                                       Color backgroundColor)
Returns an icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

Parameters:
letter - The letter to show in the center of the icon. This letter is capitalized if it was not capitalized.
isCollection - If true, a special marker sign is shown in the upper-right portion of the resulting image icon.
backgroundColor - The background color for the resulting image icon.
Returns:
An icon image with specified background that contains a single letter in its center with optional marker sign that is shown when isCollection parameter is true.

getLetterIconWithArrow

public static Icon getLetterIconWithArrow(char letter,
                                          boolean isCollection,
                                          Color backgroundColor,
                                          boolean isArrowToRight,
                                          Color arrowColor)
Returns an icon image with specified background that contains a single letter in its center, an arrow in the bottom portion of the icon and an optional marker sign that is shown when isCollection parameter is true.

Parameters:
letter - The letter to show in the center of the icon. This letter is capitalized if it was not capitalized.
isCollection - If true, a special marker sign is shown in the upper-right portion of the resulting image icon.
backgroundColor - The background color for the resulting image icon.
isArrowToRight - If true, the arrow will point to the right, otherwise the arrow will point to the left.
arrowColor - The color of the arrow.
Returns:
An icon image with specified background that contains a single letter in its center, an arrow in the bottom portion of the icon and an optional marker sign that is shown when isCollection parameter is true.

getRightArrow

public static BufferedImage getRightArrow(Color color,
                                          Color haloColor,
                                          int width)
Returns an image that contains a right-pointing arrow of specified width and color.

Parameters:
color - Arrow color.
width - Arrow width.
Returns:
An image that contains a right-pointing arrow of specified width and color.

getLeftArrow

public static BufferedImage getLeftArrow(Color arrowColor,
                                         Color haloColor,
                                         int width)
Returns an image that contains a left-pointing arrow of specified width and color.

Parameters:
arrowColor - Arrow color.
width - Arrow width.
Returns:
An image that contains a left-pointing arrow of specified width and color.

getArrowImage

public static BufferedImage getArrowImage(Color arrowColor,
                                          Color haloColor,
                                          int width,
                                          boolean isArrowToRight)
Returns an image that contains an arrow of specified width, direction and color.

Parameters:
arrowColor - Arrow color.
width - Arrow width.
isArrowToRight - If true, the arrow is pointing to the right, otherwise the arrow is pointing to the left.
Returns:
An image that contains a left-pointing arrow of specified width and color.

createGradientLine

public static BufferedImage createGradientLine(int width,
                                               Color leftColor,
                                               Color rightColor,
                                               double opacity)
Creates a one-pixel high gradient image of specified width, opacity and colors of the starting pixel and the ending pixel.

Parameters:
width - The width of the resulting image.
leftColor - The color of the first pixel of the resulting image.
rightColor - The color of the last pixel of the resulting image.
opacity - The opacity of the resulting image (in 0..1 range). The smaller the value, the more transparent the resulting image is.
Returns:
A one-pixel high gradient image of specified width, opacity and colors of the starting pixel and the ending pixel.

getGutterMarker

public static BufferedImage getGutterMarker(Color themeColor,
                                            int width,
                                            int height)
Returns a gutter marker of specified dimensions and theme color. The resulting image is a rectangle with dark border and light filling. The colors of the border and the filling are created based on the input color.

Parameters:
themeColor - Base color for border and filling.
width - Gutter marker width.
height - Gutter marker height.
Returns:
Gutter marker of specified dimensions and theme color.

getGutterStatusImage

public static BufferedImage getGutterStatusImage(Color themeColor,
                                                 int dimension)
Returns a square gutter status image of specified dimensions and theme color. The resulting image is a square with gradient filling and dark and light borders.

Parameters:
themeColor - Base color for borders and filling.
dimension - Width and height of the resulting image.
Returns:
Square gutter status image of specified dimensions and theme color

getCloseIcon

public static Icon getCloseIcon(int dimension)
Creates close image icon of specified dimension.

Parameters:
dimension - The dimension of the resulting square icon.
Returns:
The resulting icon.

getCloseIcon

public static Icon getCloseIcon(int dimension,
                                char letter)
Creates close image icon of specified dimension.

Parameters:
dimension - The dimension of the resulting square icon.
Returns:
The resulting icon.

getEditIcon

public static Icon getEditIcon(int dimension,
                               char letter)
Creates edit image icon of specified dimension.

Parameters:
dimension - The dimension of the resulting square icon.
Returns:
The resulting icon.

getGradientCubesImage

public static BufferedImage getGradientCubesImage(int width,
                                                  int height,
                                                  Color leftColor,
                                                  Color rightColor,
                                                  int transitionStart,
                                                  int transitionEnd)
Creates an image with transition area between two colors. The transition area is specified by the starting and ending columns (in pixel units). The transition area is randomly covered by semi-randomly colored squares.

Parameters:
width - The width of the resilting image.
height - The height of the resilting image.
leftColor - The color on the left side of the resulting image.
rightColor - The color on the right side of the resulting image.
transitionStart - The starting column of the transition area. All the pixels lying to the left of this column will be colored uniformly by the left-side color.
transitionEnd - The ending column of the transition area. All the pixels lying to the right of this column will be colored uniformly by the right-side color.
Returns:
The resulting image.

getIconFontBigger

public static Icon getIconFontBigger(Font font,
                                     char letter)
Retrieves an icon for Increase font size menu item. Contains a single letter with upwards arrow.

Parameters:
font - The font of the letter.
letter - The letter to show.
Returns:
Icon for Increase font size menu item. // * @see org.jvnet.jaxbw.xjcad.MainFrame.MainFrameMenuBar#MainFrameMenuBar(org.jvnet.jaxbw.xjcad.MainFrame) // * @see org.jvnet.jaxbw.xjcad.ViewerPanel#showPopup(int, int)

getIconFontSmaller

public static Icon getIconFontSmaller(Font font,
                                      char letter)
Retrieves an icon for Decrease font size menu item. Contains a single letter with downwards arrow.

Parameters:
font - The font of the letter.
letter - The letter to show.
Returns:
Icon for Decrease font size menu item. // * @see org.jvnet.jaxbw.xjcad.MainFrame.MainFrameMenuBar#MainFrameMenuBar(org.jvnet.jaxbw.xjcad.MainFrame) // * @see org.jvnet.jaxbw.xjcad.ViewerPanel#showPopup(int, int)

getIconFontPaint

public static Icon getIconFontPaint(Font font,
                                    char letter)
Retrieves an icon for Paint in color menu item. Contains two letters, one in gray, another in colored gradient.

Parameters:
font - The font of the letters.
letter - The letter to show.
Returns:
Icon for Paint in color menu item. // * @see org.jvnet.jaxbw.xjcad.MainFrame.MainFrameMenuBar#MainFrameMenuBar(org.jvnet.jaxbw.xjcad.MainFrame) // * @see org.jvnet.jaxbw.xjcad.ViewerPanel#showPopup(int, int)

getIconChangeFont

public static Icon getIconChangeFont(Font font1,
                                     char letter)
Retrieves an icon for Change font menu item. Contains two letters, one in gray, another in black Serif font.

Parameters:
font1 - The font of the first letter.
letter - The letter to show.
Returns:
Icon for Change font menu item. // * @see org.jvnet.jaxbw.xjcad.MainFrame.MainFrameMenuBar#MainFrameMenuBar(org.jvnet.jaxbw.xjcad.MainFrame) // * @see org.jvnet.jaxbw.xjcad.ViewerPanel#showPopup(int, int)

getRoundedRectangle

public static Polygon getRoundedRectangle(Rectangle rect)
Computes rounded version of the specified rectangle.

Parameters:
rect - Rectangle.
Returns:
Rounded version of the specified rectangle.

overlay

public static Icon overlay(Icon icon1,
                           Icon icon2)

getIconImage

public static Image getIconImage()

getCheckIcon

public static Icon getCheckIcon(int dimension)
Draws a green check in an oval, to use to indicate OK status.

Parameters:
dimension - the dimension of the icon.
Returns:
a green check icon.

getErrorIcon

public static Icon getErrorIcon(int dimension)
Draws a red error icon in an oval background.

Parameters:
dimension - The dimension of the icon.
Returns:
an error icon.

Please visit Base Apps, hosted on Sourceforge.net.

Copyright 2011, Blue Agate Software Entity (BASE)