com.javaranch.common
Class AWT

java.lang.Object
  |
  +--com.javaranch.common.AWT
Direct Known Subclasses:
GUI

public class AWT
extends java.lang.Object

contains a collection of static methods related to GUI's (AWT only).

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton

Field Summary
static int center
           
static int right
           
static int rightPad
           
 
Method Summary
static int ascent(java.awt.Component c)
          Get the ascent associated with the font used by a component.
static java.awt.Button blank()
          Returns an object that can be used for whitespace in GridLayout.
static void center(java.awt.Component c)
          Center any GUI object on the screen.
static IRect drawBeveledRect(java.awt.Graphics g, IRect r, java.awt.Color topColor, java.awt.Color rightColor, java.awt.Color bottomColor, java.awt.Color leftColor, int borderThickness)
          Draw a beveled rectangle.
static java.awt.Rectangle drawBeveledRect(java.awt.Graphics g, java.awt.Rectangle r, int thickness, boolean outtie)
          Draw a beveled rectangle and assumes the color of gray.
static java.awt.Rectangle drawBeveledRect(java.awt.Graphics g, java.awt.Rectangle r, int Thickness, boolean Outtie, java.awt.Color c)
          Draw a beveled rectangle.
static int FontHeight(java.awt.Component c)
          Get the height associated with the font used by a component.
static java.awt.GridBagConstraints gbc(int x, int y)
          For creating quick GridBagConstraints objects.
static java.awt.GridBagConstraints gbc(int x, int y, int wide, int high, double weightx, double weighty)
          For creating quick GridBagConstraints objects.
static java.awt.Frame getFrame(java.awt.Component c)
          Given any component, find the closest parent frame.
static java.awt.Dimension getSize(java.awt.Font f, java.lang.String s)
           
static java.awt.Rectangle shrink(java.awt.Rectangle r)
          Get a rectangle that fits perfectly within another rectangle.
static void tellUser(java.awt.Component c, java.lang.String s)
          Pop up a dialog to pass a message to the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

center

public static final int center
See Also:
Constant Field Values

right

public static final int right
See Also:
Constant Field Values

rightPad

public static final int rightPad
See Also:
Constant Field Values
Method Detail

gbc

public static java.awt.GridBagConstraints gbc(int x,
                                              int y,
                                              int wide,
                                              int high,
                                              double weightx,
                                              double weighty)
For creating quick GridBagConstraints objects.


gbc

public static java.awt.GridBagConstraints gbc(int x,
                                              int y)
For creating quick GridBagConstraints objects.


blank

public static java.awt.Button blank()
Returns an object that can be used for whitespace in GridLayout.

Returns:
An object that will take up a bit of space.


getFrame

public static java.awt.Frame getFrame(java.awt.Component c)
Given any component, find the closest parent frame.

Parameters:
c - Any AWT or Swing component.

Returns:
The nearest Frame object that c uses.


tellUser

public static void tellUser(java.awt.Component c,
                            java.lang.String s)
Pop up a dialog to pass a message to the user.

Parameters:
c - Any component.

s - The message.


center

public static void center(java.awt.Component c)
Center any GUI object on the screen.

Parameters:
c - The component to be centered.


shrink

public static java.awt.Rectangle shrink(java.awt.Rectangle r)
Get a rectangle that fits perfectly within another rectangle.

Parameters:
r - The rectangle that the new rectangle will fit inside of.

Returns:
The new rectangle that fits perfectly within r.


drawBeveledRect

public static java.awt.Rectangle drawBeveledRect(java.awt.Graphics g,
                                                 java.awt.Rectangle r,
                                                 int Thickness,
                                                 boolean Outtie,
                                                 java.awt.Color c)
Draw a beveled rectangle.

Parameters:
g - A Graphics object that will be drawn on.

r - The rectangle that defines the outermost edge of the beveled rectangle.

Thickness - How many lines thick should this beveled rectangle be?

Outtie - Should the bevel be made to look like a button sticking out (true) or an indent in the canvas (false).

Returns:
The rectangle that fits perfectly within the beveled rectangle.


drawBeveledRect

public static java.awt.Rectangle drawBeveledRect(java.awt.Graphics g,
                                                 java.awt.Rectangle r,
                                                 int thickness,
                                                 boolean outtie)
Draw a beveled rectangle and assumes the color of gray.

Parameters:
g - A Graphics object that will be drawn on.

r - The rectangle that defines the outermost edge of the beveled rectangle.

thickness - How many lines thick should this beveled rectangle be?

outtie - Should the bevel be made to look like a button sticking out (true) or an indent in the canvas (false).

Returns:
The rectangle that fits perfectly within the beveled rectangle.


drawBeveledRect

public static IRect drawBeveledRect(java.awt.Graphics g,
                                    IRect r,
                                    java.awt.Color topColor,
                                    java.awt.Color rightColor,
                                    java.awt.Color bottomColor,
                                    java.awt.Color leftColor,
                                    int borderThickness)
Draw a beveled rectangle.

Parameters:
g - A Graphics object that will be drawn on.

r - The rectangle that defines the outermost edge of the beveled rectangle.

topColor - The color to be used on the top edge.

rightColor - The color to be used on the right edge.

bottomColor - The color to be used on the bottom edge.

leftColor - The color to be used on the left edge.

borderThickness - How many lines thick should this beveled rectangle be?

Returns:
The rectangle that fits perfectly within the beveled rectangle.


ascent

public static int ascent(java.awt.Component c)
Get the ascent associated with the font used by a component.


FontHeight

public static int FontHeight(java.awt.Component c)
Get the height associated with the font used by a component.


getSize

public static java.awt.Dimension getSize(java.awt.Font f,
                                         java.lang.String s)


Copyright ©2004 Paul Wheaton All Rights Reserved