001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.markup.generic;
032:
033: import java.awt.*;
034: import java.util.*;
035:
036: import de.ug2t.channel.markup.html.renderer.*;
037: import de.ug2t.connector.*;
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.*;
040: import de.ug2t.unifiedGui.interfaces.*;
041:
042: public class MuGenericSpinner extends MuGenericComponent implements
043: IUnSpinner, IKePoolable {
044: private HashMap pem_values = new LinkedHashMap();
045: private IKeView pem_view = new HtmlSpinnerRenderer();
046: private IUnLink pem_up = null;
047: private IUnLink pem_down = null;
048:
049: final class MuSpinnerListener implements IUnGuiEventListener {
050: public void pcmf_execListener(UnComponent xParam)
051: throws Exception {
052: if (xParam == MuGenericSpinner.this .pem_down)
053: MuGenericSpinner.this .pcmf_spinDown();
054: else
055: MuGenericSpinner.this .pcmf_spinUp();
056:
057: MuGenericSpinner.this .pcmf_dispatchEvent();
058: }
059: }
060:
061: public MuGenericSpinner(String xName, ACoDataGetter xTplGetter,
062: Object xTplName, MuGenericApplication xAppl)
063: throws Exception {
064: super (xName, xTplGetter, xTplName, xAppl);
065:
066: this .pcmf_setView(pem_view);
067: this .pcmf_setBgColor("white");
068:
069: this .pem_up = IUnLink.Factory.create("");
070: this .pem_up.pcmf_setIcon(this .pcmf_getAppl()
071: .pcmf_getComponentFactory().pcmf_createImage(
072: UnComponentFactory.MARKUP, "up",
073: this .pcmf_getMarkupString("UPICO").toString(),
074: this .pcmf_getAppl()));
075: this .pem_down = IUnLink.Factory.create("");
076: this .pem_down
077: .pcmf_setIcon(this .pcmf_getAppl()
078: .pcmf_getComponentFactory().pcmf_createImage(
079: UnComponentFactory.MARKUP,
080: "down",
081: this .pcmf_getMarkupString("DOWNICO")
082: .toString(),
083: this .pcmf_getAppl()));
084:
085: IUnGuiEventListener l_listen = new MuSpinnerListener();
086: this .pem_up.pcmf_addListener(l_listen);
087: this .pem_down.pcmf_addListener(l_listen);
088:
089: this .pem_up.pcmf_setTextAlign(TEXT_ALIGN_CENTER);
090: this .pem_down.pcmf_setTextAlign(TEXT_ALIGN_CENTER);
091: UnFontDescriptor l_font = new UnFontDescriptor("arial", 5,
092: Font.PLAIN);
093: this .pem_up.pcmf_setFont(l_font);
094: this .pem_down.pcmf_setFont(l_font);
095:
096: this .pem_up.pcmf_setFixedSize(20, 5, UnFixedSize.FIX_SIZE);
097: this .pem_down.pcmf_setFixedSize(20, 5, UnFixedSize.FIX_SIZE);
098:
099: this .pcmf_setBorder(IUnComponent.INSETS_BORDER, "silver", 2);
100:
101: return;
102: };
103:
104: // @@
105:
106: public UnComponent pcmf_getUpKey() {
107: return (this .pem_up.pcmf_getUnComponent());
108: }
109:
110: public UnComponent pcmf_getDownKey() {
111: return (this .pem_down.pcmf_getUnComponent());
112: }
113:
114: public void pcmf_spinUp() {
115: Object l_selected = this .pcmf_getValue();
116: ArrayList l_keys = new ArrayList(this .pem_values.keySet());
117: int l_idx = l_keys.indexOf(l_selected);
118: l_idx++;
119: if (l_idx >= l_keys.size())
120: l_idx = 0;
121:
122: this .pcmf_setValue(l_keys.get(l_idx));
123: }
124:
125: public void pcmf_spinDown() {
126: Object l_selected = this .pcmf_getValue();
127: ArrayList l_keys = new ArrayList(this .pem_values.keySet());
128: int l_idx = l_keys.indexOf(l_selected);
129: l_idx--;
130: if (l_idx < 0)
131: l_idx = l_keys.size() - 1;
132:
133: this .pcmf_setValue(l_keys.get(l_idx));
134: }
135:
136: public void pcmf_addValueObj(String xValue, KeRegisteredObject xObj) {
137: this .pcmf_addValue(xValue, xObj);
138: this .pcmf_setPropChanged(true);
139: }
140:
141: public void pcmf_addValue(String xValue, String xString) {
142: pem_values.put(xValue, xString);
143: this .pcmf_setPropChanged(true);
144: };
145:
146: private void pcmf_addValue(String xValue, Object xString) {
147: if (xString instanceof KeTreeNode)
148: this .pcmf_addNode(xValue, (KeTreeNode) xString);
149:
150: pem_values.put(xValue, xString);
151: this .pcmf_setPropChanged(true);
152: };
153:
154: public void pcmf_removeValue(String xValue) {
155: this .pcmf_removeNode(xValue);
156: pem_values.remove(xValue);
157: this .pcmf_setPropChanged(true);
158: };
159:
160: private int pem_talign = IUnInputField.TEXT_ALIGN_WEST;
161:
162: public void pcmf_setTextAlign(int xAlign) {
163: this .pem_talign = xAlign;
164: }
165:
166: public int pcmf_getTextAlign() {
167: return (this .pem_talign);
168: }
169:
170: public void pcmf_disable() {
171: this .pem_up.pcmf_disable();
172: this .pem_down.pcmf_disable();
173:
174: super .pcmf_disable();
175: }
176:
177: public void pcmf_enable() {
178: this .pem_up.pcmf_enable();
179: this .pem_down.pcmf_enable();
180:
181: super .pcmf_enable();
182: }
183:
184: public void pcmf_clearSpinner() {
185: this .pem_values.clear();
186:
187: Iterator l_it = new ArrayList(this .pcmf_getAllSubs())
188: .iterator();
189: Object l_obj = null;
190: while (l_it.hasNext()) {
191: l_obj = l_it.next();
192: if (l_obj instanceof IUnContextMenu
193: || l_obj instanceof IUnEventChannel)
194: continue;
195:
196: this .pcmf_removeNode((KeTreeNode) l_obj);
197: }
198:
199: this .pcmf_setPropChanged(true);
200: }
201:
202: public void pcmf_clearAndReleaseSpinner() {
203: this .pem_values.clear();
204:
205: Iterator l_it = new ArrayList(this .pcmf_getAllSubs())
206: .iterator();
207: Object l_obj = null;
208: while (l_it.hasNext()) {
209: l_obj = l_it.next();
210: if (l_obj instanceof IUnContextMenu
211: || l_obj instanceof IUnEventChannel)
212: continue;
213:
214: this .pcmf_removeNode((KeTreeNode) l_obj);
215: ((KeTreeNode) l_obj).pcmf_releaseSubs();
216: }
217:
218: this .pcmf_setPropChanged(true);
219: }
220:
221: public void pcmf_delete() throws Exception {
222: if (this .pdm_deleted == true)
223: return;
224:
225: this .pem_up.pcmf_delete();
226: this .pem_down.pcmf_delete();
227:
228: super .pcmf_delete();
229: }
230:
231: // @@
232:
233: public HashMap pcmf_getValues() {
234: return (pem_values);
235: }
236:
237: public void pcmf_clearListWidget() {
238: this .pcmf_clearSpinner();
239: }
240:
241: public void pcmf_clearAndReleaseListWidget() {
242: this .pcmf_clearAndReleaseSpinner();
243: }
244:
245: public void pcmf_beginTr() {
246: return;
247: }
248:
249: public void pcmf_commitTr() {
250: return;
251: }
252: }
|