01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.textpanel;
14:
15: import java.awt.Image;
16: import java.awt.Component;
17:
18: class OffscreenBufferCache {
19:
20: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
21: private Image fOffscreenBuffer = null;
22: private Component fHost;
23:
24: OffscreenBufferCache(Component host) {
25:
26: fHost = host;
27: }
28:
29: private Image makeBuffer(int width, int height) {
30:
31: return fHost.createImage(Math.max(width, 1), Math
32: .max(height, 1));
33: }
34:
35: Image getBuffer(int width, int height) {
36:
37: Image buffer = fOffscreenBuffer;
38:
39: if (buffer != null) {
40: if (buffer.getWidth(fHost) >= width
41: && buffer.getHeight(fHost) >= height) {
42: return buffer;
43: }
44: }
45:
46: buffer = makeBuffer(width, height);
47: fOffscreenBuffer = buffer;
48: return buffer;
49: }
50: }
|