Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/lib/SwingSet2/src/DemoModule.java
41161 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.awt.BorderLayout;
25
import java.awt.Dimension;
26
import java.io.BufferedReader;
27
import java.io.InputStream;
28
import java.io.InputStreamReader;
29
import java.net.URL;
30
31
import javax.swing.BoxLayout;
32
import javax.swing.Icon;
33
import javax.swing.ImageIcon;
34
import javax.swing.JApplet;
35
import javax.swing.JFrame;
36
import javax.swing.JPanel;
37
import javax.swing.UIManager;
38
import javax.swing.border.Border;
39
import javax.swing.border.CompoundBorder;
40
import javax.swing.border.EmptyBorder;
41
import javax.swing.border.SoftBevelBorder;
42
43
/**
44
* A generic SwingSet2 demo module
45
*
46
* @author Jeff Dinkins
47
*/
48
public class DemoModule extends JApplet {
49
50
// The preferred size of the demo
51
private int PREFERRED_WIDTH = 680;
52
private int PREFERRED_HEIGHT = 600;
53
54
Border loweredBorder = new CompoundBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED),
55
new EmptyBorder(5,5,5,5));
56
57
// Premade convenience dimensions, for use wherever you need 'em.
58
public static Dimension HGAP2 = new Dimension(2,1);
59
public static Dimension VGAP2 = new Dimension(1,2);
60
61
public static Dimension HGAP5 = new Dimension(5,1);
62
public static Dimension VGAP5 = new Dimension(1,5);
63
64
public static Dimension HGAP10 = new Dimension(10,1);
65
public static Dimension VGAP10 = new Dimension(1,10);
66
67
public static Dimension HGAP15 = new Dimension(15,1);
68
public static Dimension VGAP15 = new Dimension(1,15);
69
70
public static Dimension HGAP20 = new Dimension(20,1);
71
public static Dimension VGAP20 = new Dimension(1,20);
72
73
public static Dimension HGAP25 = new Dimension(25,1);
74
public static Dimension VGAP25 = new Dimension(1,25);
75
76
public static Dimension HGAP30 = new Dimension(30,1);
77
public static Dimension VGAP30 = new Dimension(1,30);
78
79
private SwingSet2 swingset = null;
80
private JPanel panel = null;
81
private String resourceName = null;
82
private String iconPath = null;
83
private String sourceCode = null;
84
85
public DemoModule(SwingSet2 swingset) {
86
this(swingset, null, null);
87
}
88
89
public DemoModule(SwingSet2 swingset, String resourceName, String iconPath) {
90
UIManager.put("swing.boldMetal", Boolean.FALSE);
91
panel = new JPanel();
92
panel.setLayout(new BorderLayout());
93
94
this.resourceName = resourceName;
95
this.iconPath = iconPath;
96
this.swingset = swingset;
97
98
loadSourceCode();
99
}
100
101
public String getResourceName() {
102
return resourceName;
103
}
104
105
public JPanel getDemoPanel() {
106
return panel;
107
}
108
109
public SwingSet2 getSwingSet2() {
110
return swingset;
111
}
112
113
114
public String getString(String key) {
115
116
if (getSwingSet2() != null) {
117
return getSwingSet2().getString(key);
118
}else{
119
return "nada";
120
}
121
}
122
123
public char getMnemonic(String key) {
124
return (getString(key)).charAt(0);
125
}
126
127
public ImageIcon createImageIcon(String filename, String description) {
128
if(getSwingSet2() != null) {
129
return getSwingSet2().createImageIcon(filename, description);
130
} else {
131
String path = "/resources/images/" + filename;
132
return new ImageIcon(getClass().getResource(path), description);
133
}
134
}
135
136
137
public String getSourceCode() {
138
return sourceCode;
139
}
140
141
public void loadSourceCode() {
142
if(getResourceName() != null) {
143
String filename = getResourceName() + ".java";
144
sourceCode = new String("<html><body bgcolor=\"#ffffff\"><pre>");
145
InputStream is;
146
InputStreamReader isr;
147
URL url;
148
149
try {
150
url = getClass().getResource(filename);
151
is = url.openStream();
152
isr = new InputStreamReader(is, "UTF-8");
153
BufferedReader reader = new BufferedReader(isr);
154
155
// Read one line at a time, htmlize using super-spiffy
156
// html java code formating utility from www.CoolServlets.com
157
String line = reader.readLine();
158
while(line != null) {
159
sourceCode += line + " \n ";
160
line = reader.readLine();
161
}
162
sourceCode += new String("</pre></body></html>");
163
} catch (Exception ex) {
164
sourceCode = "Could not load file: " + filename;
165
}
166
}
167
}
168
169
public String getName() {
170
return getString(getResourceName() + ".name");
171
};
172
173
public Icon getIcon() {
174
return createImageIcon(iconPath, getResourceName() + ".name");
175
};
176
177
public String getToolTip() {
178
return getString(getResourceName() + ".tooltip");
179
};
180
181
public void mainImpl() {
182
JFrame frame = new JFrame(getName());
183
frame.getContentPane().setLayout(new BorderLayout());
184
frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
185
getDemoPanel().setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
186
frame.pack();
187
frame.show();
188
}
189
190
public JPanel createHorizontalPanel(boolean threeD) {
191
JPanel p = new JPanel();
192
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
193
p.setAlignmentY(TOP_ALIGNMENT);
194
p.setAlignmentX(LEFT_ALIGNMENT);
195
if(threeD) {
196
p.setBorder(loweredBorder);
197
}
198
return p;
199
}
200
201
public JPanel createVerticalPanel(boolean threeD) {
202
JPanel p = new JPanel();
203
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
204
p.setAlignmentY(TOP_ALIGNMENT);
205
p.setAlignmentX(LEFT_ALIGNMENT);
206
if(threeD) {
207
p.setBorder(loweredBorder);
208
}
209
return p;
210
}
211
212
public static void main(String[] args) {
213
DemoModule demo = new DemoModule(null);
214
demo.mainImpl();
215
}
216
217
public void init() {
218
getContentPane().setLayout(new BorderLayout());
219
getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
220
}
221
222
void updateDragEnabled(boolean dragEnabled) {}
223
}
224