1 /*
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * This source code is provided to illustrate the usage of a given feature
34 * or technique and has been deliberately simplified. Additional steps
35 * required for a production-quality application, such as security checks,
36 * input validation and proper error handling, might not be present in
37 * this sample code.
38 */
39
40
41 package j2dbench;
42
43 import java.io.PrintWriter;
44 import javax.swing.BoxLayout;
45 import javax.swing.JComponent;
46 import javax.swing.JPanel;
47 import javax.swing.JTabbedPane;
48 import javax.swing.border.TitledBorder;
49 import java.util.NoSuchElementException;
50
51 import j2dbench.ui.CompactLayout;
52 import j2dbench.ui.EnableButton;
53
54 public class Group extends Node {
55 public static Group root = new Group();
56
57 private Node children;
58 private boolean tabbed;
59 private boolean hidden;
60 private boolean horizontal;
61 private Boolean bordered;
62 private int tabPlacement;
63
64 private Group() {
65 setTabbed(JTabbedPane.LEFT);
66 }
182 }
183 }
184 return jtp;
185 } else {
186 JPanel p = new JPanel();
187 p.setLayout(new BoxLayout(p,
188 horizontal
189 ? BoxLayout.X_AXIS
190 : BoxLayout.Y_AXIS));
191 p.setLayout(new CompactLayout(horizontal));
192 if (getDescription() != null && isBordered()) {
193 p.setBorder(new TitledBorder(getDescription()));
194 addEnableButtons(p);
195 }
196 for (Node node = children; node != null; node = node.getNext()) {
197 JComponent comp = node.getJComponent();
198 if (comp != null) {
199 p.add(comp);
200 }
201 }
202 return p;
203 }
204 }
205
206 public void addEnableButtons(JPanel p) {
207 p.add(new EnableButton(this, EnableButton.DEFAULT));
208 p.add(new EnableButton(this, EnableButton.CLEAR));
209 p.add(new EnableButton(this, EnableButton.INVERT));
210 p.add(new EnableButton(this, EnableButton.SET));
211 }
212
213 public static void restoreAllDefaults() {
214 root.traverse(new Visitor() {
215 public void visit(Node node) {
216 node.restoreDefault();
217 }
218 });
219 }
220
221 public static void writeAll(final PrintWriter pw) {
222 root.traverse(new Visitor() {
|
1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * This source code is provided to illustrate the usage of a given feature
34 * or technique and has been deliberately simplified. Additional steps
35 * required for a production-quality application, such as security checks,
36 * input validation and proper error handling, might not be present in
37 * this sample code.
38 */
39
40
41 package j2dbench;
42
43 import java.io.PrintWriter;
44 import javax.swing.BoxLayout;
45 import javax.swing.JComponent;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTabbedPane;
49 import javax.swing.border.TitledBorder;
50 import java.util.NoSuchElementException;
51
52 import j2dbench.ui.CompactLayout;
53 import j2dbench.ui.EnableButton;
54
55 public class Group extends Node {
56 public static Group root = new Group();
57
58 private Node children;
59 private boolean tabbed;
60 private boolean hidden;
61 private boolean horizontal;
62 private Boolean bordered;
63 private int tabPlacement;
64
65 private Group() {
66 setTabbed(JTabbedPane.LEFT);
67 }
183 }
184 }
185 return jtp;
186 } else {
187 JPanel p = new JPanel();
188 p.setLayout(new BoxLayout(p,
189 horizontal
190 ? BoxLayout.X_AXIS
191 : BoxLayout.Y_AXIS));
192 p.setLayout(new CompactLayout(horizontal));
193 if (getDescription() != null && isBordered()) {
194 p.setBorder(new TitledBorder(getDescription()));
195 addEnableButtons(p);
196 }
197 for (Node node = children; node != null; node = node.getNext()) {
198 JComponent comp = node.getJComponent();
199 if (comp != null) {
200 p.add(comp);
201 }
202 }
203 return new JScrollPane(p);
204 }
205 }
206
207 public void addEnableButtons(JPanel p) {
208 p.add(new EnableButton(this, EnableButton.DEFAULT));
209 p.add(new EnableButton(this, EnableButton.CLEAR));
210 p.add(new EnableButton(this, EnableButton.INVERT));
211 p.add(new EnableButton(this, EnableButton.SET));
212 }
213
214 public static void restoreAllDefaults() {
215 root.traverse(new Visitor() {
216 public void visit(Node node) {
217 node.restoreDefault();
218 }
219 });
220 }
221
222 public static void writeAll(final PrintWriter pw) {
223 root.traverse(new Visitor() {
|