< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java

Print this page




  38  *
  39  * @since 1.5
  40  * @author Scott Violet
  41  */
  42 public class SynthGraphicsUtils {
  43     // These are used in the text painting code to avoid allocating a bunch of
  44     // garbage.
  45     private Rectangle paintIconR = new Rectangle();
  46     private Rectangle paintTextR = new Rectangle();
  47     private Rectangle paintViewR = new Rectangle();
  48     private Insets paintInsets = new Insets(0, 0, 0, 0);
  49 
  50     // These Rectangles/Insets are used in the text size calculation to avoid a
  51     // a bunch of garbage.
  52     private Rectangle iconR = new Rectangle();
  53     private Rectangle textR = new Rectangle();
  54     private Rectangle viewR = new Rectangle();
  55     private Insets viewSizingInsets = new Insets(0, 0, 0, 0);
  56 
  57     /**
  58      * Creates a <code>SynthGraphicsUtils</code>.
  59      */
  60     public SynthGraphicsUtils() {
  61     }
  62 
  63     /**
  64      * Draws a line between the two end points.
  65      *
  66      * @param context Identifies hosting region.
  67      * @param paintKey Identifies the portion of the component being asked
  68      *                 to paint, may be null.
  69      * @param g Graphics object to paint to
  70      * @param x1 x origin
  71      * @param y1 y origin
  72      * @param x2 x destination
  73      * @param y2 y destination
  74      */
  75     public void drawLine(SynthContext context, Object paintKey,
  76                          Graphics g, int x1, int y1, int x2, int y2) {
  77         g.drawLine(x1, y1, x2, y2);
  78     }
  79 
  80     /**
  81      * Draws a line between the two end points.
  82      * <p>This implementation supports only one line style key,
  83      * <code>"dashed"</code>. The <code>"dashed"</code> line style is applied
  84      * only to vertical and horizontal lines.
  85      * <p>Specifying <code>null</code> or any key different from
  86      * <code>"dashed"</code> will draw solid lines.
  87      *
  88      * @param context identifies hosting region
  89      * @param paintKey identifies the portion of the component being asked
  90      *                 to paint, may be null
  91      * @param g Graphics object to paint to
  92      * @param x1 x origin
  93      * @param y1 y origin
  94      * @param x2 x destination
  95      * @param y2 y destination
  96      * @param styleKey identifies the requested style of the line (e.g. "dashed")
  97      * @since 1.6
  98      */
  99     public void drawLine(SynthContext context, Object paintKey,
 100                          Graphics g, int x1, int y1, int x2, int y2,
 101                          Object styleKey) {
 102         if ("dashed".equals(styleKey)) {
 103             // draw vertical line
 104             if (x1 == x2) {
 105                 y1 += (y1 % 2);
 106 




  38  *
  39  * @since 1.5
  40  * @author Scott Violet
  41  */
  42 public class SynthGraphicsUtils {
  43     // These are used in the text painting code to avoid allocating a bunch of
  44     // garbage.
  45     private Rectangle paintIconR = new Rectangle();
  46     private Rectangle paintTextR = new Rectangle();
  47     private Rectangle paintViewR = new Rectangle();
  48     private Insets paintInsets = new Insets(0, 0, 0, 0);
  49 
  50     // These Rectangles/Insets are used in the text size calculation to avoid a
  51     // a bunch of garbage.
  52     private Rectangle iconR = new Rectangle();
  53     private Rectangle textR = new Rectangle();
  54     private Rectangle viewR = new Rectangle();
  55     private Insets viewSizingInsets = new Insets(0, 0, 0, 0);
  56 
  57     /**
  58      * Creates a {@code SynthGraphicsUtils}.
  59      */
  60     public SynthGraphicsUtils() {
  61     }
  62 
  63     /**
  64      * Draws a line between the two end points.
  65      *
  66      * @param context Identifies hosting region.
  67      * @param paintKey Identifies the portion of the component being asked
  68      *                 to paint, may be null.
  69      * @param g Graphics object to paint to
  70      * @param x1 x origin
  71      * @param y1 y origin
  72      * @param x2 x destination
  73      * @param y2 y destination
  74      */
  75     public void drawLine(SynthContext context, Object paintKey,
  76                          Graphics g, int x1, int y1, int x2, int y2) {
  77         g.drawLine(x1, y1, x2, y2);
  78     }
  79 
  80     /**
  81      * Draws a line between the two end points.
  82      * <p>This implementation supports only one line style key,
  83      * {@code "dashed"}. The {@code "dashed"} line style is applied
  84      * only to vertical and horizontal lines.
  85      * <p>Specifying {@code null} or any key different from
  86      * {@code "dashed"} will draw solid lines.
  87      *
  88      * @param context identifies hosting region
  89      * @param paintKey identifies the portion of the component being asked
  90      *                 to paint, may be null
  91      * @param g Graphics object to paint to
  92      * @param x1 x origin
  93      * @param y1 y origin
  94      * @param x2 x destination
  95      * @param y2 y destination
  96      * @param styleKey identifies the requested style of the line (e.g. "dashed")
  97      * @since 1.6
  98      */
  99     public void drawLine(SynthContext context, Object paintKey,
 100                          Graphics g, int x1, int y1, int x2, int y2,
 101                          Object styleKey) {
 102         if ("dashed".equals(styleKey)) {
 103             // draw vertical line
 104             if (x1 == x2) {
 105                 y1 += (y1 % 2);
 106 


< prev index next >