72 * Creates an instance of <code>CachedPainter</code> that will cache up
73 * to <code>cacheCount</code> images of this class.
74 *
75 * @param cacheCount Max number of images to cache
76 */
77 public CachedPainter(int cacheCount) {
78 getCache(getClass()).setMaxCount(cacheCount);
79 }
80
81 /**
82 * Renders the cached image to the passed in <code>Graphic</code>.
83 * If there is no cached image <code>paintToImage</code> will be invoked.
84 * <code>paintImage</code> is invoked to paint the cached image.
85 *
86 * @param c Component rendering to, this may be null.
87 * @param g Graphics to paint to
88 * @param x X-coordinate to render to
89 * @param y Y-coordinate to render to
90 * @param w Width to render in
91 * @param h Height to render in
92 * @param arg Variable arguments that will be passed to paintToImage
93 */
94 public void paint(Component c, Graphics g, int x,
95 int y, int w, int h, Object... args) {
96 if (w <= 0 || h <= 0) {
97 return;
98 }
99 if (c != null) {
100 synchronized(c.getTreeLock()) {
101 synchronized(CachedPainter.class) {
102 // If c is non-null, synchronize on the tree lock.
103 // This is necessary because asking for the
104 // GraphicsConfiguration will grab a tree lock.
105 paint0(c, g, x, y, w, h, args);
106 }
107 }
108 }
109 else {
110 synchronized(CachedPainter.class) {
111 paint0(c, g, x, y, w, h, args);
112 }
|
72 * Creates an instance of <code>CachedPainter</code> that will cache up
73 * to <code>cacheCount</code> images of this class.
74 *
75 * @param cacheCount Max number of images to cache
76 */
77 public CachedPainter(int cacheCount) {
78 getCache(getClass()).setMaxCount(cacheCount);
79 }
80
81 /**
82 * Renders the cached image to the passed in <code>Graphic</code>.
83 * If there is no cached image <code>paintToImage</code> will be invoked.
84 * <code>paintImage</code> is invoked to paint the cached image.
85 *
86 * @param c Component rendering to, this may be null.
87 * @param g Graphics to paint to
88 * @param x X-coordinate to render to
89 * @param y Y-coordinate to render to
90 * @param w Width to render in
91 * @param h Height to render in
92 * @param args Variable arguments that will be passed to paintToImage
93 */
94 public void paint(Component c, Graphics g, int x,
95 int y, int w, int h, Object... args) {
96 if (w <= 0 || h <= 0) {
97 return;
98 }
99 if (c != null) {
100 synchronized(c.getTreeLock()) {
101 synchronized(CachedPainter.class) {
102 // If c is non-null, synchronize on the tree lock.
103 // This is necessary because asking for the
104 // GraphicsConfiguration will grab a tree lock.
105 paint0(c, g, x, y, w, h, args);
106 }
107 }
108 }
109 else {
110 synchronized(CachedPainter.class) {
111 paint0(c, g, x, y, w, h, args);
112 }
|