01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.properties.editors;
20:
21: import java.awt.BorderLayout;
22: import java.awt.Component;
23: import java.awt.event.ActionEvent;
24: import java.awt.event.ActionListener;
25: import java.util.Collection;
26: import java.util.Iterator;
27:
28: import javax.swing.JComboBox;
29: import javax.swing.JPanel;
30:
31: import com.jeta.forms.store.properties.TransformOptionsProperty;
32: import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
33:
34: public class ComboEditor extends JETAPropertyEditor {
35: private JPanel m_panel;
36: private JComboBox m_cbox = new JComboBox();
37:
38: public ComboEditor() {
39: m_panel = new JPanel(new BorderLayout());
40: m_panel.add(m_cbox, BorderLayout.CENTER);
41: m_cbox.addActionListener(new ActionListener() {
42: public void actionPerformed(ActionEvent evt) {
43: setValue(m_cbox.getSelectedItem());
44: }
45: });
46: }
47:
48: public Component getCustomEditor() {
49: return m_panel;
50: }
51:
52: /**
53: * @return true if this editor supports custom editing inline in the
54: * property table. Property types such as the Java primitives and
55: * Strings support inline editing.
56: */
57: public boolean supportsInlineEditing() {
58: return true;
59: }
60:
61: public Object getValue() {
62: return m_cbox.getSelectedItem();
63: }
64:
65: /**
66: *
67: */
68: public void setValue(Object value) {
69: super .setValue(value);
70: if (value instanceof TransformOptionsProperty) {
71: TransformOptionsProperty p = (TransformOptionsProperty) value;
72: m_cbox.removeAllItems();
73: Collection c = p.getOptions();
74: if (c != null) {
75: Iterator iter = c.iterator();
76: while (iter.hasNext()) {
77: m_cbox.addItem(iter.next());
78: }
79: }
80: m_cbox.setSelectedItem(p.getCurrentItem());
81: } else {
82: // assert( false );
83: }
84: }
85:
86: }
|