javax.swing.plaf.synth

Class SynthGraphicsUtils

public class SynthGraphicsUtils extends Object

Wrapper for graphics primitives used in Synth.

Since: 1.5

Constructor Summary
SynthGraphicsUtils()
Creates a new SynthGraphicsUtils object.
Method Summary
intcomputeStringWidth(SynthContext ctx, Font font, FontMetrics fm, String text)
Returns the width of the string text for the specified font and font metrics.
voiddrawLine(SynthContext ctx, Object paintKey, Graphics g, int x1, int y1, int x2, int y2)
Draws a line from (x1,y1) to (x2,y2).
intgetMaximumCharHeight(SynthContext context)
Returns the maximum character height of the font from the component of the passed in context.
DimensiongetMaximumSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the maximum size that is needed to render the label with text and icon correctly.
DimensiongetMinimumSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the minimums size that is needed to render the label with text and icon correctly.
DimensiongetPreferredSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the preferred size that is needed to render the label with text and icon correctly.
StringlayoutText(SynthContext ctx, FontMetrics fm, String text, Icon icon, int hAlign, int vAlign, int hTextPos, int vTextPos, Rectangle viewR, Rectangle iconR, Rectangle textR, int iconTextGap)
Lays out a label and (if non-null) an icon.
voidpaintText(SynthContext ctx, Graphics g, String text, Rectangle bounds, int mnemonicIndex)
Renders the specified text within the bounds.
voidpaintText(SynthContext ctx, Graphics g, String text, int x, int y, int mnemonicIndex)
Renders the specified text at the specified location.
voidpaintText(SynthContext ctx, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset)

Constructor Detail

SynthGraphicsUtils

public SynthGraphicsUtils()
Creates a new SynthGraphicsUtils object.

Method Detail

computeStringWidth

public int computeStringWidth(SynthContext ctx, Font font, FontMetrics fm, String text)
Returns the width of the string text for the specified font and font metrics.

Parameters: ctx identifies the current region font the font fm the font metrics to use text the text to be measured

Returns: the width of the string text for the specified font and font metrics

drawLine

public void drawLine(SynthContext ctx, Object paintKey, Graphics g, int x1, int y1, int x2, int y2)
Draws a line from (x1,y1) to (x2,y2).

Parameters: ctx the synth context, identifies the region paintKey identifies the portion of the component to be painted, may be null g the graphics context to use for painting x1 the x coordinate of the start point y1 the y coordinate of the start point x2 the x coordinate of the end point y2 the y coordinate of the end point

getMaximumCharHeight

public int getMaximumCharHeight(SynthContext context)
Returns the maximum character height of the font from the component of the passed in context.

Parameters: context identifies the current component and region

Returns: the maximum character height of the font from the component of the passed in context

getMaximumSize

public Dimension getMaximumSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the maximum size that is needed to render the label with text and icon correctly.

Parameters: ctx identifies the current region font the font to use text the label text icon the label icon hAlign the horizontal alignment vAlign the vertical alignment hTextPosition the horizontal text position vTextPosition the vertical text position iconTextGap the gap between icon and text mnemonicIndex index to the mnemonic character within text

Returns: the maximum size that is needed to render the label with text and icon correctly

getMinimumSize

public Dimension getMinimumSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the minimums size that is needed to render the label with text and icon correctly.

Parameters: ctx identifies the current region font the font to use text the label text icon the label icon hAlign the horizontal alignment vAlign the vertical alignment hTextPosition the horizontal text position vTextPosition the vertical text position iconTextGap the gap between icon and text mnemonicIndex index to the mnemonic character within text

Returns: the minimums size that is needed to render the label with text and icon correctly

getPreferredSize

public Dimension getPreferredSize(SynthContext ctx, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)
Calculates the preferred size that is needed to render the label with text and icon correctly.

Parameters: ctx identifies the current region font the font to use text the label text icon the label icon hAlign the horizontal alignment vAlign the vertical alignment hTextPosition the horizontal text position vTextPosition the vertical text position iconTextGap the gap between icon and text mnemonicIndex index to the mnemonic character within text

Returns: the preferred size that is needed to render the label with text and icon correctly

layoutText

public String layoutText(SynthContext ctx, FontMetrics fm, String text, Icon icon, int hAlign, int vAlign, int hTextPos, int vTextPos, Rectangle viewR, Rectangle iconR, Rectangle textR, int iconTextGap)
Lays out a label and (if non-null) an icon. The calculated coordinates are then stored in viewR, iconR and textR. The alignment and position parameters may be one of the alignment or position constants defined in {@link javax.swing.SwingConstants}.

Parameters: ctx the synth context, identifies the current region fm the font metrics to use to fetch the text measures text the text to lay out, may be null icon the icon to lay out, may be null hAlign the horizontal alignment of the label vAlign the vertical alignment of the label hTextPos the horizontal text position vTextPos the vertical text position viewR the view rectangle (return parameter) iconR the icon rectangle (return parameter) textR the text rectangle (return parameter) iconTextGap the gap between text and label

Returns: the label text, may be shortened

paintText

public void paintText(SynthContext ctx, Graphics g, String text, Rectangle bounds, int mnemonicIndex)
Renders the specified text within the bounds.

Parameters: ctx identifies the component and region g the graphics context for drawing the tetx text the text to be rendered bounds the bounds within which the text should be rendered mnemonicIndex the index of the mnemonic character within text

paintText

public void paintText(SynthContext ctx, Graphics g, String text, int x, int y, int mnemonicIndex)
Renders the specified text at the specified location.

Parameters: ctx identifies the component and region g the graphics context for drawing the tetx text the text to be rendered x the X location where the text should be rendered y the Y location where the text should be rendered mnemonicIndex the index of the mnemonic character within text

paintText

public void paintText(SynthContext ctx, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset)