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

int
computeStringWidth(SynthContext ctx, Font font, FontMetrics fm, String text)
Returns the width of the string text for the specified font and font metrics.
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).
int
getMaximumCharHeight(SynthContext context)
Returns the maximum character height of the font from the component of the passed in context.
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.
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.
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.
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.
void
paintText(SynthContext ctx, Graphics g, String text, int x, int y, int mnemonicIndex)
Renders the specified text at the specified location.
void
paintText(SynthContext ctx, Graphics g, String text, Rectangle bounds, int mnemonicIndex)
Renders the specified text within the bounds.
void
paintText(SynthContext ctx, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset)

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

SynthGraphicsUtils

public SynthGraphicsUtils()
Creates a new SynthGraphicsUtils object.

Method Details

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)
            throws gnu.classpath.NotImplementedException
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)
            throws gnu.classpath.NotImplementedException
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)
            throws gnu.classpath.NotImplementedException
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 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,
                      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,
                      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,
                      Icon icon,
                      int hAlign,
                      int vAlign,
                      int hTextPosition,
                      int vTextPosition,
                      int iconTextGap,
                      int mnemonicIndex,
                      int textOffset)
            throws gnu.classpath.NotImplementedException

SynthGraphicsUtils.java -- Wrapper for graphics primitives used in Synth Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.