01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: HeavyWeightContainer.java,v 1.5 2005/12/04 13:46:04 jesper Exp $
23: package net.infonode.docking.internal;
24:
25: import java.awt.*;
26:
27: /**
28: * @author johan
29: */
30: public class HeavyWeightContainer extends Panel {
31: private Image bufferImage;
32: private boolean doubleBuffer = false;
33:
34: public HeavyWeightContainer(Component c) {
35: this (c, false);
36: }
37:
38: public HeavyWeightContainer(Component c, boolean doubleBuffer) {
39: super (new BorderLayout());
40: this .doubleBuffer = doubleBuffer;
41: add(c, BorderLayout.CENTER);
42: }
43:
44: public void invalidate() {
45: super .invalidate();
46: bufferImage = null;
47: }
48:
49: public void update(Graphics g) {
50: if (doubleBuffer)
51: paint(g);
52: else
53: super .update(g);
54: }
55:
56: public boolean isDoubleBuffered() {
57: return doubleBuffer;
58: }
59:
60: public void paint(Graphics g) {
61: if (doubleBuffer) {
62: if (bufferImage == null)
63: bufferImage = createImage(getWidth(), getHeight());
64:
65: Graphics g2 = bufferImage.getGraphics();
66: g2.setColor(getBackground());
67: g2.fillRect(0, 0, getWidth(), getHeight());
68: super .paint(g2);
69:
70: g.drawImage(bufferImage, 0, 0, null);
71: g2.dispose();
72: } else {
73: super.paint(g);
74: }
75: }
76: }
|