KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java2d > GlobalPanel


1 /*
2  * @(#)GlobalPanel.java 1.20 05/11/30
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36
37 /*
38  * @(#)GlobalPanel.java 1.20 05/11/30
39  */

40
41
42 package java2d;
43
44 import java.awt.GridBagLayout JavaDoc;
45 import java.awt.BorderLayout JavaDoc;
46 import javax.swing.JPanel JavaDoc;
47 import javax.swing.JTabbedPane JavaDoc;
48 import javax.swing.border.*;
49 import javax.swing.event.ChangeEvent JavaDoc;
50 import javax.swing.event.ChangeListener JavaDoc;
51
52
53 /**
54  * Panel that holds the Demo groups, Controls and Monitors for each tab.
55  * It's a special "always visible" panel for the Controls, MemoryMonitor &
56  * PerformanceMonitor.
57  */

58 public class GlobalPanel extends JPanel JavaDoc implements ChangeListener JavaDoc {
59
60
61     private JPanel JavaDoc p;
62     private int index;
63
64
65     public GlobalPanel() {
66         setLayout(new BorderLayout JavaDoc());
67         p = new JPanel JavaDoc(new GridBagLayout JavaDoc());
68         EmptyBorder eb = new EmptyBorder(5,0,5,5);
69         BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
70         p.setBorder(new CompoundBorder(eb,bb));
71         Java2Demo.addToGridBag(p,Java2Demo.controls,0,0,1,1,0,0);
72         Java2Demo.addToGridBag(p,Java2Demo.memorymonitor,0,1,1,1,0,0);
73         Java2Demo.addToGridBag(p,Java2Demo.performancemonitor,0,2,1,1,0,0);
74         add(Java2Demo.intro);
75     }
76
77
78     public void stateChanged(ChangeEvent JavaDoc e) {
79          
80         Java2Demo.group[index].shutDown(Java2Demo.group[index].getPanel());
81         if (Java2Demo.tabbedPane.getSelectedIndex() == 0) {
82             Java2Demo.memorymonitor.surf.stop();
83             Java2Demo.performancemonitor.surf.stop();
84             removeAll();
85             add(Java2Demo.intro);
86             Java2Demo.intro.start();
87         } else {
88             if (getComponentCount() == 1) {
89                 Java2Demo.intro.stop();
90                 remove(Java2Demo.intro);
91                 add(p, BorderLayout.EAST);
92                 if (Java2Demo.memoryCB.getState()) {
93                     Java2Demo.memorymonitor.surf.start();
94                 }
95                 if (Java2Demo.perfCB.getState()) {
96                     Java2Demo.performancemonitor.surf.start();
97                 }
98             } else {
99                 remove(Java2Demo.group[index]);
100             }
101             index = Java2Demo.tabbedPane.getSelectedIndex()-1;
102             add(Java2Demo.group[index]);
103             Java2Demo.group[index].setup(false);
104         }
105         revalidate();
106     }
107 }
108
Popular Tags