public final class GraphicUtils
extends java.lang.Object
GraphicsUtils
class defines common user-interface related
utility functions.Modifier and Type | Field and Description |
---|---|
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 |
Modifier and Type | Method and Description |
---|---|
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)
Converting an
Image into a BufferedImage Transparency
some Images gets lost |
static javax.swing.ImageIcon |
createImageIcon(java.awt.Image image)
Creates an ImageIcon from an Image
|
static javax.swing.ImageIcon |
createShadowPicture(java.awt.Image buf)
Creates an
ImageIcon with a Shadow |
static java.lang.String |
createToolTip(java.lang.String text)
Creates a Tooltop
|
static java.lang.String |
createToolTip(java.lang.String text,
int width)
Creates a Tooltip with specified 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 javax.swing.ImageIcon |
fitToSquare(javax.swing.ImageIcon icon,
int newSize)
Scale an image to fit in a square of the given size, preserving aspect
ratio.
|
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 java.awt.image.BufferedImage |
getBufferedImage(java.io.File file)
Converts a File holding an Image into a Buffered Image
|
static byte[] |
getBytesFromImage(java.io.File file)
Gets the Bytes from an Image using an FileInputStream
|
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)
Highlights Words
|
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()
Returns the ScreenBounds
|
static boolean |
isAncestorOfFocusedComponent(java.awt.Component c) |
static void |
load(java.awt.Image image)
Loading an image via a MediaTracker
|
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 void |
makeSameSize(javax.swing.JComponent... comps)
Makes all Compontens the same Size
|
static java.awt.image.BufferedImage |
removeTransparency(java.awt.Image image)
removes the Transparency of an
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)
Converts a
BufferedImage to Image |
public static final java.awt.Color SELECTION_COLOR
public static final java.awt.Color TOOLTIP_COLOR
protected static final java.awt.Component component
protected static final java.awt.MediaTracker tracker
public static final java.awt.Cursor HAND_CURSOR
public static final java.awt.Cursor DEFAULT_CURSOR
public static void centerWindowOnScreen(java.awt.Window window)
window
- The window to be centered.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)
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.EtchedBorder
public static java.awt.Insets getHighlightBorderInsets()
drawHighlightBorder()
.Insets
needed for the highlight border.drawHighlightBorder(java.awt.Graphics, int, int, int, int, boolean, java.awt.Color, java.awt.Color)
public static javax.swing.ImageIcon createImageIcon(java.awt.Image image)
image
- Image
ImageIcon
public static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup, java.awt.event.MouseEvent event)
popup
- the popup menuevent
- the mouse eventpublic static java.awt.Point getPopupMenuShowPoint(javax.swing.JPopupMenu popup, int x, int y)
popup
- the popup menux
- the x position in screen coordinatey
- the y position in screen coordinatespublic static void centerWindowOnComponent(java.awt.Window window, java.awt.Component over)
window
- Window to center.over
- Component to center over.public static boolean isAncestorOfFocusedComponent(java.awt.Component c)
c
- Component to check on.public static java.awt.Component getFocusableComponentOrChild(java.awt.Component c)
getFocusableComponentOrChild(Component,boolean)
c
that can accept
the focus.c
- the root of the component hierarchy to searchfocusComponentOrChild(java.awt.Component)
public static java.awt.Component getFocusableComponentOrChild(java.awt.Component c, boolean deepest)
c
that can accept
the focus.c
- the root of the component hierarchy to searchdeepest
- 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.focusComponentOrChild(java.awt.Component)
public static java.awt.Component focusComponentOrChild(java.awt.Component c)
c
that
can accept the focus.c
- Component to focus on.getFocusableComponentOrChild(java.awt.Component)
public static java.awt.Component focusComponentOrChild(java.awt.Component c, boolean deepest)
c
that
can accept the focus.c
- the root of the component hierarchy to searchdeepest
- 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.getFocusableComponentOrChild(java.awt.Component)
public static java.awt.Image loadFromResource(java.lang.String imageName, java.lang.Class<?> cls)
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.imageName
- Name of the resource to load.cls
- Class to pull resource from.Class.getResource(String)
,
Toolkit.createImage(URL)
public static java.awt.Rectangle[] getScreenBounds()
Rectangle
'spublic static void makeSameSize(javax.swing.JComponent... comps)
comps
- public static java.lang.String toHTMLColor(java.awt.Color c)
c
- Color to convert.public static java.lang.String createToolTip(java.lang.String text, int width)
text
- the Text appearing in the Tooltipwidth
- the width of the Tooltippublic static java.lang.String createToolTip(java.lang.String text)
text
- , the Text appearing in the Tooltippublic static java.lang.String getHighlightedWords(java.lang.String text, java.lang.String query)
text
- , the Text containing Words that should be Highlightedquery
- , the Words that should be Highlightedpublic static javax.swing.ImageIcon createShadowPicture(java.awt.Image buf)
ImageIcon
with a Shadowbuf
- , the Image
where a Shadow will be appliedImageIcon
with shadowpublic static java.awt.image.BufferedImage removeTransparency(java.awt.Image image)
Image
image
- BufferedImage
without Transparencypublic static java.awt.Image toImage(java.awt.image.BufferedImage bufferedImage)
BufferedImage
to Image
bufferedImage
- , the BufferedImage
Image
public static java.awt.image.BufferedImage convert(java.awt.Image im) throws java.lang.InterruptedException, java.io.IOException
Image
into a BufferedImage
Transparency
some Images gets lostim
- BufferedImage
java.lang.InterruptedException
{@link
- IOException}java.io.IOException
public static void load(java.awt.Image image) throws java.lang.InterruptedException, java.io.IOException
image
- java.lang.InterruptedException
java.io.IOException
public static byte[] getBytesFromImage(java.io.File file)
file
- , input File
public static javax.swing.ImageIcon scaleImageIcon(javax.swing.ImageIcon icon, int newHeight, int newWidth)
icon
- the image icon.newHeight
- the preferred height.newWidth
- the preferred width.public static javax.swing.ImageIcon scale(javax.swing.ImageIcon icon, int newHeight, int newWidth)
icon
- the image icon.newHeight
- the preferred height.newWidth
- the preferred width.public static javax.swing.Icon getIcon(java.io.File file)
file
- the file to check icon type.public static java.awt.image.BufferedImage getBufferedImage(java.io.File file)
file
- File
BufferedImage
public static javax.swing.ImageIcon fitToSquare(javax.swing.ImageIcon icon, int newSize)
icon
- newSize
-