KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java2d > GlobalControls


1 /*
2  * @(#)GlobalControls.java 1.31 05/11/17
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  * @(#)GlobalControls.java 1.31 05/11/17
39  */

40
41
42 package java2d;
43
44 import java.awt.*;
45 import javax.swing.*;
46 import java.awt.event.ItemListener JavaDoc;
47 import java.awt.event.ItemEvent JavaDoc;
48 import javax.swing.event.ChangeListener JavaDoc;
49 import javax.swing.event.ChangeEvent JavaDoc;
50 import javax.swing.border.TitledBorder JavaDoc;
51 import javax.swing.border.EtchedBorder JavaDoc;
52
53
54 /**
55  * Global Controls panel for changing graphic attributes of
56  * the demo surface.
57  */

58 public class GlobalControls extends JPanel implements ItemListener JavaDoc, ChangeListener JavaDoc {
59
60     static String JavaDoc[] screenNames = {
61             "Auto Screen", "On Screen", "Off Screen",
62             "INT_xRGB", "INT_ARGB", "INT_ARGB_PRE", "INT_BGR",
63             "3BYTE_BGR", "4BYTE_ABGR", "4BYTE_ABGR_PRE", "USHORT_565_RGB",
64             "USHORT_x555_RGB", "BYTE_GRAY", "USHORT_GRAY",
65         "BYTE_BINARY", "BYTE_INDEXED", "BYTE_BINARY 2 bit", "BYTE_BINARY 4 bit",
66         "INT_RGBx", "USHORT_555x_RGB"};
67     static JComboBox screenCombo;
68     public TextureChooser texturechooser;
69     public JCheckBox aliasCB, renderCB, toolBarCB;
70     public JCheckBox compositeCB, textureCB;
71     public JSlider slider;
72     public Object JavaDoc obj;
73
74     private Font font = new Font("serif", Font.PLAIN, 12);
75
76
77     public GlobalControls() {
78         setLayout(new GridBagLayout());
79         setBorder(new TitledBorder JavaDoc(new EtchedBorder JavaDoc(), "Global Controls"));
80
81         aliasCB = createCheckBox("Anti-Aliasing", true, 0);
82         renderCB = createCheckBox("Rendering Quality", false, 1);
83         textureCB = createCheckBox("Texture", false, 2);
84         compositeCB = createCheckBox("AlphaComposite", false, 3);
85
86         screenCombo = new JComboBox();
87         screenCombo.setPreferredSize(new Dimension(120, 18));
88         screenCombo.setLightWeightPopupEnabled(true);
89         screenCombo.setFont(font);
90         for (int i = 0; i < screenNames.length; i++) {
91             screenCombo.addItem(screenNames[i]);
92         }
93         screenCombo.addItemListener(this);
94         Java2Demo.addToGridBag(this, screenCombo, 0, 4, 1, 1, 0.0, 0.0);
95
96         toolBarCB = createCheckBox("Tools", false, 5);
97
98         slider = new JSlider(JSlider.HORIZONTAL, 0, 200, 30);
99         slider.addChangeListener(this);
100         TitledBorder JavaDoc tb = new TitledBorder JavaDoc(new EtchedBorder JavaDoc());
101         tb.setTitleFont(font);
102         tb.setTitle("Anim delay = 30 ms");
103         slider.setBorder(tb);
104         slider.setMinimumSize(new Dimension(80,46));
105         Java2Demo.addToGridBag(this, slider, 0, 6, 1, 1, 1.0, 1.0);
106
107         texturechooser = new TextureChooser(0);
108         Java2Demo.addToGridBag(this, texturechooser, 0, 7, 1, 1, 1.0, 1.0);
109     }
110
111
112     private JCheckBox createCheckBox(String JavaDoc s, boolean b, int y) {
113         JCheckBox cb = new JCheckBox(s, b);
114         cb.setFont(font);
115         cb.setHorizontalAlignment(JCheckBox.LEFT);
116         cb.addItemListener(this);
117         Java2Demo.addToGridBag(this, cb, 0, y, 1, 1, 1.0, 1.0);
118         return cb;
119     }
120
121
122     public void stateChanged(ChangeEvent JavaDoc e) {
123         int value = slider.getValue();
124         TitledBorder JavaDoc tb = (TitledBorder JavaDoc) slider.getBorder();
125         tb.setTitle("Anim delay = " + String.valueOf(value) + " ms");
126         int index = Java2Demo.tabbedPane.getSelectedIndex()-1;
127         DemoGroup dg = Java2Demo.group[index];
128         JPanel p = dg.getPanel();
129         for (int i = 0; i < p.getComponentCount(); i++) {
130             DemoPanel dp = (DemoPanel) p.getComponent(i);
131             if (dp.tools != null && dp.tools.slider != null) {
132                 dp.tools.slider.setValue(value);
133             }
134         }
135         slider.repaint();
136     }
137
138
139     public void itemStateChanged(ItemEvent JavaDoc e) {
140         if (Java2Demo.tabbedPane.getSelectedIndex() != 0) {
141             obj = e.getSource();
142             int index = Java2Demo.tabbedPane.getSelectedIndex()-1;
143             Java2Demo.group[index].setup(true);
144             obj = null;
145         }
146     }
147
148
149     public Dimension getPreferredSize() {
150         return new Dimension(135,260);
151     }
152 }
153
Popular Tags