|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.gui.GuiToolbox
Miscellaneous functions providing AWT and Swing support.
Details: GuiToolbox
is a collection of functions that perform various AWT- and Swing-
Constructor Summary | |
GuiToolbox()
|
Method Summary | |
static int |
blendColors(int background,
int foreground)
Blends two ARGB colors into a single ARGB color. |
static javax.swing.JButton |
buildJButton(ButtonImages bi)
Constructs JButton from ButtonImages. |
static javax.swing.JToggleButton |
buildJToggleButton(ButtonImages bi)
Constructs JToggleButton from ButtonImages. |
static java.awt.Rectangle |
centerRectangle(java.awt.Point reference,
java.awt.Rectangle moveable)
Centers a rectangle on a point. |
static java.awt.Rectangle |
centerRectangle(java.awt.Rectangle reference,
java.awt.Rectangle moveable)
Centers one rectangle with another. |
static java.awt.Dimension |
computeDifference(java.awt.Point from,
java.awt.Point to)
Computes translation between points. |
static void |
configureFaces(javax.swing.AbstractButton b,
ButtonImages bi)
Sets Swing button icons. |
static java.awt.Image |
createImage(java.lang.String filename)
Creates an image from a filename. |
static java.awt.Image |
cropImage(java.awt.Image srcimg,
java.awt.Rectangle rect)
|
static float |
distance(java.awt.Point p1,
java.awt.Point p2)
Computes distance between points. |
static void |
drawLine(java.awt.Graphics g,
java.awt.Point p1,
java.awt.Point p2)
Draws line. |
static void |
drawString(java.awt.Graphics g,
java.lang.String s,
java.awt.Point p)
|
static void |
drawStringAligned(java.awt.Graphics g,
java.lang.String s,
java.awt.Point p,
int a)
|
static void |
drawStringAligned(java.awt.Graphics g,
java.lang.String s,
java.awt.Rectangle r,
int a)
|
static java.awt.Point |
getCenter(java.awt.Rectangle rect)
Computes the center of a rectangle. |
static int |
getComponentZOrder(java.awt.Container container,
java.awt.Component component)
Returns component Z-order. |
static java.io.File |
getFile(java.awt.FileDialog fd)
Uses the supplied FileDialog window to obtain a file selection from the user. |
static java.util.Enumeration |
getMenuItems(java.awt.Menu menu)
Returns an enumeration of the given menu's MenuItems. |
static java.util.Enumeration |
getMenuItems(java.awt.MenuBar menubar)
Returns an enumeration of all of the given menu bar's MenuItems. |
static java.util.Enumeration |
getMenus(java.awt.MenuBar menubar)
Returns an enumeration of the given menu bar's menus. |
static java.awt.Container |
getRootContainer(java.awt.Component comp)
SUMMARY FORTHCOMING |
static int |
getStringAdvance(java.awt.FontMetrics fm,
java.lang.String s)
Returns the advance width of a String when printed using the font with the given FontMetrics . |
static int |
getStringAdvance(java.awt.Graphics g,
java.lang.String s)
Returns the advance width of a String when drawn through the current Graphics object. |
static boolean |
intersects(java.awt.Polygon p,
java.awt.Rectangle r)
No summary provided. |
static java.awt.Image |
loadImage(java.lang.String resname)
Loads image from classpath. |
static java.awt.Dimension |
max(java.awt.Dimension d1,
java.awt.Dimension d2)
|
static java.awt.Dimension |
min(java.awt.Dimension d1,
java.awt.Dimension d2)
|
static boolean |
orderedSizes(java.awt.Dimension dim1,
java.awt.Dimension dim2)
Determines whether two dimensions are ordered. |
static boolean |
orderedSizes(java.awt.Dimension dim1,
java.awt.Dimension dim2,
java.awt.Dimension dim3)
Determines whether three dimensions are ordered. |
static java.awt.Point |
pointForCentering(java.lang.String text,
java.awt.Point center,
java.awt.Font font,
java.awt.Component component)
Calculates the draw point for centered text. |
static java.awt.Point |
pointForCentering(java.lang.String text,
java.awt.Point center,
java.awt.Graphics graphics)
Calculates the draw point for centered text. |
static void |
repaint(java.awt.Component c,
java.awt.Rectangle b)
Invalidates rectangular region. |
static void |
runInAwtEventThread(java.lang.Runnable r)
Executes Runnable in AWT event thread. |
static java.awt.Rectangle |
scaleRectangle(java.awt.Dimension oldsize,
java.awt.Dimension newsize,
java.awt.Rectangle rect)
|
static java.awt.Dimension |
waitForDimensions(java.awt.Image image)
Waits for an image's dimensions. |
static boolean |
waitForImage(java.awt.Image i)
Waits for an image to load. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public GuiToolbox()
Method Detail |
public static final int blendColors(int background, int foreground)
background
- the background colorforeground
- the foreground colorpublic static final int getStringAdvance(java.awt.Graphics g, java.lang.String s)
String
when drawn through the current Graphics
object.g
- the graphics contexts
- the stringpublic static final int getStringAdvance(java.awt.FontMetrics fm, java.lang.String s)
String
when printed using the font with the given FontMetrics
.fm
- the graphics contexts
- the stringpublic static final boolean waitForImage(java.awt.Image i)
Details: waitForImage completely loads the specified image (i
). This class is useful in situations where images load progressively but progressive display is not desired. true
is returned if the image loads successfully, false
otherwise.
i
- the image to wait ontrue
iff the image loads successfullypublic static java.awt.Point pointForCentering(java.lang.String text, java.awt.Point center, java.awt.Font font, java.awt.Component component)
Details: This method determines the total width and height of text
, drawn using the given Font and Component. It then computes the text draw coordinate (for use in Graphics.drawString
, etc.) that will result in text centered around the given center point, center
.
text
- the textcenter
- the desired center pointfont
- the fontcomponent
- the component to which the text will be drawnpublic static java.awt.Point pointForCentering(java.lang.String text, java.awt.Point center, java.awt.Graphics graphics)
Details: This method determines the total width and height of text
, drawn using the given Graphics object. It then computes the text draw coordinate (for use in graphics.drawString
, etc.) that will produced centered text around the given center point, center
.
text
- the textcenter
- the desired center pointgraphics
- the graphics contextpublic static java.awt.Dimension waitForDimensions(java.awt.Image image)
Details: Many types of images are loaded asynchronously. This applies not only to the image's pixels, but also to other information about the image, such as its width and height. This function waits for the given image's width and height to come in, and then returns with a Dimension of those values. It will not return until the image's dimensions have been determined, or until the asynchronous image loader has given up, due to an error. If an error occurs, this method returns null. If image is null, null is returned.
image
- the imagepublic static java.util.Enumeration getMenus(java.awt.MenuBar menubar)
menubar
- the menu barpublic static java.util.Enumeration getMenuItems(java.awt.Menu menu)
menu
- the menupublic static java.util.Enumeration getMenuItems(java.awt.MenuBar menubar)
Details: getMenuItems recursively searches menubar's menus to build an Enumeration of all MenuItems. The Enumeration is then returned.
menubar
- the menu barpublic static java.io.File getFile(java.awt.FileDialog fd)
Details: getFile uses the supplied FileDialog window to obtain a file selection from the user, and does not return until the selection is made or cancelled. The value returned is a File object representing the user's choice, or null if the user did not make a selection. Either way, this method disposes of the FileDialog object before returning.
fd
- the FileDialogpublic static boolean orderedSizes(java.awt.Dimension dim1, java.awt.Dimension dim2, java.awt.Dimension dim3)
Details: orderedSizes
determines whether the given sizes are ordered. To be ordered, both the widths and heights must be ordered. orderedSizes
returns true
if dim1, dim2, and dim3 are ordered, false
otherwise.
min1
- the smallest dimensionmin2
- the middle dimensionmin3
- the largest dimensionpublic static boolean orderedSizes(java.awt.Dimension dim1, java.awt.Dimension dim2)
Details: orderedSizes
returns the result of the expression
dim1.width<=dim2.width&&dim1.height<=dim2.height
In other words, orderedSizes
returns true
if the dimensions are ordered, false
otherwise.
min1
- the small dimensionmin2
- the large dimensionpublic static java.awt.Rectangle centerRectangle(java.awt.Rectangle reference, java.awt.Rectangle moveable)
Details: centerRectangle
returns a new Rectangle
that is concentric with reference and the same size as moveable.
reference
- the rectangle defining the centermoveable
- the rectangle defining the dimensionspublic static java.awt.Rectangle centerRectangle(java.awt.Point reference, java.awt.Rectangle moveable)
Details: centerRectangle
returns a new Rectangle
that is centered on reference and the same size as moveable.
reference
- the center pointmoveable
- the rectangle defining the dimensionspublic static java.awt.Point getCenter(java.awt.Rectangle rect)
Details: getCenter
computes and returns the center of a Rectangle
.
rect
- the rectanglepublic static java.awt.Image createImage(java.lang.String filename)
Details: createImage uses the default Toolkit to create an image based on the given filename.
filename
- the filenamepublic static java.awt.Dimension min(java.awt.Dimension d1, java.awt.Dimension d2)
public static java.awt.Dimension max(java.awt.Dimension d1, java.awt.Dimension d2)
public static java.awt.Rectangle scaleRectangle(java.awt.Dimension oldsize, java.awt.Dimension newsize, java.awt.Rectangle rect)
public static void drawString(java.awt.Graphics g, java.lang.String s, java.awt.Point p)
public static void drawStringAligned(java.awt.Graphics g, java.lang.String s, java.awt.Point p, int a)
public static void drawStringAligned(java.awt.Graphics g, java.lang.String s, java.awt.Rectangle r, int a)
public static java.awt.Image cropImage(java.awt.Image srcimg, java.awt.Rectangle rect)
public static void configureFaces(javax.swing.AbstractButton b, ButtonImages bi)
Details: configureFaces
assigns the various button state images stored in bi to the corresponding Swing button. Only non-null
images in bi will be assigned to the Swing button. configureFaces
also removes the border from the button.
b
- the Swing buttonbi
- the image setpublic static javax.swing.JButton buildJButton(ButtonImages bi)
Details: buildJButton
constructs a JButton
from the given ButtonImages
object. In particular, this method creates a JButton
, initializes the button states by calling configureFaces
, and then sets the button's size to be equal to the size of the out-
bi
- the button facespublic static javax.swing.JToggleButton buildJToggleButton(ButtonImages bi)
Details: buildJToggleButton
does the same thing as buildJButton
, but returns a JToggleButton
instead.
public static java.awt.Image loadImage(java.lang.String resname)
Details: loadImage
loads an image from the classpath. resname is the slash-
Programming your application to load images from the classpath makes it possible for your application to find its image resources even when the application is run in an alternate initial directory. This technique also makes it possible for JAR'ed applications to load images from their own JARs.
loadImage
returns null
if the named resource cannot be found.
resname
- the image filenamepublic static float distance(java.awt.Point p1, java.awt.Point p2)
Details: distance computes the distance between two points using Pythagorus' theorem.
p1
- the first pointp2
- the second pointpublic static void repaint(java.awt.Component c, java.awt.Rectangle b)
Details: repaint invalidates the given Rectangle on the given Component.
c
- the Componentb
- the Rectanglepublic static void drawLine(java.awt.Graphics g, java.awt.Point p1, java.awt.Point p2)
Details: drawLine draws a line between the two given points using the given graphics context.
p1
- first pointp2
- second pointpublic static boolean intersects(java.awt.Polygon p, java.awt.Rectangle r)
Details: No details provided.
p
- pr
- rpublic static java.awt.Container getRootContainer(java.awt.Component comp)
Details: getRootContainer
returns the root Container
of the given Component
, or null
if the parent cannot be determined.
the
- Componentpublic static java.awt.Dimension computeDifference(java.awt.Point from, java.awt.Point to)
Details: computeDifference
determines the rectangular difference between two given points. For example, if from = (2, 2) and to = (4, 5), then computeDifference returns (2, 3) in a Dimension object.
from
- the first pointfrom
- the second pointpublic static int getComponentZOrder(java.awt.Container container, java.awt.Component component)
Details: This method returns the Z-order of the given component (component ) within the given container (container). If the component is in the container, the value returned will be the value n for which container . getComponent (n)
returns component. Otherwise, -1 is returned. Whether low numbers are on top or high numbers are on top depends on the container implementation.
container
- the containercomponent
- the componentpublic static final void runInAwtEventThread(java.lang.Runnable r)
Details: runInAwtEventThread
guarantees that the given Runnable (r) will be executed in an AWT event dispatching thread. If the thread in which this method is called is an AWT event dispatching thread, r will be executed immediately, and this method will not return until r.run
has completed. If the current thread is not an AWT dispatching thread, however, r will be enqueued in an AWT dispatching thread for asynchronous execution.
No action is taken if r is null.
r
- the Runnable
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |