001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 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.ho.client.swing;
032:
033: import java.awt.*;
034: import java.util.*;
035:
036: import javax.swing.*;
037: import javax.swing.event.*;
038:
039: import de.ug2t.channel.ho.*;
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042:
043: /**
044: * @author Dirk
045: *
046: * date: 20.01.2005
047: *
048: * <p>
049: * Purpose:
050: * </p>
051: */
052: public final class HoSwingSlider extends HoSwingComponent implements
053: IUnSlider {
054: private JSlider pem_swingSlider = null;
055: private Hashtable pem_labels = new Hashtable();
056:
057: /**
058: * @param xName
059: * @param xAppl
060: * @throws Exception
061: */
062: public HoSwingSlider(String xName, int xDirection,
063: IUnApplication xAppl) throws Exception {
064: super (xName, xAppl);
065: this .pcmf_setLocalValue("1");
066:
067: if (xDirection == IUnSlider.SLIDE_HORIZONTAL)
068: pem_swingSlider = new JSlider(JSlider.HORIZONTAL);
069: else
070: pem_swingSlider = new JSlider(JSlider.VERTICAL);
071:
072: super .pdm_realSwingCmp = this .pem_swingSlider;
073: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
074:
075: ChangeListener l = new ChangeListener() {
076: private HoDelayedCall pem_call = null;
077:
078: public void stateChanged(ChangeEvent ev) {
079: try {
080: String l_objName = HoSwingSlider.this
081: .pcmf_getObjName();
082:
083: // Lokale Listener aufrufen
084: HoSwingSlider.this
085: .pcmf_setValue(Integer
086: .toString(HoSwingSlider.this .pem_swingSlider
087: .getValue()));
088: HoSwingSlider.this .pcmf_setRefresh();
089: HoSwingSlider.this .pcmf_dispatchEvent();
090:
091: if (HoSwingSlider.this .pem_session
092: .pcmf_isDisabled())
093: return;
094:
095: // Werte setzen um diese zum Server zu übertragen
096: HoSwingSlider.this .pcmf_addSyncedWidgets(
097: (HoSwingPage) HoSwingSlider.this
098: .pcmf_getAppl().pcmf_getActive(),
099: HoSwingSlider.this );
100:
101: if (this .pem_call == null
102: || this .pem_call.pcmf_isReady())
103: this .pem_call = new HoDelayedCall(null,
104: HoSwingSlider.this .pem_session,
105: IUnComponent.EVENT_LATENCY_SCROLL,
106: HoSwingSlider.this , HoSwingSlider.this
107: .pcmf_getValue().toString());
108: else
109: this .pem_call.pcmf_refreshCall(null,
110: HoSwingSlider.this .pcmf_getValue()
111: .toString());
112: } catch (Exception e) {
113: KeLog.pcmf_logException("ug2t", this , e);
114: }
115: ;
116: };
117: };
118: this .pem_swingSlider.addChangeListener(l);
119: }
120:
121: /**
122: * <p>
123: * Does...
124: * </p>
125: * <p>
126: *
127: * @return a Type with
128: * </p>
129: * <p>
130: * @param
131: * </p>
132: */
133: public void pcmf_setRange(int xMinVal, int xMaxVal, int xSteps) {
134: this .pem_swingSlider.setMinimum(xMinVal);
135: this .pem_swingSlider.setMaximum(xMaxVal);
136:
137: if (xSteps != 0) {
138: this .pem_swingSlider.setMajorTickSpacing(xSteps);
139: this .pem_swingSlider.setPaintTicks(true);
140: this .pem_swingSlider.setPaintLabels(true);
141: }
142: }
143:
144: /**
145: * <p>
146: * Does...
147: * </p>
148: * <p>
149: *
150: * @return a Type with
151: * </p>
152: * <p>
153: * @param
154: * </p>
155: */
156: public void pcmf_setRange(Map xValues) {
157: Hashtable l_tab = new Hashtable();
158: l_tab.putAll(xValues);
159: this .pem_swingSlider.setLabelTable(l_tab);
160:
161: return;
162: }
163:
164: /**
165: * <p>
166: * Does...
167: * </p>
168: * <p>
169: *
170: * @return a Type with
171: * </p>
172: * <p>
173: * @param
174: * </p>
175: */
176: public void pcmf_setRange() {
177: if (this .pem_labels.size() != 0)
178: this .pem_swingSlider.setLabelTable(this .pem_labels);
179:
180: return;
181: }
182:
183: /**
184: * <p>
185: * Does...
186: * </p>
187: * <p>
188: *
189: * @return a Type with
190: * </p>
191: * <p>
192: * @param
193: * </p>
194: */
195: public void pcmf_removeAllValues() {
196: Iterator l_it = this .pem_labels.values().iterator();
197: while (l_it.hasNext()) {
198: Object l_obj = l_it.next();
199: if (l_obj instanceof Component)
200: HoSwingClient.pcm_vPanel.remove((Component) l_obj);
201: }
202: this .pem_labels.clear();
203: }
204:
205: /**
206: * <p>
207: * Does...
208: * </p>
209: * <p>
210: *
211: * @return a Type with
212: * </p>
213: * <p>
214: * @param
215: * </p>
216: */
217: public void pcmf_addValue(String xKey, String xValue) {
218: this .pem_labels.put(new Integer(xKey), new JLabel(xValue));
219: }
220:
221: /**
222: * <p>
223: * Does...
224: * </p>
225: * <p>
226: *
227: * @return a Type with
228: * </p>
229: * <p>
230: * @param
231: * </p>
232: */
233: public void pcmf_addValueObj(String xKey, HoSwingComponent xValue) {
234: this .pem_labels.put(new Integer(xKey), xValue
235: .pcmf_getRealSwingObj());
236: HoSwingClient.pcm_vPanel.add(xValue.pcmf_getRealSwingObj());
237: }
238:
239: public void pcmf_setValue(Object xValue) {
240: this .pem_swingSlider.setValue(Integer.parseInt(xValue
241: .toString()));
242: this .pcmf_setLocalValue(xValue);
243:
244: return;
245: };
246:
247: public void pcmf_commitSlider() {
248: this .pcmf_setRange();
249: }
250:
251: public void pcmf_addValueItem(String xName, Object xValue) {
252: if (xValue instanceof HoSwingComponent)
253: this .pcmf_addValueObj(xName, (HoSwingComponent) xValue);
254: else
255: this .pcmf_addValue(xName, xValue.toString());
256: }
257:
258: public void pcmf_delete() throws Exception {
259: this.pcmf_removeAllValues();
260: super.pcmf_delete();
261: }
262:
263: }
|