KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > fakepeer > FakePeerContainer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.form.fakepeer;
22
23 import java.awt.*;
24
25 /**
26  *
27  * @author Tran Duc Trung
28  */

29
30 public class FakePeerContainer extends Container
31 {
32     public FakePeerContainer() {
33         super();
34         setFont(FakePeerSupport.getDefaultAWTFont());
35     }
36
37     public void addNotify() {
38         FakePeerSupport.attachFakePeerRecursively(this);
39         super.addNotify();
40     }
41
42     protected void addImpl(Component comp, Object JavaDoc constraints, int index) {
43         FakePeerSupport.attachFakePeer(comp);
44         super.addImpl(comp, constraints, index);
45     }
46     
47     public void update(Graphics g) {
48     }
49
50     public void paint(Graphics g) {
51         Dimension sz = getSize();
52 // Shape oldClip = g.getClip();
53
// g.setClip(0, 0, sz.width, sz.height);
54

55         Color c = SystemColor.control;
56         g.setColor(c);
57         g.fillRect(0, 0, sz.width, sz.height);
58 // g.setClip(oldClip);
59

60         super.paint(g);
61         paintFakePeersRecursively(g, this);
62     }
63
64     private static void paintFakePeersRecursively(Graphics g, Container container) {
65         if (!container.isVisible())
66             return;
67
68         Component components[] = FakePeerSupport.getComponents(container);
69         int ncomponents = components.length;
70
71         Rectangle clip = g.getClipBounds();
72         for (int i = 0; i < ncomponents; i++) {
73             Component comp = components[i];
74             if (comp != null &&
75                 comp.getPeer() instanceof FakePeer &&
76                 comp.isVisible()) {
77                 Rectangle cr = comp.getBounds();
78                 if ((clip == null) || cr.intersects(clip)) {
79                     Graphics cg = g.create(cr.x, cr.y, cr.width, cr.height);
80                     cg.setFont(comp.getFont());
81                     try {
82 // System.err.println("** painting " + comp.getPeer());
83
// System.err.println("** bounds = " + cr);
84
comp.getPeer().paint(cg);
85                     }
86                     finally {
87                         cg.dispose();
88                     }
89                 }
90             }
91             if (comp instanceof Container) {
92                 Rectangle cr = comp.getBounds();
93                 if ((clip == null) || cr.intersects(clip)) {
94                     Graphics cg = g.create(cr.x, cr.y, cr.width, cr.height);
95                     paintFakePeersRecursively(cg,(Container) comp);
96                     cg.dispose();
97                 }
98             }
99         }
100     }
101 }
102
Popular Tags