org.jdesktop.swingx.plaf.nimbus
Class NimbusGraphicsUtils

java.lang.Object
  extended by javax.swing.plaf.synth.SynthGraphicsUtils
      extended by org.jdesktop.swingx.plaf.nimbus.NimbusGraphicsUtils

public class NimbusGraphicsUtils
extends javax.swing.plaf.synth.SynthGraphicsUtils

NimbusGraphicsUtils - extends SynthGraphicsUtils to force all Synth painted text to be antialiased and provides some static helper methods.

Author:
Created by Jasper Potts (Jan 4, 2007)

Constructor Summary
NimbusGraphicsUtils()
           
 
Method Summary
static java.awt.image.BufferedImage createColorMaskImage(java.awt.image.BufferedImage alpha, java.awt.Color c)
          Creates and returns a new color image filled with color c and with alpha channel alpha.
static java.awt.image.BufferedImage createCompatibleTranslucentImage(int width, int height)
          Returns a new translucent compatible image of the specified width and height.
static java.awt.image.BufferedImage getAlphaMask(java.awt.image.BufferedImage srcImg, int dstWidth, int dstHeight)
          Extract the alpha channel from a image as a greyscale image
static java.awt.Color getMidWebColor(java.lang.String c1, java.lang.String c2)
          Get a Color that is 50% inbetween the two web colors given.
static java.awt.RenderingHints getRenderingHints(java.awt.Graphics2D g2d, java.util.Map<?,?> hintsToSave, java.awt.RenderingHints savedHints)
          Get rendering hints from a Graphics instance.
static java.awt.image.Kernel[] getSeparateGaussianKernel(int radius)
          Generate a pair of 1D Gaussian kernels
static java.awt.Color getWebColor(java.lang.String c)
          Get a Color object from a web color string of the form "FF00AB" or "#FF00AB".
static java.awt.image.BufferedImage loadImage(java.lang.String imgName)
          Load an image using ImageIO from resource in org.jdesktop.swingx.plaf.nimbus.images.
 void paintText(javax.swing.plaf.synth.SynthContext ss, java.awt.Graphics g, java.lang.String text, int x, int y, int mnemonicIndex)
          Overrides paintText in SynthGraphicsUtils to force all Synth painted text to be antialiased
 
Methods inherited from class javax.swing.plaf.synth.SynthGraphicsUtils
computeStringWidth, drawLine, drawLine, getMaximumCharHeight, getMaximumSize, getMinimumSize, getPreferredSize, layoutText, paintText, paintText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NimbusGraphicsUtils

public NimbusGraphicsUtils()
Method Detail

getRenderingHints

public static java.awt.RenderingHints getRenderingHints(java.awt.Graphics2D g2d,
                                                        java.util.Map<?,?> hintsToSave,
                                                        java.awt.RenderingHints savedHints)
Get rendering hints from a Graphics instance. "hintsToSave" is a Map of RenderingHint key-values. For each hint key present in that map, the value of that hint is obtained from the Graphics and stored as the value for the key in savedHints.

Parameters:
g2d - the graphics surface
hintsToSave - the list of rendering hints to set on the graphics
savedHints - a set where to save the previous rendering hints, might be null
Returns:
the previous set of rendering hints

paintText

public void paintText(javax.swing.plaf.synth.SynthContext ss,
                      java.awt.Graphics g,
                      java.lang.String text,
                      int x,
                      int y,
                      int mnemonicIndex)
Overrides paintText in SynthGraphicsUtils to force all Synth painted text to be antialiased

Overrides:
paintText in class javax.swing.plaf.synth.SynthGraphicsUtils

loadImage

public static java.awt.image.BufferedImage loadImage(java.lang.String imgName)
Load an image using ImageIO from resource in org.jdesktop.swingx.plaf.nimbus.images. Catches and prints all Exceptions so that it can safely be used in a static context.

Parameters:
imgName - The name of the image to load, eg. "border.png"
Returns:
The loaded image

getWebColor

public static java.awt.Color getWebColor(java.lang.String c)
Get a Color object from a web color string of the form "FF00AB" or "#FF00AB".

Parameters:
c - The color string
Returns:
The Color described

getMidWebColor

public static java.awt.Color getMidWebColor(java.lang.String c1,
                                            java.lang.String c2)
Get a Color that is 50% inbetween the two web colors given. The Web colors are of the form "FF00AB" or "#FF00AB".

Parameters:
c1 - The first color string
c2 - The second color string
Returns:
The Color middle color

createCompatibleTranslucentImage

public static java.awt.image.BufferedImage createCompatibleTranslucentImage(int width,
                                                                            int height)

Returns a new translucent compatible image of the specified width and height.

Parameters:
width - the width of the new image
height - the height of the new image
Returns:
a new translucent compatible BufferedImage of the specified width and height

getAlphaMask

public static java.awt.image.BufferedImage getAlphaMask(java.awt.image.BufferedImage srcImg,
                                                        int dstWidth,
                                                        int dstHeight)
Extract the alpha channel from a image as a greyscale image

Parameters:
srcImg - the source image
dstWidth - The width of the destintaion, allows padding to be added to alpha
dstHeight - The height of the destintaion, allows padding to be added to alpha
Returns:
new greyscale image with the alpha channel from srcImg in the center

createColorMaskImage

public static java.awt.image.BufferedImage createColorMaskImage(java.awt.image.BufferedImage alpha,
                                                                java.awt.Color c)
Creates and returns a new color image filled with color c and with alpha channel alpha.

Parameters:
alpha - The alpha channel for the new image
c - The fill color
Returns:
New image filled with c and with alpha channel alpha

getSeparateGaussianKernel

public static java.awt.image.Kernel[] getSeparateGaussianKernel(int radius)
Generate a pair of 1D Gaussian kernels

Parameters:
radius - the blur radius
Returns:
array containg horizontal and vertical kernels