1 | package org.expeditee.items;
|
---|
2 |
|
---|
3 |
|
---|
4 | import java.awt.FlowLayout;
|
---|
5 |
|
---|
6 | import javax.swing.JButton;
|
---|
7 | import javax.swing.JComboBox;
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.JPanel;
|
---|
10 | import javax.swing.JSplitPane;
|
---|
11 | import javax.swing.JTextArea;
|
---|
12 |
|
---|
13 | public class SampleWidget2 extends InteractiveWidget {
|
---|
14 |
|
---|
15 | private JComboBox _combo;
|
---|
16 | private JTextArea _text;
|
---|
17 |
|
---|
18 | public SampleWidget2(Text source, String[] args) {
|
---|
19 | super(source, new JSplitPane(JSplitPane.VERTICAL_SPLIT), 60, -1, 40, -1);
|
---|
20 |
|
---|
21 | JSplitPane sp = (JSplitPane)super._swingComponent;
|
---|
22 |
|
---|
23 | JPanel p = new JPanel(new FlowLayout());
|
---|
24 |
|
---|
25 | JLabel lbl = new JLabel("This widget has multiple JComponents!");
|
---|
26 |
|
---|
27 | JButton button = new JButton("Click Me!");
|
---|
28 |
|
---|
29 | JButton button2 = new JButton("Or Me!");
|
---|
30 |
|
---|
31 | _text = new JTextArea();
|
---|
32 |
|
---|
33 | _combo = new JComboBox(new String[] {"Item 1", "Item 2", "Item 3", "Item 21", "Item 22", "Item 23", "Item 31", "Item 32", "Item 33", "Item 41", "Item 42", "Item 43"});
|
---|
34 |
|
---|
35 | p.add(lbl);
|
---|
36 | p.add(_combo);
|
---|
37 | p.add(button);
|
---|
38 | p.add(button2);
|
---|
39 |
|
---|
40 | sp.setTopComponent(p);
|
---|
41 | sp.setBottomComponent(_text);
|
---|
42 |
|
---|
43 | // Set state
|
---|
44 | if (args != null && args.length >= 1) {
|
---|
45 |
|
---|
46 | int selectedItem = 0;
|
---|
47 |
|
---|
48 | // extract selected index
|
---|
49 | if (args.length >= 1 && args[0] != null) {
|
---|
50 | try {
|
---|
51 | selectedItem = Integer.parseInt(args[0]);
|
---|
52 | } catch (NumberFormatException e) {
|
---|
53 | e.printStackTrace();
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | if (selectedItem < 0) selectedItem = 0;
|
---|
58 | else if (selectedItem >= _combo.getItemCount())
|
---|
59 | selectedItem = _combo.getItemCount() - 1;
|
---|
60 |
|
---|
61 | _combo.setSelectedIndex(selectedItem);
|
---|
62 |
|
---|
63 | if (args.length >= 2 && args[1] != null) {
|
---|
64 | _text.setText(args[1]);
|
---|
65 | }
|
---|
66 |
|
---|
67 | if (args.length >= 3 && args[2] != null) {
|
---|
68 | try {
|
---|
69 | int div = Integer.parseInt(args[2]);
|
---|
70 | ((JSplitPane)super._swingComponent).setDividerLocation(div);
|
---|
71 | } catch (NumberFormatException e) {}
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | protected String[] getArgs(boolean isCopy) {
|
---|
81 | return new String[] {
|
---|
82 | Integer.toString(_combo.getSelectedIndex()),
|
---|
83 | _text.getText(),
|
---|
84 | Integer.toString(((JSplitPane)super._swingComponent).getDividerLocation())
|
---|
85 | };
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | protected String getTopMostClassName() {
|
---|
90 | return getClass().getName();
|
---|
91 | }
|
---|
92 |
|
---|
93 | }
|
---|