org.jfree.ui
Class RefineryUtilities

java.lang.Object
  extended byorg.jfree.ui.RefineryUtilities

public abstract class RefineryUtilities
extends java.lang.Object

A collection of utility methods relating to user interfaces.

Author:
David Gilbert

Field Summary
protected static LogContext logger
          Access to logging facilities.
 
Constructor Summary
RefineryUtilities()
           
 
Method Summary
static java.awt.Shape calculateRotatedStringBounds(java.lang.String text, java.awt.Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY)
          Deprecated. Moved to the TextUtilities class.
static java.awt.Shape calculateRotatedStringBounds(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle)
          Deprecated. Moved to the TextUtilities class (note also the change in the order of the parameters).
static void centerDialogInParent(java.awt.Dialog dialog)
          Positions the specified dialog within its parent.
static void centerFrameOnScreen(java.awt.Window frame)
          Positions the specified frame in the middle of the screen.
static javax.swing.JButton createJButton(java.lang.String label, java.awt.Font font)
          Creates a JButton.
static javax.swing.JLabel createJLabel(java.lang.String text, java.awt.Font font)
          Creates a label with a specific font.
static javax.swing.JLabel createJLabel(java.lang.String text, java.awt.Font font, java.awt.Color color)
          Creates a label with a specific font and color.
static javax.swing.JPanel createTablePanel(javax.swing.table.TableModel model)
          Creates a panel that contains a table based on the specified table model.
static void drawAlignedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor anchor)
          Deprecated. Use TextUtilities.drawAlignedString().
static void drawRotatedShape(java.awt.Shape shape, java.awt.Graphics2D g2, float x, float y, double angle)
          Deprecated. Moved to the ShapeUtilities class (note also that the order of the parameters has changed).
static void drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, double angle)
          Deprecated. Moved to the TextUtilities class (note also the order of the parameters has been changed).
static void drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY)
          Deprecated. Moved to the TextUtilities class.
static void drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, float rotationX, float rotationY, double angle)
          Deprecated. Moved to the TextUtilities class (note also the order of the parameters has changed).
static void drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle)
          Deprecated. Moved to the TextUtilities class (note also the order of the parameters has changed).
static java.awt.geom.Point2D getPointInRectangle(double x, double y, java.awt.geom.Rectangle2D area)
          Deprecated. Moved to ShapeUtilities.
static boolean invokeAndWait(java.lang.Runnable runnable)
          Executes the given runnable on the EventDispatcher thread.
static void positionDialogRelativeToParent(java.awt.Dialog dialog, double horizontalPercent, double verticalPercent)
          Positions the specified dialog at a position relative to its parent.
static void positionFrameOnScreen(java.awt.Window frame, double horizontalPercent, double verticalPercent)
          Positions the specified frame at a relative position in the screen, where 50% is considered to be the center of the screen.
static void positionFrameRandomly(java.awt.Window frame)
          Positions the specified frame at a random location on the screen while ensuring that the entire frame is visible (provided that the frame is smaller than the screen).
static void setUseDrawRotatedStringWorkaround(boolean use)
          Deprecated. Moved to the TextUtilities class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final LogContext logger
Access to logging facilities.

Constructor Detail

RefineryUtilities

public RefineryUtilities()
Method Detail

centerFrameOnScreen

public static void centerFrameOnScreen(java.awt.Window frame)
Positions the specified frame in the middle of the screen.

Parameters:
frame - the frame to be centered on the screen.

positionFrameOnScreen

public static void positionFrameOnScreen(java.awt.Window frame,
                                         double horizontalPercent,
                                         double verticalPercent)
Positions the specified frame at a relative position in the screen, where 50% is considered to be the center of the screen.

Parameters:
frame - the frame.
horizontalPercent - the relative horizontal position of the frame (0.0 to 1.0, where 0.5 is the center of the screen).
verticalPercent - the relative vertical position of the frame (0.0 to 1.0, where 0.5 is the center of the screen).

positionFrameRandomly

public static void positionFrameRandomly(java.awt.Window frame)
Positions the specified frame at a random location on the screen while ensuring that the entire frame is visible (provided that the frame is smaller than the screen).

Parameters:
frame - the frame.

centerDialogInParent

public static void centerDialogInParent(java.awt.Dialog dialog)
Positions the specified dialog within its parent.

Parameters:
dialog - the dialog to be positioned on the screen.

positionDialogRelativeToParent

public static void positionDialogRelativeToParent(java.awt.Dialog dialog,
                                                  double horizontalPercent,
                                                  double verticalPercent)
Positions the specified dialog at a position relative to its parent.

Parameters:
dialog - the dialog to be positioned.
horizontalPercent - the relative location.
verticalPercent - the relative location.

createTablePanel

public static javax.swing.JPanel createTablePanel(javax.swing.table.TableModel model)
Creates a panel that contains a table based on the specified table model.

Parameters:
model - the table model to use when constructing the table.
Returns:
The panel.

createJLabel

public static javax.swing.JLabel createJLabel(java.lang.String text,
                                              java.awt.Font font)
Creates a label with a specific font.

Parameters:
text - the text for the label.
font - the font.
Returns:
The label.

createJLabel

public static javax.swing.JLabel createJLabel(java.lang.String text,
                                              java.awt.Font font,
                                              java.awt.Color color)
Creates a label with a specific font and color.

Parameters:
text - the text for the label.
font - the font.
color - the color.
Returns:
The label.

createJButton

public static javax.swing.JButton createJButton(java.lang.String label,
                                                java.awt.Font font)
Creates a JButton.

Parameters:
label - the label.
font - the font.
Returns:
The button.

getPointInRectangle

public static java.awt.geom.Point2D getPointInRectangle(double x,
                                                        double y,
                                                        java.awt.geom.Rectangle2D area)
Deprecated. Moved to ShapeUtilities.

Returns a point based on (x, y) but constrained to be within the bounds of a given rectangle.

Parameters:
x - the x-coordinate.
y - the y-coordinate.
area - the constraining rectangle.
Returns:
A point within the rectangle.

drawRotatedShape

public static void drawRotatedShape(java.awt.Shape shape,
                                    java.awt.Graphics2D g2,
                                    float x,
                                    float y,
                                    double angle)
Deprecated. Moved to the ShapeUtilities class (note also that the order of the parameters has changed).

Draws a rotated shape.

Parameters:
shape - the shape.
g2 - the graphics device.
x - the x coordinate for the rotation point.
y - the y coordinate for the rotation point.
angle - the angle.

drawAlignedString

public static void drawAlignedString(java.lang.String text,
                                     java.awt.Graphics2D g2,
                                     float x,
                                     float y,
                                     TextAnchor anchor)
Deprecated. Use TextUtilities.drawAlignedString().

Draws a string such that the specified anchor point is aligned to the given (x, y) location.

Parameters:
text - the text.
g2 - the graphics device.
x - the x coordinate (Java 2D).
y - the y coordinate (Java 2D).
anchor - the anchor location.

drawRotatedString

public static void drawRotatedString(java.lang.String text,
                                     java.awt.Graphics2D g2,
                                     float x,
                                     float y,
                                     double angle)
Deprecated. Moved to the TextUtilities class (note also the order of the parameters has been changed).

A utility method for drawing rotated text.

A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the characters on the left).

Parameters:
text - the text.
g2 - the graphics device.
x - the x-coordinate.
y - the y-coordinate.
angle - the angle of the (clockwise) rotation (in radians).

calculateRotatedStringBounds

public static java.awt.Shape calculateRotatedStringBounds(java.lang.String text,
                                                          java.awt.Graphics2D g2,
                                                          float textX,
                                                          float textY,
                                                          double angle,
                                                          float rotateX,
                                                          float rotateY)
Deprecated. Moved to the TextUtilities class.

Returns a shape that represents the bounds of the string after the specified rotation has been applied.

Parameters:
text - the text (null permitted).
g2 - the graphics device.
textX - the x coordinate for the text.
textY - the y coordinate for the text.
angle - the angle.
rotateX - the x coordinate for the rotation point.
rotateY - the y coordinate for the rotation point.
Returns:
The bounds (possibly null).

drawRotatedString

public static void drawRotatedString(java.lang.String text,
                                     java.awt.Graphics2D g2,
                                     float textX,
                                     float textY,
                                     double angle,
                                     float rotateX,
                                     float rotateY)
Deprecated. Moved to the TextUtilities class.

A utility method for drawing rotated text.

A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the characters on the left).

Parameters:
text - the text.
g2 - the graphics device.
textX - the x-coordinate for the text (before rotation).
textY - the y-coordinate for the text (before rotation).
angle - the angle of the (clockwise) rotation (in radians).
rotateX - the point about which the text is rotated.
rotateY - the point about which the text is rotated.

drawRotatedString

public static void drawRotatedString(java.lang.String text,
                                     java.awt.Graphics2D g2,
                                     float x,
                                     float y,
                                     TextAnchor textAnchor,
                                     float rotationX,
                                     float rotationY,
                                     double angle)
Deprecated. Moved to the TextUtilities class (note also the order of the parameters has changed).

Draws a string that is aligned by one anchor point and rotated about another anchor point.

Parameters:
text - the text.
g2 - the graphics device.
x - the location of the text anchor.
y - the location of the text anchor.
textAnchor - the text anchor.
rotationX - the x-coordinate for the rotation anchor point.
rotationY - the y-coordinate for the rotation anchor point.
angle - the rotation angle.

drawRotatedString

public static void drawRotatedString(java.lang.String text,
                                     java.awt.Graphics2D g2,
                                     float x,
                                     float y,
                                     TextAnchor textAnchor,
                                     TextAnchor rotationAnchor,
                                     double angle)
Deprecated. Moved to the TextUtilities class (note also the order of the parameters has changed).

Draws a string that is aligned by one anchor point and rotated about another anchor point.

Parameters:
text - the text.
g2 - the graphics device.
x - the location of the text anchor.
y - the location of the text anchor.
textAnchor - the text anchor.
rotationAnchor - the rotation anchor.
angle - the rotation angle.

calculateRotatedStringBounds

public static java.awt.Shape calculateRotatedStringBounds(java.lang.String text,
                                                          java.awt.Graphics2D g2,
                                                          float x,
                                                          float y,
                                                          TextAnchor textAnchor,
                                                          TextAnchor rotationAnchor,
                                                          double angle)
Deprecated. Moved to the TextUtilities class (note also the change in the order of the parameters).

Returns a shape that represents the bounds of the string after the specified rotation has been applied.

Parameters:
text - the text (null permitted).
g2 - the graphics device.
x - the x coordinate for the anchor point.
y - the y coordinate for the anchor point.
textAnchor - the text anchor.
rotationAnchor - the rotation anchor.
angle - the angle.
Returns:
The bounds (possibly null).

setUseDrawRotatedStringWorkaround

public static void setUseDrawRotatedStringWorkaround(boolean use)
Deprecated. Moved to the TextUtilities class.

Sets the flag that controls whether or not the rotated string workaround is used.

Parameters:
use - the new flag value.

invokeAndWait

public static boolean invokeAndWait(java.lang.Runnable runnable)
                             throws java.lang.InterruptedException
Executes the given runnable on the EventDispatcher thread. This method checks, whether the current thread is the EventDispatcher and in that case executes the run method directly.

Parameters:
runnable - the runnable that should be executed
Returns:
true, if the runnable was executed or false otherwise
Throws:
java.lang.InterruptedException - if the thread was interrupted before the execution was finished.