source: trunk/src/org/expeditee/items/widgets/SampleWidget1.java@ 1178

Last change on this file since 1178 was 1178, checked in by bln4, 6 years ago

org.expeditee.items.widgets.SampleWidget1 ->
org.expeditee.items.widgets.SampleWidget2 ->

Code tidying and additional functionality for the purposes of testing.

org.expeditee.items.widgets.SampleWidget3 ->

A new sample widget that was used to assist with debugging widget reimplementation.

File size: 3.8 KB
Line 
1/**
2 * SampleWidget1.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
21import java.awt.Component;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.awt.event.FocusEvent;
25import java.awt.event.FocusListener;
26import java.awt.event.ItemEvent;
27import java.awt.event.ItemListener;
28
29import javax.swing.InputVerifier;
30import javax.swing.JComboBox;
31import javax.swing.JComponent;
32
33import org.expeditee.items.Text;
34
35public class SampleWidget1 extends DataFrameWidget {
36
37 private static final String[] STRINGS = new String[] { "dog", "fish", "cat", "pig" };
38 //private static final String[] STRINGS = new String[] { "1", "2", "3", "4", "1", "2", "3", "4", "1", "2", "3", "4", "1", "2", "3", "4" };
39 private JComboBox<String> cmboOptions;
40
41 public SampleWidget1(Text source, String[] args) {
42 super(source, new JComboBox<String>(STRINGS), 200, 200, 50, 50);
43 cmboOptions = (JComboBox<String>) _swingComponent;
44 final DisplaySelection listener = new DisplaySelection();
45 cmboOptions.addActionListener(listener);
46 cmboOptions.addItemListener(listener);
47 cmboOptions.addFocusListener(listener);
48 cmboOptions.setInputVerifier(listener);
49 for (Component c : cmboOptions.getComponents()) {
50 c.setFocusable(true);
51 }
52 }
53
54 private void printParents(final java.awt.Component component) {
55 if(component.getParent() != null) {
56 printParents(component.getParent());
57 System.err.println("Component: " + component);
58 } else {
59 System.err.println("Component: " + component);
60 }
61 }
62
63 private final class DisplaySelection extends InputVerifier implements ActionListener, ItemListener, FocusListener {
64 @Override
65 public void actionPerformed(final ActionEvent e) {
66 System.err.println("Selected Item: " + cmboOptions.getSelectedItem());
67 }
68
69 @Override
70 public void itemStateChanged(final ItemEvent e) {
71 if(e.getStateChange() == ItemEvent.SELECTED) {
72 System.err.println("Combobox Selected");
73 System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
74 } else if (e.getStateChange() == ItemEvent.DESELECTED) {
75 System.err.println("Combobox Lost Selection");
76 System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
77 } else {
78 System.err.println("Unexpected Combobox e.getStateChange(): " + e.getStateChange());
79 }
80 }
81
82 @Override
83 public void focusGained(FocusEvent e) {
84 System.err.println("Combobox focus gained");
85 }
86
87 @Override
88 public void focusLost(FocusEvent e) {
89 System.err.println("Combobox focus lost");
90 }
91
92 @Override
93 public boolean verify(JComponent input) {
94 return true;
95 //return !cmboOptions.isPopupVisible();
96 }
97 }
98
99 @Override
100 protected String[] getArgs() {
101 String[] stateArgs = new String[1];
102 stateArgs[0] = Integer.toString(cmboOptions.getSelectedIndex());
103 return stateArgs;
104 }
105
106 /** TODO: REVISE
107 @Override
108 public void refresh() {
109 super.refresh();
110 Frame frame = getDataFrame();
111 if(frame != null) {
112 _combo.removeAllItems();
113 for(Text text: frame.getBodyTextItems(false)) {
114 _combo.addItem(text.getText());
115 }
116 _combo.setSelectedIndex(0);
117 }
118 }
119 */
120
121}
Note: See TracBrowser for help on using the repository browser.