SynthGraphicsUtilspublic class SynthGraphicsUtils extends Object Wrapper for primitive graphics calls. |
Fields Summary |
---|
private Rectangle | paintIconR | private Rectangle | paintTextR | private Rectangle | paintViewR | private Insets | paintInsets | private Rectangle | iconR | private Rectangle | textR | private Rectangle | viewR | private Insets | viewSizingInsets |
Constructors Summary |
---|
public SynthGraphicsUtils()Creates a SynthGraphicsUtils .
|
Methods Summary |
---|
public int | computeStringWidth(javax.swing.plaf.synth.SynthContext ss, java.awt.Font font, java.awt.FontMetrics metrics, java.lang.String text)Returns the size of the passed in string.
return SwingUtilities2.stringWidth(ss.getComponent(), metrics,
text);
| public void | drawLine(javax.swing.plaf.synth.SynthContext context, java.lang.Object paintKey, java.awt.Graphics g, int x1, int y1, int x2, int y2)Draws a line between the two end points.
g.drawLine(x1, y1, x2, y2);
| public void | drawLine(javax.swing.plaf.synth.SynthContext context, java.lang.Object paintKey, java.awt.Graphics g, int x1, int y1, int x2, int y2, java.lang.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.
if ("dashed".equals(styleKey)) {
// draw vertical line
if (x1 == x2) {
y1 += (y1 % 2);
for (int y = y1; y <= y2; y+=2) {
g.drawLine(x1, y, x2, y);
}
// draw horizontal line
} else if (y1 == y2) {
x1 += (x1 % 2);
for (int x = x1; x <= x2; x+=2) {
g.drawLine(x, y1, x, y2);
}
// oblique lines are not supported
}
} else {
drawLine(context, paintKey, g, x1, y1, x2, y2);
}
| public int | getMaximumCharHeight(javax.swing.plaf.synth.SynthContext context)Returns the maximum height of the the Font from the passed in
SynthContext.
FontMetrics fm = context.getComponent().getFontMetrics(
context.getStyle().getFont(context));
return (fm.getAscent() + fm.getDescent());
| public java.awt.Dimension | getMaximumSize(javax.swing.plaf.synth.SynthContext ss, java.awt.Font font, java.lang.String text, javax.swing.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.
JComponent c = ss.getComponent();
Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
vAlign, hTextPosition, vTextPosition,
iconTextGap, mnemonicIndex);
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
size.width += v.getMaximumSpan(View.X_AXIS) -
v.getPreferredSpan(View.X_AXIS);
}
return size;
| public java.awt.Dimension | getMinimumSize(javax.swing.plaf.synth.SynthContext ss, java.awt.Font font, java.lang.String text, javax.swing.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.
JComponent c = ss.getComponent();
Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
vAlign, hTextPosition, vTextPosition,
iconTextGap, mnemonicIndex);
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
size.width -= v.getPreferredSpan(View.X_AXIS) -
v.getMinimumSpan(View.X_AXIS);
}
return size;
| public java.awt.Dimension | getPreferredSize(javax.swing.plaf.synth.SynthContext ss, java.awt.Font font, java.lang.String text, javax.swing.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.
JComponent c = ss.getComponent();
Insets insets = c.getInsets(viewSizingInsets);
int dx = insets.left + insets.right;
int dy = insets.top + insets.bottom;
if (icon == null && (text == null || font == null)) {
return new Dimension(dx, dy);
}
else if ((text == null) || ((icon != null) && (font == null))) {
return new Dimension(SynthIcon.getIconWidth(icon, ss) + dx,
SynthIcon.getIconHeight(icon, ss) + dy);
}
else {
FontMetrics fm = c.getFontMetrics(font);
iconR.x = iconR.y = iconR.width = iconR.height = 0;
textR.x = textR.y = textR.width = textR.height = 0;
viewR.x = dx;
viewR.y = dy;
viewR.width = viewR.height = Short.MAX_VALUE;
layoutText(ss, fm, text, icon, hAlign, vAlign,
hTextPosition, vTextPosition, viewR, iconR, textR,
iconTextGap);
int x1 = Math.min(iconR.x, textR.x);
int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width);
int y1 = Math.min(iconR.y, textR.y);
int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height);
Dimension rv = new Dimension(x2 - x1, y2 - y1);
rv.width += dx;
rv.height += dy;
return rv;
}
| public java.lang.String | layoutText(javax.swing.plaf.synth.SynthContext ss, java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int iconTextGap)Lays out text and an icon returning, by reference, the location to
place the icon and text.
if (icon instanceof SynthIcon) {
SynthIconWrapper wrapper = SynthIconWrapper.get((SynthIcon)icon,
ss);
String formattedText = SwingUtilities.layoutCompoundLabel(
ss.getComponent(), fm, text, wrapper, vAlign, hAlign,
vTextPosition, hTextPosition, viewR, iconR, textR,
iconTextGap);
SynthIconWrapper.release(wrapper);
return formattedText;
}
return SwingUtilities.layoutCompoundLabel(
ss.getComponent(), fm, text, icon, vAlign, hAlign,
vTextPosition, hTextPosition, viewR, iconR, textR,
iconTextGap);
| public void | paintText(javax.swing.plaf.synth.SynthContext ss, java.awt.Graphics g, java.lang.String text, java.awt.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.
paintText(ss, g, text, bounds.x, bounds.y, mnemonicIndex);
| public void | paintText(javax.swing.plaf.synth.SynthContext ss, java.awt.Graphics g, java.lang.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.
if (text != null) {
JComponent c = ss.getComponent();
SynthStyle style = ss.getStyle();
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
y += fm.getAscent();
SwingUtilities2.drawString(c, g, text, x, y);
if (mnemonicIndex >= 0 && mnemonicIndex < text.length()) {
int underlineX = x + SwingUtilities2.stringWidth(
c, fm, text.substring(0, mnemonicIndex));
int underlineY = y;
int underlineWidth = fm.charWidth(text.charAt(mnemonicIndex));
int underlineHeight = 1;
g.fillRect(underlineX, underlineY + fm.getDescent() - 1,
underlineWidth, underlineHeight);
}
}
| public void | paintText(javax.swing.plaf.synth.SynthContext ss, java.awt.Graphics g, java.lang.String text, javax.swing.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.
if ((icon == null) && (text == null)) {
return;
}
JComponent c = ss.getComponent();
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets);
paintViewR.x = insets.left;
paintViewR.y = insets.top;
paintViewR.width = c.getWidth() - (insets.left + insets.right);
paintViewR.height = c.getHeight() - (insets.top + insets.bottom);
paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
String clippedText =
layoutText(ss, fm, text, icon, hAlign, vAlign,
hTextPosition, vTextPosition, paintViewR, paintIconR,
paintTextR, iconTextGap);
if (icon != null) {
Color color = g.getColor();
paintIconR.x += textOffset;
paintIconR.y += textOffset;
SynthIcon.paintIcon(icon, ss, g, paintIconR.x, paintIconR.y,
paintIconR.width, paintIconR.height);
g.setColor(color);
}
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, paintTextR);
} else {
paintTextR.x += textOffset;
paintTextR.y += textOffset;
paintText(ss, g, clippedText, paintTextR, mnemonicIndex);
}
}
|
|