Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/demo/share/jfc/J2Ddemo/java2d/GlobalPanel.java
41154 views
1
/*
2
*
3
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
*
12
* - Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* - Neither the name of Oracle nor the names of its
17
* contributors may be used to endorse or promote products derived
18
* from this software without specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
package java2d;
33
34
35
import java.awt.BorderLayout;
36
import java.awt.GridBagLayout;
37
import javax.swing.JPanel;
38
import javax.swing.border.BevelBorder;
39
import javax.swing.border.CompoundBorder;
40
import javax.swing.border.EmptyBorder;
41
import javax.swing.event.ChangeEvent;
42
import javax.swing.event.ChangeListener;
43
44
45
/**
46
* Panel that holds the Demo groups, Controls and Monitors for each tab.
47
* It's a special "always visible" panel for the Controls, MemoryMonitor &
48
* PerformanceMonitor.
49
*/
50
@SuppressWarnings("serial")
51
public class GlobalPanel extends JPanel implements ChangeListener {
52
private final DemoInstVarsAccessor demoInstVars;
53
private JPanel p;
54
private int index;
55
56
public GlobalPanel(DemoInstVarsAccessor demoInstVars) {
57
this.demoInstVars = demoInstVars;
58
59
setLayout(new BorderLayout());
60
p = new JPanel(new GridBagLayout());
61
EmptyBorder eb = new EmptyBorder(5, 0, 5, 5);
62
BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
63
p.setBorder(new CompoundBorder(eb, bb));
64
J2Ddemo.addToGridBag(p, demoInstVars.getControls(), 0, 0, 1, 1, 0, 0);
65
J2Ddemo.addToGridBag(p, demoInstVars.getMemoryMonitor(), 0, 1, 1, 1, 0, 0);
66
J2Ddemo.addToGridBag(p, demoInstVars.getPerformanceMonitor(), 0, 2, 1, 1, 0, 0);
67
add(demoInstVars.getIntro());
68
}
69
70
@Override
71
public void stateChanged(ChangeEvent e) {
72
73
demoInstVars.getGroup()[index].shutDown(demoInstVars.getGroup()[index].getPanel());
74
if (demoInstVars.getTabbedPane().getSelectedIndex() == 0) {
75
demoInstVars.getMemoryMonitor().surf.stop();
76
demoInstVars.getPerformanceMonitor().surf.stop();
77
removeAll();
78
add(demoInstVars.getIntro());
79
demoInstVars.getIntro().start();
80
} else {
81
if (getComponentCount() == 1) {
82
demoInstVars.getIntro().stop();
83
remove(demoInstVars.getIntro());
84
add(p, BorderLayout.EAST);
85
if (demoInstVars.getMemoryCB().getState()) {
86
demoInstVars.getMemoryMonitor().surf.start();
87
}
88
if (demoInstVars.getPerfCB().getState()) {
89
demoInstVars.getPerformanceMonitor().surf.start();
90
}
91
} else {
92
remove(demoInstVars.getGroup()[index]);
93
}
94
index = demoInstVars.getTabbedPane().getSelectedIndex() - 1;
95
add(demoInstVars.getGroup()[index]);
96
demoInstVars.getGroup()[index].setup(false);
97
}
98
revalidate();
99
}
100
}
101
102