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

Last change on this file since 1191 was 1191, checked in by bln4, 6 years ago
File size: 4.0 KB
RevLine 
[919]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
[198]19package org.expeditee.items.widgets;
[11]20
[1178]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;
[11]30import javax.swing.JComboBox;
[1178]31import javax.swing.JComponent;
[11]32
[198]33import org.expeditee.items.Text;
34
[214]35public class SampleWidget1 extends DataFrameWidget {
[203]36
[1178]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;
[203]40
[11]41 public SampleWidget1(Text source, String[] args) {
[1178]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 }
[11]52 }
[1178]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 }
[11]62
[1178]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) {
[1191]72 //System.err.println("Combobox Selected");
73 //System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
[1178]74 } else if (e.getStateChange() == ItemEvent.DESELECTED) {
[1191]75 //System.err.println("Combobox Lost Selection");
76 //System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
[1178]77 } else {
[1191]78 //System.err.println("Unexpected Combobox e.getStateChange(): " + e.getStateChange());
[1178]79 }
80 }
81
82 @Override
83 public void focusGained(FocusEvent e) {
[1191]84 //System.err.println("Combobox focus gained");
85 //System.err.println("Combobox popup visible: " + cmboOptions.isPopupVisible());
86 //System.err.println("Combobox popup object: " + cmboOptions.getComponentPopupMenu());
[1178]87 }
88
89 @Override
90 public void focusLost(FocusEvent e) {
[1191]91 //System.err.println("Combobox focus lost");
[1178]92 }
93
94 @Override
95 public boolean verify(JComponent input) {
96 return true;
97 //return !cmboOptions.isPopupVisible();
98 }
99 }
100
[11]101 @Override
[139]102 protected String[] getArgs() {
[203]103 String[] stateArgs = new String[1];
[1178]104 stateArgs[0] = Integer.toString(cmboOptions.getSelectedIndex());
[11]105 return stateArgs;
106 }
[1178]107
[206]108 /** TODO: REVISE
[203]109 @Override
110 public void refresh() {
111 super.refresh();
112 Frame frame = getDataFrame();
113 if(frame != null) {
114 _combo.removeAllItems();
115 for(Text text: frame.getBodyTextItems(false)) {
116 _combo.addItem(text.getText());
117 }
118 _combo.setSelectedIndex(0);
119 }
120 }
[206]121 */
[11]122
123}
Note: See TracBrowser for help on using the repository browser.