Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

oracle.javatools.util
Class SwingUtils

java.lang.Object
  extended by oracle.javatools.util.SwingUtils

public final class SwingUtils
extends java.lang.Object

Utility methods for Swing and Java.


Field Summary
static java.lang.String MAIN_WINDOW_KEY
           
static java.lang.String PROGRAM_NAME_KEY
           
static java.lang.String PROGRAM_SHORT_NAME_KEY
           
static java.lang.String STARTUP_WINDOW_KEY
           
 
Method Summary
static void dispatch(java.lang.Runnable runnable)
          Dispatch a runnable.
static void drawChars(java.awt.Graphics graphics, char[] data, int offset, int length, int x, int y)
          Deprecated. since 11.1.1 - Use @{link GraphicUtils#drawChars(Graphics,char[],int,int.int,int)}.
static void drawString(java.awt.Graphics2D graphics2d, java.lang.String text, float x, float y)
          Deprecated. since 11.1.1 - Use GraphicUtils.drawString(Graphics2D,String,float,float)
static void drawString(java.awt.Graphics graphics, java.text.AttributedCharacterIterator iterator, int x, int y)
          Deprecated. since 11.1.1 - Use .
static void drawString(java.awt.Graphics graphics, java.lang.String text, int x, int y)
          Deprecated. since 11.1.1 - Use GraphicUtils.drawString(Graphics,String,int,int).
static java.awt.Window findAncestorFrameOrDialog(java.awt.Component component)
          Finds the first parent of the specified Component that is an instance of Frame or Dialog.
static java.awt.Frame findFrame(java.awt.Component component)
          Finds the first parent of the specified Component that is an instance of Frame.
static java.awt.Dialog getAncestorDialog(java.awt.Component parent)
          Given a Component, find its nearest hosting Dialog, if any, which may be itself.
static java.awt.Frame getAncestorFrame(java.awt.Component parent)
          Given a Component, find its nearest hosting Frame, if any, which may be itself.
static java.awt.Container getAncestorOfClasses(java.lang.Class<?>[] classes, java.awt.Component comp)
          Convenience method for searching above comp in the component hierarchy and returns the first object of one of the classes in the array of classes classes it finds.
static java.awt.Frame getMainWindow()
          Retrieves the window that can be considered the main window of this application.
static java.lang.String getProgramName()
          Retrieves the name of this application.
static java.lang.String getProgramShortName()
           
static java.awt.Frame getStartupWindow()
          Retrieves the window that can be considered the startup window of this application while waiting for the main window.
static java.awt.Frame getToplevelWindow()
          Get a top level window upon which dialogs and other windows may be parented.
static void invokeAfterRepaint(java.lang.Runnable runnable)
          Deprecated. This method was introduced to fix the "gray rectangle" problem in Swing. Now the issue is fixed in Java 1.6 (sun bug no: 4967886), we no longer need this method. Clients are requested to use SwingUtilities.invokeLater if they feel the need to use this method. For now, this method is same as SwingUtilities.invokeLater.
static void removeKeyStrokesFromInputMap(javax.swing.JComponent component, javax.swing.KeyStroke[] keyStrokes, int mapType)
          Remove all mappings bound to the specified set of KeyStrokes for the InputMap of the specified type that is associated with the specified JComponent.
static void removeKeyStrokesFromInputMaps(javax.swing.JComponent component, javax.swing.KeyStroke[] keyStrokes)
          Remove all mappings bound to the specified set of KeyStrokes for each InputMap that is associated with the specified JComponent.
static void setMainWindow(javax.swing.JFrame frame)
          Sets the main window being used by this program.
static void setProgramName(java.lang.String name)
          Sets the name of this application.
static void setProgramShortName(java.lang.String name)
           
static void setStartupWindow(javax.swing.JFrame frame)
          Sets the startup window being used by this program.
static boolean useTextAntialiasing()
          Deprecated. since 11.1.1 - Use GraphicUtils.useTextAntialiasing().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STARTUP_WINDOW_KEY

public static final java.lang.String STARTUP_WINDOW_KEY
See Also:
Constant Field Values

MAIN_WINDOW_KEY

public static final java.lang.String MAIN_WINDOW_KEY
See Also:
Constant Field Values

PROGRAM_NAME_KEY

public static final java.lang.String PROGRAM_NAME_KEY
See Also:
Constant Field Values

PROGRAM_SHORT_NAME_KEY

public static final java.lang.String PROGRAM_SHORT_NAME_KEY
See Also:
Constant Field Values
Method Detail

findFrame

public static java.awt.Frame findFrame(java.awt.Component component)
Finds the first parent of the specified Component that is an instance of Frame. If the component itself is a Frame, then it is returned. If the component is null then null is returned.


findAncestorFrameOrDialog

public static java.awt.Window findAncestorFrameOrDialog(java.awt.Component component)
Finds the first parent of the specified Component that is an instance of Frame or Dialog. If the component itself is a Frame or Dialog, then it is returned. If the component is null then null is returned.


getAncestorOfClasses

public static java.awt.Container getAncestorOfClasses(java.lang.Class<?>[] classes,
                                                      java.awt.Component comp)
Convenience method for searching above comp in the component hierarchy and returns the first object of one of the classes in the array of classes classes it finds. Can return null, if a no ancestor of one of the specified classes classes can be found.


getMainWindow

public static java.awt.Frame getMainWindow()
Retrieves the window that can be considered the main window of this application. If no main window has been set, the first Frame found will be returned.


getStartupWindow

public static java.awt.Frame getStartupWindow()
Retrieves the window that can be considered the startup window of this application while waiting for the main window. This is usefull for status type dialogs which may need to be displayed prior to the display of the main window. If no startup window has been set, null will be returned.


getToplevelWindow

public static java.awt.Frame getToplevelWindow()
Get a top level window upon which dialogs and other windows may be parented. References to the returned object should not be held, as the return result may be a different object between calls depending on whether or not the main window has been displayed yet.


setMainWindow

public static void setMainWindow(javax.swing.JFrame frame)
Sets the main window being used by this program.

Parameters:
frame - the JFrame that can be considered the main window of the application, or null to clear the main window setting.

setStartupWindow

public static void setStartupWindow(javax.swing.JFrame frame)
Sets the startup window being used by this program. The startup window is a temporary window for hosting dialogs prior to the showing of the main window. getToplevelWindow will return the startup window if the main window has not yet been created and displayed.

Parameters:
frame - the JFrame that can be considered the startup window of the application, or null to clear the startup window setting.

getProgramName

public static java.lang.String getProgramName()
Retrieves the name of this application.


setProgramName

public static void setProgramName(java.lang.String name)
Sets the name of this application. The main window of this application must be set before setting the program name.


getProgramShortName

public static java.lang.String getProgramShortName()

setProgramShortName

public static void setProgramShortName(java.lang.String name)

getAncestorDialog

public static java.awt.Dialog getAncestorDialog(java.awt.Component parent)
Given a Component, find its nearest hosting Dialog, if any, which may be itself.

Returns:
null if Component is not hosted by a Dialog

getAncestorFrame

public static java.awt.Frame getAncestorFrame(java.awt.Component parent)
Given a Component, find its nearest hosting Frame, if any, which may be itself.

Returns:
null if Component is not hosted by a Frame

removeKeyStrokesFromInputMaps

public static void removeKeyStrokesFromInputMaps(javax.swing.JComponent component,
                                                 javax.swing.KeyStroke[] keyStrokes)
Remove all mappings bound to the specified set of KeyStrokes for each InputMap that is associated with the specified JComponent.


removeKeyStrokesFromInputMap

public static void removeKeyStrokesFromInputMap(javax.swing.JComponent component,
                                                javax.swing.KeyStroke[] keyStrokes,
                                                int mapType)
Remove all mappings bound to the specified set of KeyStrokes for the InputMap of the specified type that is associated with the specified JComponent.

The mapType parameter should be one of the following values:


useTextAntialiasing

public static boolean useTextAntialiasing()
Deprecated. since 11.1.1 - Use GraphicUtils.useTextAntialiasing().

Fetch whether text should be drawn with text anti-aliasing on.

Returns:
true if text should be drawn with anti-aliasing

drawChars

public static void drawChars(java.awt.Graphics graphics,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y)
Deprecated. since 11.1.1 - Use @{link GraphicUtils#drawChars(Graphics,char[],int,int.int,int)}.

Draw the text specified by the character array. This will set the appropriate rendering hints on the graphics object if text anti-aliasing is on. Asides from setting the rendering hint, this method works the same way as the Graphics.drawChars() method.

Parameters:
graphics - the graphics context
data - the array of characters to be drawn
offset - the start offset in the data
length - the number of characters to be drawn
x - the x-coordinate of the baseline of the text
y - the y-coordinate of the baseline of the text
See Also:
Graphics.drawChars(char[], int, int, int, int)

drawString

public static void drawString(java.awt.Graphics graphics,
                              java.lang.String text,
                              int x,
                              int y)
Deprecated. since 11.1.1 - Use GraphicUtils.drawString(Graphics,String,int,int).

Draw the specified String text. This will set the appropriate rendering hints on the graphics object if text anti-aliasing is on. Asides from setting the rendering hint, this method works the same way as the Graphics.drawString() method.

Parameters:
graphics - the graphics context
text - the String to draw
x - the x-coordinate of the baseline of the text
y - the y-coordinate of the baseline of the text
See Also:
Graphics.drawString(java.lang.String, int, int)

drawString

public static void drawString(java.awt.Graphics2D graphics2d,
                              java.lang.String text,
                              float x,
                              float y)
Deprecated. since 11.1.1 - Use GraphicUtils.drawString(Graphics2D,String,float,float)

Draw the specified String text. This will set the appropriate rendering hints on the graphics object if text anti-aliasing is on. Asides from setting the rendering hint, this method works the same way as the Graphics2D.drawString() method.

Parameters:
graphics2d - the 2D graphics context
text - the String to draw
x - the x-coordinate location to draw the text
y - the y-coordinate location to draw the text
See Also:
Graphics2D.drawString(java.lang.String, int, int)

drawString

public static void drawString(java.awt.Graphics graphics,
                              java.text.AttributedCharacterIterator iterator,
                              int x,
                              int y)
Deprecated. since 11.1.1 - Use .

Draw the text specified by the given iterator. This will set the appropriate rendering hints on the graphics object if text anti-aliasing is on. Asides from setting the rendering hint, this method works the same way as the Graphics.drawString() method.

Parameters:
graphics - the graphics context
iterator - the text iterator to draw
x - the x-coordinate of the baseline of the text
y - the y-coordinate of the baseline of the text
See Also:
Graphics.drawString(java.lang.String, int, int)

invokeAfterRepaint

@Deprecated
public static void invokeAfterRepaint(java.lang.Runnable runnable)
Deprecated. This method was introduced to fix the "gray rectangle" problem in Swing. Now the issue is fixed in Java 1.6 (sun bug no: 4967886), we no longer need this method. Clients are requested to use SwingUtilities.invokeLater if they feel the need to use this method. For now, this method is same as SwingUtilities.invokeLater.

This method is similar to SwingUtilities.invokeLater(Runnable) except that the runnable is started after all the pending repaints.

Parameters:
runnable -

dispatch

public static void dispatch(java.lang.Runnable runnable)
Dispatch a runnable. The Runnable.run() method is guaranteed to be invoked on the AWT event dispatch thread. If the calling thread is the event dispatch thread, then the run method will be invoked immediately (synchronously). For any other thread, an invocation event will be posted to the dispatch thread to run the runnable later. In this latter case, this method may return before the run() method of the runnable has been called.

Parameters:
runnable - a runnable to dispatch.

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

Copyright © 1997, 2011, Oracle. All rights reserved.