Skip to content

Commit a61a15e

Browse files
committed
Update examples.
1 parent 0066c71 commit a61a15e

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package org.httprpc.sierra.test;
16+
17+
import com.formdev.flatlaf.FlatLightLaf;
18+
import org.httprpc.sierra.UILoader;
19+
20+
import javax.swing.JFrame;
21+
import javax.swing.SwingUtilities;
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
26+
import static org.httprpc.kilo.util.Collections.*;
27+
28+
public class PreviewTest extends JFrame implements Runnable {
29+
private PreviewTest() {
30+
super("Preview Test");
31+
32+
setDefaultCloseOperation(EXIT_ON_CLOSE);
33+
}
34+
35+
@Override
36+
public void run() {
37+
var workingPath = Path.of(System.getProperty("java.io.tmpdir"));
38+
39+
var names = listOf("GreetingTest.xml", "world.png");
40+
var paths = names.stream().map(workingPath::resolve).toList();
41+
42+
try {
43+
try {
44+
var n = names.size();
45+
46+
for (var i = 0; i < n; i++) {
47+
try (var inputStream = getClass().getResourceAsStream(names.get(i))) {
48+
Files.copy(inputStream, paths.get(i));
49+
}
50+
}
51+
52+
setContentPane(UILoader.load(paths.getFirst()));
53+
} finally {
54+
for (var path : paths) {
55+
Files.deleteIfExists(path);
56+
}
57+
}
58+
} catch (IOException exception) {
59+
throw new RuntimeException(exception);
60+
}
61+
62+
setSize(320, 480);
63+
setVisible(true);
64+
}
65+
66+
public static void main(String[] args) {
67+
FlatLightLaf.setup();
68+
69+
SwingUtilities.invokeLater(new PreviewTest());
70+
}
71+
}

0 commit comments

Comments
 (0)