001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.comp.free;
015:
016: import org.itsnat.comp.ItsNatListCellEditor;
017: import org.itsnat.comp.free.ItsNatFreeComboBox;
018: import org.itsnat.comp.ui.ItsNatComboBoxUI;
019: import org.itsnat.comp.ui.ItsNatComponentUI;
020: import org.itsnat.core.ItsNatException;
021: import org.itsnat.impl.comp.*;
022: import org.itsnat.impl.comp.ui.free.ItsNatFreeComboBoxUIImpl;
023: import java.awt.event.ItemEvent;
024: import java.awt.event.ItemListener;
025: import javax.swing.ComboBoxModel;
026: import javax.swing.DefaultComboBoxModel;
027: import javax.swing.ListModel;
028: import javax.swing.MutableComboBoxModel;
029: import javax.swing.event.EventListenerList;
030: import javax.swing.event.ListDataEvent;
031: import org.itsnat.comp.ItsNatListStructure;
032: import org.itsnat.comp.ui.ItsNatListCellUI;
033: import org.itsnat.comp.ui.ItsNatListUI;
034: import org.itsnat.core.NameValue;
035: import org.w3c.dom.Element;
036: import org.w3c.dom.Node;
037: import org.w3c.dom.events.Event;
038:
039: /**
040: *
041: * @author jmarranz
042: */
043: public class ItsNatFreeComboBoxImpl extends ItsNatFreeListImpl
044: implements ItsNatFreeComboBox, ItsNatComboBoxInternal {
045: protected Object selectedItemReminder;
046: protected EventListenerList listenerList = new EventListenerList();
047:
048: /**
049: * Creates a new instance of ItsNatFreeComboBoxImpl
050: */
051: public ItsNatFreeComboBoxImpl(Element element,
052: ItsNatListStructure structure, NameValue[] artifacts,
053: ItsNatComponentManagerImpl componentMgr) {
054: super (element, structure, artifacts, componentMgr);
055:
056: init();
057: }
058:
059: public Object getSelectedItemReminder() {
060: return selectedItemReminder;
061: }
062:
063: public void setSelectedItemReminder(Object obj) {
064: this .selectedItemReminder = obj;
065: }
066:
067: public void processDOMEvent(Event evt) {
068: String type = evt.getType();
069: if (type.equals("click") || type.equals("mouseup")) {
070: Node nodeClicked = (Node) evt.getTarget(); // Puede ser un nodo interior del elemento pulsado
071:
072: ItsNatListUI compUI = getItsNatListUI();
073: ItsNatListCellUI option = compUI
074: .getItsNatListCellUIFromNode(nodeClicked);
075: if (option != null) // por si acaso
076: {
077: int selectedIndex = option.getIndex();
078: setSelectedIndex(selectedIndex);
079: }
080: }
081:
082: super .processDOMEvent(evt);
083: }
084:
085: public ItsNatComboBoxUI getItsNatComboBoxUI() {
086: return (ItsNatComboBoxUI) compUI;
087: }
088:
089: public ItsNatComboBoxUI createDefaultItsNatFreeComboBoxUI() {
090: return new ItsNatFreeComboBoxUIImpl(this );
091: }
092:
093: public ItsNatComponentUI createDefaultItsNatComponentUI() {
094: return createDefaultItsNatFreeComboBoxUI();
095: }
096:
097: public void syncUIWithDataModel() {
098: super .syncUIWithDataModel();
099:
100: ItsNatComboBoxSharedImpl.syncUIWithDataModel(this );
101: }
102:
103: public ComboBoxModel getComboBoxModel() {
104: return (ComboBoxModel) dataModel;
105: }
106:
107: public void setComboBoxModel(ComboBoxModel dataModel) {
108: setDataModel(dataModel);
109: }
110:
111: public ListModel getListModel() {
112: return getComboBoxModel();
113: }
114:
115: public void setListModel(ListModel dataModel) {
116: setComboBoxModel((ComboBoxModel) dataModel);
117: }
118:
119: public void checkMutableComboBoxModel() {
120: ItsNatComboBoxSharedImpl
121: .checkMutableComboBoxModel(getComboBoxModel());
122: }
123:
124: public void addElement(Object anObject) {
125: checkMutableComboBoxModel();
126: MutableComboBoxModel model = (MutableComboBoxModel) getComboBoxModel();
127: model.addElement(anObject);
128: }
129:
130: public void insertElementAt(int index, Object anObject) {
131: checkMutableComboBoxModel();
132: MutableComboBoxModel model = (MutableComboBoxModel) getComboBoxModel();
133: model.insertElementAt(anObject, index);
134: }
135:
136: public void removeElementAt(int anIndex) {
137: checkMutableComboBoxModel();
138: MutableComboBoxModel model = (MutableComboBoxModel) getComboBoxModel();
139: model.removeElementAt(anIndex);
140: }
141:
142: public void removeAllElements() {
143: checkMutableComboBoxModel();
144: ItsNatComboBoxSharedImpl.removeAllElements(this );
145: }
146:
147: public void removeElement(Object anObject) {
148: checkMutableComboBoxModel();
149: MutableComboBoxModel model = (MutableComboBoxModel) getComboBoxModel();
150: model.removeElement(anObject);
151: }
152:
153: public int getSelectedIndex() {
154: return ItsNatComboBoxSharedImpl.getSelectedIndex(this );
155: }
156:
157: public void setSelectedIndex(int index) {
158: ItsNatComboBoxSharedImpl.setSelectedIndex(this , index);
159: }
160:
161: public Object getSelectedItem() {
162: return ItsNatComboBoxSharedImpl.getSelectedItem(this );
163: }
164:
165: public void setSelectedItem(Object anObject) {
166: ItsNatComboBoxSharedImpl.setSelectedItem(this , anObject);
167: }
168:
169: public Object[] getSelectedObjects() {
170: return ItsNatComboBoxSharedImpl.getSelectedObjects(this );
171: }
172:
173: public void contentsChanged(ListDataEvent e) {
174: super .contentsChanged(e);
175:
176: ItsNatComboBoxSharedImpl.contentsChanged(this , e);
177: }
178:
179: public void intervalAdded(ListDataEvent e) {
180: super .intervalAdded(e);
181:
182: ItsNatComboBoxSharedImpl.intervalAdded(this , e);
183: }
184:
185: public void intervalRemoved(ListDataEvent e) {
186: super .intervalRemoved(e);
187:
188: ItsNatComboBoxSharedImpl.intervalRemoved(this , e);
189: }
190:
191: public void addItemListener(ItemListener l) {
192: listenerList.add(ItemListener.class, l);
193: }
194:
195: public void removeItemListener(ItemListener l) {
196: listenerList.remove(ItemListener.class, l);
197: }
198:
199: public boolean hasItemListeners() {
200: return listenerList.getListenerCount() > 0;
201: }
202:
203: public ItemListener[] getItemListeners() {
204: return (ItemListener[]) listenerList
205: .getListeners(ItemListener.class);
206: }
207:
208: public void fireItemStateChanged(ItemEvent e) {
209: ItsNatComboBoxSharedImpl.fireItemStateChanged(this , e);
210: }
211:
212: public Object createDefaultModelInternal() {
213: return createDefaultListModel();
214: }
215:
216: public ListModel createDefaultListModel() {
217: return new DefaultComboBoxModel();
218: }
219:
220: public ItsNatListCellEditor getItsNatListCellEditor() {
221: return null;
222: }
223:
224: public void setItsNatListCellEditor(ItsNatListCellEditor cellEditor) {
225: throw new ItsNatException(
226: "Combo box items can not be graphically edited");
227: }
228:
229: public void startEditingAt(int index) {
230: throw new ItsNatException(
231: "Combo box items can not be graphically edited");
232: }
233:
234: public boolean isEditing() {
235: return false;
236: }
237:
238: public int getEditingIndex() {
239: return -1;
240: }
241:
242: public String getEditorActivatorEvent() {
243: throw new ItsNatException(
244: "Combo box items can not be graphically edited");
245: }
246:
247: public void setEditorActivatorEvent(String event) {
248: throw new ItsNatException(
249: "Combo box items can not be graphically edited");
250: }
251:
252: public void setUISelectedIndex(int index) {
253: ItsNatComboBoxUI compUI = getItsNatComboBoxUI();
254: compUI.setSelectedIndex(index);
255: }
256: }
|