< prev index next >

src/java.desktop/share/classes/sun/swing/plaf/synth/Paint9Painter.java

Print this page




  23  * questions.
  24  */
  25 package sun.swing.plaf.synth;
  26 
  27 import java.awt.*;
  28 import java.awt.image.BufferedImage;
  29 import sun.swing.CachedPainter;
  30 
  31 /**
  32  * Paint9Painter is used for painting images for both Synth and GTK's
  33  * pixmap/blueprint engines.
  34  *
  35  */
  36 public class Paint9Painter extends CachedPainter {
  37     /**
  38      * Enumeration for the types of painting this class can handle.
  39      */
  40     public enum PaintType {
  41         /**
  42          * Painting type indicating the image should be centered in
  43          * the space provided.  When used the <code>mask</code> is ignored.
  44          */
  45         CENTER,
  46 
  47         /**
  48          * Painting type indicating the image should be tiled across the
  49          * specified width and height.  When used the <code>mask</code> is
  50          * ignored.
  51          */
  52         TILE,
  53 
  54         /**
  55          * Painting type indicating the image should be split into nine
  56          * regions with the top, left, bottom and right areas stretched.
  57          */
  58         PAINT9_STRETCH,
  59 
  60         /**
  61          * Painting type indicating the image should be split into nine
  62          * regions with the top, left, bottom and right areas tiled.
  63          */
  64         PAINT9_TILE
  65     };
  66 
  67     private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
  68 
  69     public static final int PAINT_TOP_LEFT = 1;
  70     public static final int PAINT_TOP = 2;
  71     public static final int PAINT_TOP_RIGHT = 4;
  72     public static final int PAINT_LEFT = 8;
  73     public static final int PAINT_CENTER = 16;
  74     public static final int PAINT_RIGHT = 32;
  75     public static final int PAINT_BOTTOM_RIGHT = 64;
  76     public static final int PAINT_BOTTOM = 128;
  77     public static final int PAINT_BOTTOM_LEFT = 256;
  78     /**
  79      * Specifies that all regions should be painted.  If this is set any
  80      * other regions specified will not be painted.  For example
  81      * PAINT_ALL | PAINT_CENTER will paint all but the center.
  82      */
  83     public static final int PAINT_ALL = 512;
  84 
  85     /**
  86      * Convenience method for testing the validity of an image.
  87      *
  88      * @param image Image to check.
  89      * @return true if <code>image</code> is non-null and has a positive
  90      *         size.
  91      */
  92     public static boolean validImage(Image image) {
  93         return (image != null && image.getWidth(null) > 0 &&
  94                 image.getHeight(null) > 0);
  95     }
  96 
  97 
  98     public Paint9Painter(int cacheCount) {
  99         super(cacheCount);
 100     }
 101 
 102     /**
 103      * Paints using the algorightm specified by <code>paintType</code>.
 104      * NOTE that this just invokes super.paint(...) with the same
 105      * argument ordering as this method.
 106      *
 107      * @param c Component rendering to
 108      * @param g Graphics to render to
 109      * @param x X-coordinate
 110      * @param y Y-coordinate
 111      * @param w Width to render to
 112      * @param h Height to render to
 113      * @param source Image to render from, if <code>null</code> this method
 114      *               will do nothing
 115      * @param sInsets Insets specifying the portion of the image that
 116      *                will be stretched or tiled, if <code>null</code> empty
 117      *                <code>Insets</code> will be used.
 118      * @param dInsets Destination insets specifying the portion of the image
 119      *                will be stretched or tiled, if <code>null</code> empty
 120      *                <code>Insets</code> will be used.
 121      * @param type Specifies what type of algorithm to use in painting
 122      * @param mask Specifies portion of image to render, if
 123      *             <code>PAINT_ALL</code> is specified, any other regions
 124      *             specified will not be painted, for example
 125      *             PAINT_ALL | PAINT_CENTER paints everything but the center.
 126      */
 127     public void paint(Component c, Graphics g, int x,
 128                       int y, int w, int h, Image source, Insets sInsets,
 129                       Insets dInsets,
 130                       PaintType type, int mask) {
 131         if (source == null) {
 132             return;
 133         }
 134         super.paint(c, g, x, y, w, h, source, sInsets, dInsets, type, mask);
 135     }
 136 
 137     protected void paintToImage(Component c, Image destImage, Graphics g,
 138                                 int w, int h, Object[] args) {
 139         int argIndex = 0;
 140         while (argIndex < args.length) {
 141             Image image = (Image)args[argIndex++];
 142             Insets sInsets = (Insets)args[argIndex++];
 143             Insets dInsets = (Insets)args[argIndex++];




  23  * questions.
  24  */
  25 package sun.swing.plaf.synth;
  26 
  27 import java.awt.*;
  28 import java.awt.image.BufferedImage;
  29 import sun.swing.CachedPainter;
  30 
  31 /**
  32  * Paint9Painter is used for painting images for both Synth and GTK's
  33  * pixmap/blueprint engines.
  34  *
  35  */
  36 public class Paint9Painter extends CachedPainter {
  37     /**
  38      * Enumeration for the types of painting this class can handle.
  39      */
  40     public enum PaintType {
  41         /**
  42          * Painting type indicating the image should be centered in
  43          * the space provided.  When used the {@code mask} is ignored.
  44          */
  45         CENTER,
  46 
  47         /**
  48          * Painting type indicating the image should be tiled across the
  49          * specified width and height.  When used the {@code mask} is
  50          * ignored.
  51          */
  52         TILE,
  53 
  54         /**
  55          * Painting type indicating the image should be split into nine
  56          * regions with the top, left, bottom and right areas stretched.
  57          */
  58         PAINT9_STRETCH,
  59 
  60         /**
  61          * Painting type indicating the image should be split into nine
  62          * regions with the top, left, bottom and right areas tiled.
  63          */
  64         PAINT9_TILE
  65     };
  66 
  67     private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
  68 
  69     public static final int PAINT_TOP_LEFT = 1;
  70     public static final int PAINT_TOP = 2;
  71     public static final int PAINT_TOP_RIGHT = 4;
  72     public static final int PAINT_LEFT = 8;
  73     public static final int PAINT_CENTER = 16;
  74     public static final int PAINT_RIGHT = 32;
  75     public static final int PAINT_BOTTOM_RIGHT = 64;
  76     public static final int PAINT_BOTTOM = 128;
  77     public static final int PAINT_BOTTOM_LEFT = 256;
  78     /**
  79      * Specifies that all regions should be painted.  If this is set any
  80      * other regions specified will not be painted.  For example
  81      * PAINT_ALL | PAINT_CENTER will paint all but the center.
  82      */
  83     public static final int PAINT_ALL = 512;
  84 
  85     /**
  86      * Convenience method for testing the validity of an image.
  87      *
  88      * @param image Image to check.
  89      * @return true if {@code image} is non-null and has a positive
  90      *         size.
  91      */
  92     public static boolean validImage(Image image) {
  93         return (image != null && image.getWidth(null) > 0 &&
  94                 image.getHeight(null) > 0);
  95     }
  96 
  97 
  98     public Paint9Painter(int cacheCount) {
  99         super(cacheCount);
 100     }
 101 
 102     /**
 103      * Paints using the algorightm specified by {@code paintType}.
 104      * NOTE that this just invokes super.paint(...) with the same
 105      * argument ordering as this method.
 106      *
 107      * @param c Component rendering to
 108      * @param g Graphics to render to
 109      * @param x X-coordinate
 110      * @param y Y-coordinate
 111      * @param w Width to render to
 112      * @param h Height to render to
 113      * @param source Image to render from, if {@code null} this method
 114      *               will do nothing
 115      * @param sInsets Insets specifying the portion of the image that
 116      *                will be stretched or tiled, if {@code null} empty
 117      *                {@code Insets} will be used.
 118      * @param dInsets Destination insets specifying the portion of the image
 119      *                will be stretched or tiled, if {@code null} empty
 120      *                {@code Insets} will be used.
 121      * @param type Specifies what type of algorithm to use in painting
 122      * @param mask Specifies portion of image to render, if
 123      *             {@code PAINT_ALL} is specified, any other regions
 124      *             specified will not be painted, for example
 125      *             PAINT_ALL | PAINT_CENTER paints everything but the center.
 126      */
 127     public void paint(Component c, Graphics g, int x,
 128                       int y, int w, int h, Image source, Insets sInsets,
 129                       Insets dInsets,
 130                       PaintType type, int mask) {
 131         if (source == null) {
 132             return;
 133         }
 134         super.paint(c, g, x, y, w, h, source, sInsets, dInsets, type, mask);
 135     }
 136 
 137     protected void paintToImage(Component c, Image destImage, Graphics g,
 138                                 int w, int h, Object[] args) {
 139         int argIndex = 0;
 140         while (argIndex < args.length) {
 141             Image image = (Image)args[argIndex++];
 142             Insets sInsets = (Insets)args[argIndex++];
 143             Insets dInsets = (Insets)args[argIndex++];


< prev index next >