[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] | 19 | package org.expeditee.items.widgets;
|
---|
[11] | 20 |
|
---|
[1178] | 21 | import java.awt.Component;
|
---|
| 22 | import java.awt.event.ActionEvent;
|
---|
| 23 | import java.awt.event.ActionListener;
|
---|
| 24 | import java.awt.event.FocusEvent;
|
---|
| 25 | import java.awt.event.FocusListener;
|
---|
| 26 | import java.awt.event.ItemEvent;
|
---|
| 27 | import java.awt.event.ItemListener;
|
---|
| 28 |
|
---|
| 29 | import javax.swing.InputVerifier;
|
---|
[11] | 30 | import javax.swing.JComboBox;
|
---|
[1178] | 31 | import javax.swing.JComponent;
|
---|
[11] | 32 |
|
---|
[198] | 33 | import org.expeditee.items.Text;
|
---|
| 34 |
|
---|
[214] | 35 | public 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 | }
|
---|
[1511] | 52 | System.err.println("SampleWidget1::setting light weight popup enabled to false.");
|
---|
| 53 | cmboOptions.setLightWeightPopupEnabled(false);
|
---|
[11] | 54 | }
|
---|
[1178] | 55 |
|
---|
| 56 | private void printParents(final java.awt.Component component) {
|
---|
| 57 | if(component.getParent() != null) {
|
---|
| 58 | printParents(component.getParent());
|
---|
| 59 | System.err.println("Component: " + component);
|
---|
| 60 | } else {
|
---|
| 61 | System.err.println("Component: " + component);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
[11] | 64 |
|
---|
[1178] | 65 | private final class DisplaySelection extends InputVerifier implements ActionListener, ItemListener, FocusListener {
|
---|
| 66 | @Override
|
---|
| 67 | public void actionPerformed(final ActionEvent e) {
|
---|
| 68 | System.err.println("Selected Item: " + cmboOptions.getSelectedItem());
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | @Override
|
---|
| 72 | public void itemStateChanged(final ItemEvent e) {
|
---|
| 73 | if(e.getStateChange() == ItemEvent.SELECTED) {
|
---|
[1191] | 74 | //System.err.println("Combobox Selected");
|
---|
| 75 | //System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
|
---|
[1178] | 76 | } else if (e.getStateChange() == ItemEvent.DESELECTED) {
|
---|
[1191] | 77 | //System.err.println("Combobox Lost Selection");
|
---|
| 78 | //System.err.println("SampleWidget1::main component children count: " + cmboOptions.getComponents().length);
|
---|
[1178] | 79 | } else {
|
---|
[1191] | 80 | //System.err.println("Unexpected Combobox e.getStateChange(): " + e.getStateChange());
|
---|
[1178] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | @Override
|
---|
| 85 | public void focusGained(FocusEvent e) {
|
---|
[1191] | 86 | //System.err.println("Combobox focus gained");
|
---|
| 87 | //System.err.println("Combobox popup visible: " + cmboOptions.isPopupVisible());
|
---|
| 88 | //System.err.println("Combobox popup object: " + cmboOptions.getComponentPopupMenu());
|
---|
[1178] | 89 | }
|
---|
| 90 |
|
---|
| 91 | @Override
|
---|
| 92 | public void focusLost(FocusEvent e) {
|
---|
[1191] | 93 | //System.err.println("Combobox focus lost");
|
---|
[1178] | 94 | }
|
---|
| 95 |
|
---|
| 96 | @Override
|
---|
| 97 | public boolean verify(JComponent input) {
|
---|
| 98 | return true;
|
---|
| 99 | //return !cmboOptions.isPopupVisible();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[11] | 103 | @Override
|
---|
[139] | 104 | protected String[] getArgs() {
|
---|
[203] | 105 | String[] stateArgs = new String[1];
|
---|
[1178] | 106 | stateArgs[0] = Integer.toString(cmboOptions.getSelectedIndex());
|
---|
[11] | 107 | return stateArgs;
|
---|
| 108 | }
|
---|
[1178] | 109 |
|
---|
[206] | 110 | /** TODO: REVISE
|
---|
[203] | 111 | @Override
|
---|
| 112 | public void refresh() {
|
---|
| 113 | super.refresh();
|
---|
| 114 | Frame frame = getDataFrame();
|
---|
| 115 | if(frame != null) {
|
---|
| 116 | _combo.removeAllItems();
|
---|
| 117 | for(Text text: frame.getBodyTextItems(false)) {
|
---|
| 118 | _combo.addItem(text.getText());
|
---|
| 119 | }
|
---|
| 120 | _combo.setSelectedIndex(0);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[206] | 123 | */
|
---|
[11] | 124 |
|
---|
| 125 | }
|
---|