source: trunk/src/org/expeditee/items/widgets/SampleWidget2.java@ 919

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.3 KB
Line 
1/**
2 * SampleWidget2.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items.widgets;
20
21
22import java.awt.Color;
23import java.awt.FlowLayout;
24import java.awt.Font;
25
26import javax.swing.JCheckBox;
27import javax.swing.JComboBox;
28import javax.swing.JLabel;
29import javax.swing.JPanel;
30import javax.swing.JSplitPane;
31import javax.swing.JTextArea;
32import javax.swing.JToggleButton;
33
34import org.expeditee.items.Text;
35
36public class SampleWidget2 extends InteractiveWidget {
37
38 private JComboBox _combo;
39 private JTextArea _text;
40
41 public SampleWidget2(Text source, String[] args) {
42 super(source, new JSplitPane(JSplitPane.VERTICAL_SPLIT), 60, -1, 40, -1);
43
44 Font bigFont = null;
45
46 JSplitPane sp = (JSplitPane)super._swingComponent;
47
48 JPanel p = new JPanel(new FlowLayout());
49 p.setBackground(new Color(255,228,195));
50
51 JLabel lbl = new JLabel("This is an example InteractiveWidget!");
52 bigFont = lbl.getFont().deriveFont(24F);
53 lbl.setFont(bigFont);
54
55 JToggleButton button = new JToggleButton("Toggle Style");
56 button.setFont(bigFont);
57
58 JCheckBox checkBox = new JCheckBox("Big Font");
59 checkBox.setBackground(null);
60 checkBox.setSelected(true);
61 checkBox.setFont(bigFont);
62
63
64 //JButton button2 = new JButton("Example CheckBox");
65
66 _text = new JTextArea();
67 _text.setFont(bigFont);
68
69 _combo = new JComboBox(new String[] {"Peach", "Item 2", "Item 3", "Item 21", "Item 22", "Item 23", "Item 31", "Item 32", "Item 33", "Item 41", "Item 42", "Item 43"});
70 _combo.setFont(bigFont);
71
72 p.add(lbl);
73 p.add(_combo);
74 p.add(button);
75 p.add(checkBox);
76
77 sp.setTopComponent(p);
78 sp.setBottomComponent(_text);
79
80 // Set state
81 if (args != null && args.length >= 1) {
82
83 int selectedItem = 0;
84
85 // extract selected index
86 if (args.length >= 1 && args[0] != null) {
87 try {
88 selectedItem = Integer.parseInt(args[0]);
89 } catch (NumberFormatException e) {
90 e.printStackTrace();
91 }
92 }
93
94 if (selectedItem < 0) selectedItem = 0;
95 else if (selectedItem >= _combo.getItemCount())
96 selectedItem = _combo.getItemCount() - 1;
97
98 _combo.setSelectedIndex(selectedItem);
99
100 if (args.length >= 2 && args[1] != null) {
101 _text.setText(args[1]);
102 }
103
104 if (args.length >= 3 && args[2] != null) {
105 try {
106 int div = Integer.parseInt(args[2]);
107 ((JSplitPane)super._swingComponent).setDividerLocation(div);
108 } catch (NumberFormatException e) {}
109
110 }
111 }
112 }
113
114 @Override
115 protected String[] getArgs() {
116
117 return new String[] {
118 Integer.toString(_combo.getSelectedIndex()),
119 _text.getText(),
120 Integer.toString(((JSplitPane)super._swingComponent).getDividerLocation())
121 };
122 }
123}
Note: See TracBrowser for help on using the repository browser.