org.jivesoftware.spark.util
Class GraphicUtils

java.lang.Object
  extended by org.jivesoftware.spark.util.GraphicUtils

public final class GraphicUtils
extends java.lang.Object

GraphicsUtils class defines common user-interface related utility functions.


Field Summary
protected static java.awt.Component component
           
static java.awt.Cursor DEFAULT_CURSOR
          The default Text Cursor.
static java.awt.Cursor HAND_CURSOR
          The default Hand cursor.
static java.awt.Color SELECTION_COLOR
           
static java.awt.Color TOOLTIP_COLOR
           
protected static java.awt.MediaTracker tracker
           
 
Method Summary
static void centerWindowOnComponent(java.awt.Window window, java.awt.Component over)
          Centers the window over a component (usually another window).
static void centerWindowOnScreen(java.awt.Window window)
          Sets the location of the specified window so that it is centered on screen.
static java.awt.image.BufferedImage convert(java.awt.Image im)
           
static javax.swing.ImageIcon createImageIcon(java.awt.Image image)
           
static javax.swing.ImageIcon createShadowPicture(java.awt.Image buf)
           
static java.lang.String createToolTip(java.lang.String text)
           
static java.lang.String createToolTip(java.lang.String text, int width)
           
static void drawHighlightBorder(java.awt.Graphics g, int x, int y, int width, int height, boolean raised, java.awt.Color shadow, java.awt.Color highlight)
          Draws a single-line highlight border rectangle.
static java.awt.Component focusComponentOrChild(java.awt.Component c)
          Puts the focus on the first component in the tree of c that can accept the focus.
static java.awt.Component focusComponentOrChild(java.awt.Component c, boolean deepest)
          Puts the focus on the first component in the tree of c that can accept the focus.
static byte[] getBytesFromImage(java.awt.Image image)
           
static java.awt.Component getFocusableComponentOrChild(java.awt.Component c)
          Deprecated. replaced by getFocusableComponentOrChild(Component,boolean)
static java.awt.Component getFocusableComponentOrChild(java.awt.Component c, boolean deepest)
          Returns the first component in the tree of c that can accept the focus.
static java.awt.Insets getHighlightBorderInsets()
          Return the amount of space taken up by a highlight border drawn by drawHighlightBorder().
static java.lang.String getHighlightedWords(java.lang.String text, java.lang.String query)
           
static javax.swing.Icon getIcon(java.io.File file)
          Returns the native icon, if one exists for the filetype, otherwise returns a default document icon.
static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup, int x, int y)
          Returns a point where the given popup menu should be shown.
static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup, java.awt.event.MouseEvent event)
          Returns a point where the given popup menu should be shown.
static java.awt.Rectangle[] getScreenBounds()
           
static boolean isAncestorOfFocusedComponent(java.awt.Component c)
           
static void load(java.awt.Image image)
           
static java.awt.Image loadFromResource(java.lang.String imageName, java.lang.Class cls)
          Loads an Image named imageName as a resource relative to the Class cls.
static java.awt.Image makeColorTransparent(java.awt.Image im, java.awt.Color color)
           
static void makeSameSize(javax.swing.JComponent[] comps)
           
static java.awt.image.BufferedImage removeTransparency(java.awt.Image image)
           
static javax.swing.ImageIcon scale(javax.swing.ImageIcon icon, int newHeight, int newWidth)
          Returns a scaled down image if the height or width is smaller than the image size.
static javax.swing.ImageIcon scaleImageIcon(javax.swing.ImageIcon icon, int newHeight, int newWidth)
          Returns a scaled down image if the height or width is smaller than the image size.
static java.lang.String toHTMLColor(java.awt.Color c)
          Return the hexidecimal color from a java.awt.Color
static java.awt.Image toImage(java.awt.image.BufferedImage bufferedImage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTION_COLOR

public static final java.awt.Color SELECTION_COLOR

TOOLTIP_COLOR

public static final java.awt.Color TOOLTIP_COLOR

component

protected static final java.awt.Component component

tracker

protected static final java.awt.MediaTracker tracker

HAND_CURSOR

public static final java.awt.Cursor HAND_CURSOR
The default Hand cursor.


DEFAULT_CURSOR

public static final java.awt.Cursor DEFAULT_CURSOR
The default Text Cursor.

Method Detail

centerWindowOnScreen

public static void centerWindowOnScreen(java.awt.Window window)
Sets the location of the specified window so that it is centered on screen.

Parameters:
window - The window to be centered.

drawHighlightBorder

public static void drawHighlightBorder(java.awt.Graphics g,
                                       int x,
                                       int y,
                                       int width,
                                       int height,
                                       boolean raised,
                                       java.awt.Color shadow,
                                       java.awt.Color highlight)
Draws a single-line highlight border rectangle.

Parameters:
g - The graphics context to use for drawing.
x - The left edge of the border.
y - The top edge of the border.
width - The width of the border.
height - The height of the border.
raised - true if the border is to be drawn raised, false if lowered.
shadow - The shadow color for the border.
highlight - The highlight color for the border.
See Also:
EtchedBorder

getHighlightBorderInsets

public static java.awt.Insets getHighlightBorderInsets()
Return the amount of space taken up by a highlight border drawn by drawHighlightBorder().

Returns:
The Insets needed for the highlight border.
See Also:
drawHighlightBorder(java.awt.Graphics, int, int, int, int, boolean, java.awt.Color, java.awt.Color)

createImageIcon

public static javax.swing.ImageIcon createImageIcon(java.awt.Image image)

getPopupMenuShowPoint

public static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup,
                                                   java.awt.event.MouseEvent event)
Returns a point where the given popup menu should be shown. The point is calculated by adjusting the X and Y coordinates from the given mouse event so that the popup menu will not be clipped by the screen boundaries.

Parameters:
popup - the popup menu
event - the mouse event
Returns:
the point where the popup menu should be shown

getPopupMenuShowPoint

public static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup,
                                                   int x,
                                                   int y)
Returns a point where the given popup menu should be shown. The point is calculated by adjusting the X and Y coordinates so that the popup menu will not be clipped by the screen boundaries.

Parameters:
popup - the popup menu
x - the x position in screen coordinate
y - the y position in screen coordinates
Returns:
the point where the popup menu should be shown in screen coordinates

centerWindowOnComponent

public static void centerWindowOnComponent(java.awt.Window window,
                                           java.awt.Component over)
Centers the window over a component (usually another window). The window must already have been sized.


isAncestorOfFocusedComponent

public static boolean isAncestorOfFocusedComponent(java.awt.Component c)
Returns:
returns true if the component of one of its child has the focus

getFocusableComponentOrChild

public static java.awt.Component getFocusableComponentOrChild(java.awt.Component c)
Deprecated. replaced by getFocusableComponentOrChild(Component,boolean)

Returns the first component in the tree of c that can accept the focus.

Parameters:
c - the root of the component hierarchy to search
See Also:
focusComponentOrChild(java.awt.Component)

getFocusableComponentOrChild

public static java.awt.Component getFocusableComponentOrChild(java.awt.Component c,
                                                              boolean deepest)
Returns the first component in the tree of c that can accept the focus.

Parameters:
c - the root of the component hierarchy to search
deepest - if deepest is true the method will return the first and deepest component that can accept the focus. For example, if both a child and its parent are focusable and deepest is true, the child is returned.
See Also:
focusComponentOrChild(java.awt.Component)

focusComponentOrChild

public static java.awt.Component focusComponentOrChild(java.awt.Component c)
Puts the focus on the first component in the tree of c that can accept the focus.

See Also:
getFocusableComponentOrChild(java.awt.Component)

focusComponentOrChild

public static java.awt.Component focusComponentOrChild(java.awt.Component c,
                                                       boolean deepest)
Puts the focus on the first component in the tree of c that can accept the focus.

Parameters:
c - the root of the component hierarchy to search
deepest - if deepest is true the method will focus the first and deepest component that can accept the focus. For example, if both a child and its parent are focusable and deepest is true, the child is focused.
See Also:
getFocusableComponentOrChild(java.awt.Component)

loadFromResource

public static java.awt.Image loadFromResource(java.lang.String imageName,
                                              java.lang.Class cls)
Loads an Image named imageName as a resource relative to the Class cls. If the Image can not be loaded, then null is returned. Images loaded here will be added to an internal cache based upon the full URL to their location.

This method replaces legacy code from JDeveloper 3.x and earlier.

See Also:
Class.getResource(String), Toolkit.createImage(URL)

getScreenBounds

public static java.awt.Rectangle[] getScreenBounds()

makeSameSize

public static final void makeSameSize(javax.swing.JComponent[] comps)

toHTMLColor

public static final java.lang.String toHTMLColor(java.awt.Color c)
Return the hexidecimal color from a java.awt.Color

Parameters:
c -
Returns:
hexadecimal string

createToolTip

public static final java.lang.String createToolTip(java.lang.String text,
                                                   int width)

createToolTip

public static final java.lang.String createToolTip(java.lang.String text)

getHighlightedWords

public static final java.lang.String getHighlightedWords(java.lang.String text,
                                                         java.lang.String query)

createShadowPicture

public static javax.swing.ImageIcon createShadowPicture(java.awt.Image buf)

removeTransparency

public static java.awt.image.BufferedImage removeTransparency(java.awt.Image image)

toImage

public static java.awt.Image toImage(java.awt.image.BufferedImage bufferedImage)

convert

public static java.awt.image.BufferedImage convert(java.awt.Image im)
                                            throws java.lang.InterruptedException,
                                                   java.io.IOException
Throws:
java.lang.InterruptedException
java.io.IOException

makeColorTransparent

public static java.awt.Image makeColorTransparent(java.awt.Image im,
                                                  java.awt.Color color)

load

public static void load(java.awt.Image image)
                 throws java.lang.InterruptedException,
                        java.io.IOException
Throws:
java.lang.InterruptedException
java.io.IOException

getBytesFromImage

public static byte[] getBytesFromImage(java.awt.Image image)

scaleImageIcon

public static javax.swing.ImageIcon scaleImageIcon(javax.swing.ImageIcon icon,
                                                   int newHeight,
                                                   int newWidth)
Returns a scaled down image if the height or width is smaller than the image size.

Parameters:
icon - the image icon.
newHeight - the preferred height.
newWidth - the preferred width.
Returns:
the icon.

scale

public static javax.swing.ImageIcon scale(javax.swing.ImageIcon icon,
                                          int newHeight,
                                          int newWidth)
Returns a scaled down image if the height or width is smaller than the image size.

Parameters:
icon - the image icon.
newHeight - the preferred height.
newWidth - the preferred width.
Returns:
the icon.

getIcon

public static javax.swing.Icon getIcon(java.io.File file)
Returns the native icon, if one exists for the filetype, otherwise returns a default document icon.

Parameters:
file - the file to check icon type.
Returns:
the native icon, otherwise default document icon.