1 |
781 |
jeremybenn |
/* MiniDemo.java -- A Swing demo suitable for embedded environments
|
2 |
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package gnu.classpath.examples.swing;
|
40 |
|
|
|
41 |
|
|
import java.awt.BorderLayout;
|
42 |
|
|
import java.awt.Font;
|
43 |
|
|
import java.awt.GridLayout;
|
44 |
|
|
import java.awt.event.ActionEvent;
|
45 |
|
|
import java.awt.event.ActionListener;
|
46 |
|
|
|
47 |
|
|
import javax.swing.Box;
|
48 |
|
|
import javax.swing.BoxLayout;
|
49 |
|
|
import javax.swing.JButton;
|
50 |
|
|
import javax.swing.JCheckBox;
|
51 |
|
|
import javax.swing.JComboBox;
|
52 |
|
|
import javax.swing.JFrame;
|
53 |
|
|
import javax.swing.JList;
|
54 |
|
|
import javax.swing.JPanel;
|
55 |
|
|
import javax.swing.JScrollPane;
|
56 |
|
|
import javax.swing.JTabbedPane;
|
57 |
|
|
import javax.swing.JTextField;
|
58 |
|
|
import javax.swing.SwingUtilities;
|
59 |
|
|
import javax.swing.plaf.metal.DefaultMetalTheme;
|
60 |
|
|
import javax.swing.plaf.metal.MetalIconFactory;
|
61 |
|
|
import javax.swing.plaf.metal.MetalLookAndFeel;
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* A Swing demo suitable for embedded environments (e.g. small display,
|
65 |
|
|
* b/w graphics etc).
|
66 |
|
|
*
|
67 |
|
|
* @author Roman Kennke (kennke@aicas.com)
|
68 |
|
|
*/
|
69 |
|
|
public class MiniDemo extends JFrame
|
70 |
|
|
{
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Creates a new MiniDemo instance.
|
74 |
|
|
*/
|
75 |
|
|
MiniDemo()
|
76 |
|
|
{
|
77 |
|
|
createGUI();
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
private void createGUI()
|
81 |
|
|
{
|
82 |
|
|
JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP,
|
83 |
|
|
JTabbedPane.SCROLL_TAB_LAYOUT);
|
84 |
|
|
|
85 |
|
|
// Setup scrolling list in first tab.
|
86 |
|
|
Object[] listData = new Object[]{"Milk", "Beer", "Wine", "Water",
|
87 |
|
|
"Orange juice", "Tea", "Coffee", "Whiskey",
|
88 |
|
|
"Lemonade", "Apple juice", "Gin Tonic",
|
89 |
|
|
"Pangalactic Garleblaster", "Coke"};
|
90 |
|
|
JList list = new JList(listData);
|
91 |
|
|
JScrollPane sp = new JScrollPane(list);
|
92 |
|
|
tabPane.addTab("List", sp);
|
93 |
|
|
|
94 |
|
|
// Setup some buttons in the second tab.
|
95 |
|
|
JPanel buttonPanel = new JPanel();
|
96 |
|
|
buttonPanel.setLayout(new GridLayout(4, 1));
|
97 |
|
|
// JButtons
|
98 |
|
|
JPanel jButtonPanel = new JPanel();
|
99 |
|
|
jButtonPanel.setLayout(new BorderLayout());
|
100 |
|
|
final JCheckBox buttonState1 = new JCheckBox("Enabled", true);
|
101 |
|
|
jButtonPanel.add(buttonState1, BorderLayout.EAST);
|
102 |
|
|
JPanel jButtonContainer = new JPanel();
|
103 |
|
|
final JButton jButton1 = new JButton("JButton");
|
104 |
|
|
final JButton jButton2 =
|
105 |
|
|
new JButton(MetalIconFactory.getInternalFrameDefaultMenuIcon());
|
106 |
|
|
jButtonContainer.add(jButton1);
|
107 |
|
|
jButtonContainer.add(jButton2);
|
108 |
|
|
jButtonPanel.add(jButtonContainer, BorderLayout.CENTER);
|
109 |
|
|
buttonState1.addActionListener(
|
110 |
|
|
new ActionListener()
|
111 |
|
|
{
|
112 |
|
|
public void actionPerformed(ActionEvent ev)
|
113 |
|
|
{
|
114 |
|
|
boolean enabled = buttonState1.isSelected();
|
115 |
|
|
jButton1.setEnabled(enabled);
|
116 |
|
|
jButton2.setEnabled(enabled);
|
117 |
|
|
}
|
118 |
|
|
});
|
119 |
|
|
buttonPanel.add(jButtonPanel);
|
120 |
|
|
// JToggleButtons
|
121 |
|
|
JPanel jToggleButtonPanel = new JPanel();
|
122 |
|
|
jToggleButtonPanel.setLayout(new BorderLayout());
|
123 |
|
|
final JCheckBox buttonState2 = new JCheckBox("Enabled", true);
|
124 |
|
|
jToggleButtonPanel.add(buttonState2, BorderLayout.EAST);
|
125 |
|
|
JPanel jToggleButtonContainer = new JPanel();
|
126 |
|
|
final JButton jToggleButton1 = new JButton("JToggleButton");
|
127 |
|
|
final JButton jToggleButton2 =
|
128 |
|
|
new JButton(MetalIconFactory.getInternalFrameDefaultMenuIcon());
|
129 |
|
|
jToggleButtonContainer.add(jToggleButton1);
|
130 |
|
|
jToggleButtonContainer.add(jToggleButton2);
|
131 |
|
|
jToggleButtonPanel.add(jToggleButtonContainer, BorderLayout.CENTER);
|
132 |
|
|
buttonState2.addActionListener(
|
133 |
|
|
new ActionListener()
|
134 |
|
|
{
|
135 |
|
|
public void actionPerformed(ActionEvent ev)
|
136 |
|
|
{
|
137 |
|
|
boolean enabled = buttonState2.isSelected();
|
138 |
|
|
jToggleButton1.setEnabled(enabled);
|
139 |
|
|
jToggleButton2.setEnabled(enabled);
|
140 |
|
|
}
|
141 |
|
|
});
|
142 |
|
|
buttonPanel.add(jToggleButtonPanel);
|
143 |
|
|
tabPane.addTab("Buttons", buttonPanel);
|
144 |
|
|
|
145 |
|
|
// ComboBoxes
|
146 |
|
|
JPanel comboBoxPanel = new JPanel();
|
147 |
|
|
JComboBox comboBox = new JComboBox(listData);
|
148 |
|
|
comboBoxPanel.add(comboBox);
|
149 |
|
|
tabPane.add("ComboBox", comboBoxPanel);
|
150 |
|
|
|
151 |
|
|
// TextFields
|
152 |
|
|
JPanel textFieldPanel = new JPanel();
|
153 |
|
|
textFieldPanel.setLayout(new BoxLayout(textFieldPanel, BoxLayout.Y_AXIS));
|
154 |
|
|
textFieldPanel.add(Box.createVerticalStrut(70));
|
155 |
|
|
JPanel leftAlignedPanel = new JPanel(new BorderLayout());
|
156 |
|
|
JPanel textFieldPanel1 = new JPanel();
|
157 |
|
|
textFieldPanel1.setLayout(new BoxLayout(textFieldPanel1,
|
158 |
|
|
BoxLayout.X_AXIS));
|
159 |
|
|
final JTextField textfield1 = new JTextField("Hello World!");
|
160 |
|
|
textfield1.setHorizontalAlignment(JTextField.LEFT);
|
161 |
|
|
textfield1.setFont(new Font("Dialog", Font.PLAIN, 8));
|
162 |
|
|
textFieldPanel1.add(textfield1);
|
163 |
|
|
final JTextField textfield2 = new JTextField("Hello World!");
|
164 |
|
|
textfield2.setHorizontalAlignment(JTextField.LEFT);
|
165 |
|
|
textfield2.setFont(new Font("Dialog", Font.ITALIC, 12));
|
166 |
|
|
textFieldPanel1.add(textfield2);
|
167 |
|
|
final JTextField textfield3 = new JTextField("Hello World!");
|
168 |
|
|
textfield3.setHorizontalAlignment(JTextField.LEFT);
|
169 |
|
|
textfield3.setFont(new Font("Dialog", Font.BOLD, 14));
|
170 |
|
|
textFieldPanel1.add(textfield3);
|
171 |
|
|
leftAlignedPanel.add(textFieldPanel1);
|
172 |
|
|
JPanel statePanel = new JPanel();
|
173 |
|
|
statePanel.setLayout(new BoxLayout(statePanel, BoxLayout.Y_AXIS));
|
174 |
|
|
statePanel.add(Box.createVerticalGlue());
|
175 |
|
|
final JCheckBox enabled1 = new JCheckBox("enabled");
|
176 |
|
|
enabled1.setSelected(true);
|
177 |
|
|
enabled1.addActionListener(
|
178 |
|
|
new ActionListener()
|
179 |
|
|
{
|
180 |
|
|
public void actionPerformed(ActionEvent ev)
|
181 |
|
|
{
|
182 |
|
|
boolean enabled = enabled1.isSelected();
|
183 |
|
|
textfield1.setEnabled(enabled);
|
184 |
|
|
textfield2.setEnabled(enabled);
|
185 |
|
|
textfield3.setEnabled(enabled);
|
186 |
|
|
}
|
187 |
|
|
});
|
188 |
|
|
statePanel.add(enabled1);
|
189 |
|
|
final JCheckBox editable1 = new JCheckBox("editable");
|
190 |
|
|
editable1.setSelected(true);
|
191 |
|
|
editable1.addActionListener(
|
192 |
|
|
new ActionListener()
|
193 |
|
|
{
|
194 |
|
|
public void actionPerformed(ActionEvent ev)
|
195 |
|
|
{
|
196 |
|
|
boolean editable = editable1.isSelected();
|
197 |
|
|
textfield1.setEditable(editable);
|
198 |
|
|
textfield2.setEditable(editable);
|
199 |
|
|
textfield3.setEditable(editable);
|
200 |
|
|
}
|
201 |
|
|
});
|
202 |
|
|
statePanel.add(editable1);
|
203 |
|
|
statePanel.add(Box.createVerticalGlue());
|
204 |
|
|
leftAlignedPanel.add(statePanel, BorderLayout.EAST);
|
205 |
|
|
textFieldPanel.add(leftAlignedPanel);
|
206 |
|
|
System.err.println(leftAlignedPanel.getPreferredSize());
|
207 |
|
|
textFieldPanel.add(Box.createVerticalStrut(70));
|
208 |
|
|
//panel.add(rightAlignedPanel);
|
209 |
|
|
tabPane.add("TextField", textFieldPanel);
|
210 |
|
|
setContentPane(tabPane);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
/**
|
214 |
|
|
* Starts the demo application.
|
215 |
|
|
*
|
216 |
|
|
* @param args the command line arguments (ignored)
|
217 |
|
|
*/
|
218 |
|
|
public static void main(String[] args)
|
219 |
|
|
{
|
220 |
|
|
SwingUtilities.invokeLater(new Runnable() {
|
221 |
|
|
public void run()
|
222 |
|
|
{
|
223 |
|
|
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
|
224 |
|
|
MiniDemo demo = new MiniDemo();
|
225 |
|
|
demo.setSize(320, 200);
|
226 |
|
|
demo.setUndecorated(true);
|
227 |
|
|
demo.setVisible(true);
|
228 |
|
|
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
229 |
|
|
}
|
230 |
|
|
});
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
}
|