APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.synth

public Class SynthGraphicsUtils

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.java.swing.plaf.gtk.GTKGraphicsUtils
Imports
java.awt.Color, .Component, .Dimension, .Font, .FontMetrics, .Graphics, .Insets, .Rectangle, javax.swing.ButtonModel, .Icon, .JComponent, .JMenuItem, .SwingUtilities, javax.swing.plaf.basic.BasicHTML, javax.swing.text.View, com.sun.java.swing.SwingUtilities3, sun.swing.MenuItemLayoutHelper, .SwingUtilities2

Wrapper for primitive graphics calls.
Author
Scott Violet
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SynthGraphicsUtils.SynthIconWrapper

Wraps a SynthIcon around the Icon interface, forwarding calls to the SynthIcon with a given SynthContext.

Field Summary

Modifier and TypeField and Description
private Rectangle
private Rectangle
private Insets
private Rectangle
private Rectangle
private Rectangle
private Rectangle
private Insets

Constructor Summary

AccessConstructor and Description
public
SynthGraphicsUtils()

Creates a SynthGraphicsUtils.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the size of the passed in string.
computeStringWidth
(SynthContext
SynthContext
ss
,
Font
Font to use
font
,
FontMetrics
FontMetrics, may be ignored
metrics
,
String
Text to get size of.
text
)

Returns the size of the passed in string.

public void
drawLine(SynthContext
Identifies hosting region.
context
,
Object
Identifies the portion of the component being asked to paint, may be null.
paintKey
,
Graphics
Graphics object to paint to
g
,
int
x origin
x1
,
int
y origin
y1
,
int
x destination
x2
,
int
y destination
y2
)

Draws a line between the two end points.

public void
drawLine(SynthContext
identifies hosting region
context
,
Object
identifies the portion of the component being asked to paint, may be null
paintKey
,
Graphics
Graphics object to paint to
g
,
int
x origin
x1
,
int
y origin
y1
,
int
x destination
x2
,
int
y destination
y2
,
Object
identifies the requested style of the line (e.g. "dashed")
styleKey
)

Draws a line between the two end points.

public static int

Returns:

an int specifying the height of the icon.
getIconHeight
(Icon
the icon
icon
,
SynthContext
SynthContext requesting the icon, may be null.
context
)

Returns the icon's height.

public static int

Returns:

an int specifying the width of the icon.
getIconWidth
(Icon
the icon
icon
,
SynthContext
SynthContext requesting the icon, may be null.
context
)

Returns the icon's width.

public int

Returns:

maximum height of the characters for the font from the passed in context.
getMaximumCharHeight
(SynthContext
SynthContext used to determine font.
context
)

Returns the maximum height of the Font from the passed in SynthContext.

public Dimension

Returns:

the maximum size needed to properly render an icon and text.
getMaximumSize
(SynthContext
SynthContext
ss
,
Font
Font to use
font
,
String
Text to layout
text
,
Icon
Icon to layout
icon
,
int
horizontal alignment
hAlign
,
int
vertical alignment
vAlign
,
int
horizontal text position
hTextPosition
,
int
vertical text position
vTextPosition
,
int
gap between icon and text
iconTextGap
,
int
Index into text to render the mnemonic at, -1 indicates no mnemonic.
mnemonicIndex
)

Returns the maximum size needed to properly render an icon and text.

public Dimension

Returns:

the minimum size needed to properly render an icon and text.
getMinimumSize
(SynthContext
SynthContext
ss
,
Font
Font to use
font
,
String
Text to layout
text
,
Icon
Icon to layout
icon
,
int
horizontal alignment
hAlign
,
int
vertical alignment
vAlign
,
int
horizontal text position
hTextPosition
,
int
vertical text position
vTextPosition
,
int
gap between icon and text
iconTextGap
,
int
Index into text to render the mnemonic at, -1 indicates no mnemonic.
mnemonicIndex
)

Returns the minimum size needed to properly render an icon and text.

pack-priv static Dimension
getPreferredMenuItemSize(SynthContext context, SynthContext accContext, JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter, boolean useCheckAndArrow, String propertyPrefix)

A quick note about how preferred sizes are calculated...

public Dimension

Returns:

the preferred size needed to properly render an icon and text.
getPreferredSize
(SynthContext
SynthContext
ss
,
Font
Font to use
font
,
String
Text to layout
text
,
Icon
Icon to layout
icon
,
int
horizontal alignment
hAlign
,
int
vertical alignment
vAlign
,
int
horizontal text position
hTextPosition
,
int
vertical text position
vTextPosition
,
int
gap between icon and text
iconTextGap
,
int
Index into text to render the mnemonic at, -1 indicates no mnemonic.
mnemonicIndex
)

Returns the preferred size needed to properly render an icon and text.

public String

Returns:

by reference, the location to place the icon and text.
layoutText
(SynthContext
SynthContext
ss
,
FontMetrics
FontMetrics for the Font to use, this may be ignored
fm
,
String
Text to layout
text
,
Icon
Icon to layout
icon
,
int
horizontal alignment
hAlign
,
int
vertical alignment
vAlign
,
int
horizontal text position
hTextPosition
,
int
vertical text position
vTextPosition
,
Rectangle
Rectangle to layout text and icon in.
viewR
,
Rectangle
Rectangle to place icon bounds in
iconR
,
Rectangle
Rectangle to place text in
textR
,
int
gap between icon and text
iconTextGap
)

Lays out text and an icon returning, by reference, the location to place the icon and text.

pack-priv static void
paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix)

pack-priv static void
pack-priv static void
pack-priv static void
pack-priv static void
pack-priv static void
public static void
paintIcon(Icon
the icon
icon
,
SynthContext
identifies hosting region, may be null.
context
,
Graphics
the graphics context
g
,
int
the x location to paint to
x
,
int
the y location to paint to
y
,
int
the width of the region to paint to, may be 0
width
,
int
the height of the region to paint to, may be 0
height
)

Paints the icon.

pack-priv static void
pack-priv static void
public void
paintText(SynthContext
SynthContext
ss
,
Graphics
Graphics used to render string in.
g
,
String
Text to render
text
,
Rectangle
Bounds of the text to be drawn.
bounds
,
int
Index to draw string at.
mnemonicIndex
)

Paints text at the specified location.

public void
paintText(SynthContext
SynthContext
ss
,
Graphics
Graphics used to render string in.
g
,
String
Text to render
text
,
int
X location to draw text at.
x
,
int
Upper left corner to draw text at.
y
,
int
Index to draw string at.
mnemonicIndex
)

Paints text at the specified location.

public void
paintText(SynthContext
SynthContext
ss
,
Graphics
Graphics to render string and icon into
g
,
String
Text to layout
text
,
Icon
Icon to layout
icon
,
int
horizontal alignment
hAlign
,
int
vertical alignment
vAlign
,
int
horizontal text position
hTextPosition
,
int
vertical text position
vTextPosition
,
int
gap between icon and text
iconTextGap
,
int
Index into text to render the mnemonic at, -1 indicates no mnemonic.
mnemonicIndex
,
int
Amount to offset the text when painting
textOffset
)

Paints an icon and text.

pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iconRback to summary
private Rectangle iconR
paintIconRback to summary
private Rectangle paintIconR
paintInsetsback to summary
private Insets paintInsets
paintTextRback to summary
private Rectangle paintTextR
paintViewRback to summary
private Rectangle paintViewR
textRback to summary
private Rectangle textR
viewRback to summary
private Rectangle viewR
viewSizingInsetsback to summary
private Insets viewSizingInsets

Constructor Detail

SynthGraphicsUtilsback to summary
public SynthGraphicsUtils()

Creates a SynthGraphicsUtils.

Method Detail

computeStringWidthback to summary
public int computeStringWidth(SynthContext ss, Font font, FontMetrics metrics, String text)

Returns the size of the passed in string.

Parameters
ss:SynthContext

SynthContext

font:Font

Font to use

metrics:FontMetrics

FontMetrics, may be ignored

text:String

Text to get size of.

Returns:int

the size of the passed in string.

drawLineback to summary
public void drawLine(SynthContext context, Object paintKey, Graphics g, int x1, int y1, int x2, int y2)

Draws a line between the two end points.

Parameters
context:SynthContext

Identifies hosting region.

paintKey:Object

Identifies the portion of the component being asked to paint, may be null.

g:Graphics

Graphics object to paint to

x1:int

x origin

y1:int

y origin

x2:int

x destination

y2:int

y destination

drawLineback to summary
public void drawLine(SynthContext context, Object paintKey, Graphics g, int x1, int y1, int x2, int y2, Object styleKey)

Draws a line between the two end points.

This implementation supports only one line style key, "dashed". The "dashed" line style is applied only to vertical and horizontal lines.

Specifying null or any key different from "dashed" will draw solid lines.

Parameters
context:SynthContext

identifies hosting region

paintKey:Object

identifies the portion of the component being asked to paint, may be null

g:Graphics

Graphics object to paint to

x1:int

x origin

y1:int

y origin

x2:int

x destination

y2:int

y destination

styleKey:Object

identifies the requested style of the line (e.g. "dashed")

Since
1.6
getIconHeightback to summary
public static int getIconHeight(Icon icon, SynthContext context)

Returns the icon's height. The getIconHeight(context) method is called for SynthIcon.

Parameters
icon:Icon

the icon

context:SynthContext

SynthContext requesting the icon, may be null.

Returns:int

an int specifying the height of the icon.

getIconWidthback to summary
public static int getIconWidth(Icon icon, SynthContext context)

Returns the icon's width. The getIconWidth(context) method is called for SynthIcon.

Parameters
icon:Icon

the icon

context:SynthContext

SynthContext requesting the icon, may be null.

Returns:int

an int specifying the width of the icon.

getMaximumCharHeightback to summary
public int getMaximumCharHeight(SynthContext context)

Returns the maximum height of the Font from the passed in SynthContext.

Parameters
context:SynthContext

SynthContext used to determine font.

Returns:int

maximum height of the characters for the font from the passed in context.

getMaximumSizeback to summary
public Dimension getMaximumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)

Returns the maximum size needed to properly render an icon and text.

Parameters
ss:SynthContext

SynthContext

font:Font

Font to use

text:String

Text to layout

icon:Icon

Icon to layout

hAlign:int

horizontal alignment

vAlign:int

vertical alignment

hTextPosition:int

horizontal text position

vTextPosition:int

vertical text position

iconTextGap:int

gap between icon and text

mnemonicIndex:int

Index into text to render the mnemonic at, -1 indicates no mnemonic.

Returns:Dimension

the maximum size needed to properly render an icon and text.

getMinimumSizeback to summary
public Dimension getMinimumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)

Returns the minimum size needed to properly render an icon and text.

Parameters
ss:SynthContext

SynthContext

font:Font

Font to use

text:String

Text to layout

icon:Icon

Icon to layout

hAlign:int

horizontal alignment

vAlign:int

vertical alignment

hTextPosition:int

horizontal text position

vTextPosition:int

vertical text position

iconTextGap:int

gap between icon and text

mnemonicIndex:int

Index into text to render the mnemonic at, -1 indicates no mnemonic.

Returns:Dimension

the minimum size needed to properly render an icon and text.

getPreferredMenuItemSizeback to summary
pack-priv static Dimension getPreferredMenuItemSize(SynthContext context, SynthContext accContext, JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter, boolean useCheckAndArrow, String propertyPrefix)

A quick note about how preferred sizes are calculated... Generally speaking, SynthPopupMenuUI will run through the list of its children (from top to bottom) and ask each for its preferred size. Each menu item will add up the max width of each element (icons, text, accelerator spacing, accelerator text or arrow icon) encountered thus far, so by the time all menu items have been calculated, we will know the maximum (preferred) menu item size for that popup menu. Later when it comes time to paint each menu item, we can use those same accumulated max element sizes in order to layout the item.

getPreferredSizeback to summary
public Dimension getPreferredSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex)

Returns the preferred size needed to properly render an icon and text.

Parameters
ss:SynthContext

SynthContext

font:Font

Font to use

text:String

Text to layout

icon:Icon

Icon to layout

hAlign:int

horizontal alignment

vAlign:int

vertical alignment

hTextPosition:int

horizontal text position

vTextPosition:int

vertical text position

iconTextGap:int

gap between icon and text

mnemonicIndex:int

Index into text to render the mnemonic at, -1 indicates no mnemonic.

Returns:Dimension

the preferred size needed to properly render an icon and text.

layoutTextback to summary
public String layoutText(SynthContext ss, FontMetrics fm, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int iconTextGap)

Lays out text and an icon returning, by reference, the location to place the icon and text.

Parameters
ss:SynthContext

SynthContext

fm:FontMetrics

FontMetrics for the Font to use, this may be ignored

text:String

Text to layout

icon:Icon

Icon to layout

hAlign:int

horizontal alignment

vAlign:int

vertical alignment

hTextPosition:int

horizontal text position

vTextPosition:int

vertical text position

viewR:Rectangle

Rectangle to layout text and icon in.

iconR:Rectangle

Rectangle to place icon bounds in

textR:Rectangle

Rectangle to place text in

iconTextGap:int

gap between icon and text

Returns:String

by reference, the location to place the icon and text.

paintback to summary
pack-priv static void paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix)
paintAccTextback to summary
pack-priv static void paintAccText(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
paintArrowIconback to summary
pack-priv static void paintArrowIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
paintBackgroundback to summary
pack-priv static void paintBackground(Graphics g, SynthMenuItemLayoutHelper lh)
paintBackgroundback to summary
pack-priv static void paintBackground(SynthContext context, Graphics g, JComponent c)
paintCheckIconback to summary
pack-priv static void paintCheckIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
paintIconback to summary
public static void paintIcon(Icon icon, SynthContext context, Graphics g, int x, int y, int width, int height)

Paints the icon. The paintIcon(context, g, x, y, width, height) method is called for SynthIcon.

Parameters
icon:Icon

the icon

context:SynthContext

identifies hosting region, may be null.

g:Graphics

the graphics context

x:int

the x location to paint to

y:int

the y location to paint to

width:int

the width of the region to paint to, may be 0

height:int

the height of the region to paint to, may be 0

paintIconback to summary
pack-priv static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
paintMenuItemback to summary
pack-priv static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
paintTextback to summary
public void paintText(SynthContext ss, Graphics g, String text, Rectangle bounds, int mnemonicIndex)

Paints text at the specified location. This will not attempt to render the text as html nor will it offset by the insets of the component.

Parameters
ss:SynthContext

SynthContext

g:Graphics

Graphics used to render string in.

text:String

Text to render

bounds:Rectangle

Bounds of the text to be drawn.

mnemonicIndex:int

Index to draw string at.

paintTextback to summary
public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex)

Paints text at the specified location. This will not attempt to render the text as html nor will it offset by the insets of the component.

Parameters
ss:SynthContext

SynthContext

g:Graphics

Graphics used to render string in.

text:String

Text to render

x:int

X location to draw text at.

y:int

Upper left corner to draw text at.

mnemonicIndex:int

Index to draw string at.

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

Paints an icon and text. This will render the text as html, if necessary, and offset the location by the insets of the component.

Parameters
ss:SynthContext

SynthContext

g:Graphics

Graphics to render string and icon into

text:String

Text to layout

icon:Icon

Icon to layout

hAlign:int

horizontal alignment

vAlign:int

vertical alignment

hTextPosition:int

horizontal text position

vTextPosition:int

vertical text position

iconTextGap:int

gap between icon and text

mnemonicIndex:int

Index into text to render the mnemonic at, -1 indicates no mnemonic.

textOffset:int

Amount to offset the text when painting

paintTextback to summary
pack-priv static void paintText(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr)
javax.swing.plaf.synth back to summary

private Class SynthGraphicsUtils.SynthIconWrapper

extends Object
implements Icon
Class Inheritance
All Implemented Interfaces
javax.swing.Icon

Wraps a SynthIcon around the Icon interface, forwarding calls to the SynthIcon with a given SynthContext.

Field Summary

Modifier and TypeField and Description
private static final List<SynthGraphicsUtils.SynthIconWrapper>
private SynthContext
private SynthIcon

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static SynthGraphicsUtils.SynthIconWrapper
get(SynthIcon icon, SynthContext context)

public int
getIconHeight()

Implements javax.swing.Icon.getIconHeight.

Returns the icon's height.

public int
getIconWidth()

Implements javax.swing.Icon.getIconWidth.

Returns the icon's width.

public void
paintIcon(Component c, Graphics g, int x, int y)

Implements javax.swing.Icon.paintIcon.

Draw the icon at the specified location.

pack-priv static void
pack-priv void
reset(SynthIcon icon, SynthContext context)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHEback to summary
private static final List<SynthGraphicsUtils.SynthIconWrapper> CACHE
contextback to summary
private SynthContext context
synthIconback to summary
private SynthIcon synthIcon

Constructor Detail

SynthIconWrapperback to summary
pack-priv SynthIconWrapper(SynthIcon icon, SynthContext context)

Method Detail

getback to summary
pack-priv static SynthGraphicsUtils.SynthIconWrapper get(SynthIcon icon, SynthContext context)
getIconHeightback to summary
public int getIconHeight()

Implements javax.swing.Icon.getIconHeight.

Doc from javax.swing.Icon.getIconHeight.

Returns the icon's height.

getIconWidthback to summary
public int getIconWidth()

Implements javax.swing.Icon.getIconWidth.

Doc from javax.swing.Icon.getIconWidth.

Returns the icon's width.

paintIconback to summary
public void paintIcon(Component c, Graphics g, int x, int y)

Implements javax.swing.Icon.paintIcon.

Doc from javax.swing.Icon.paintIcon.

Draw the icon at the specified location. Icon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.

releaseback to summary
pack-priv static void release(SynthGraphicsUtils.SynthIconWrapper wrapper)
resetback to summary
pack-priv void reset(SynthIcon icon, SynthContext context)