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.io.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038:
039: import de.ug2t.channel.ho.client.swing.*;
040: import de.ug2t.channel.markup.html.renderer.*;
041: import de.ug2t.connector.*;
042: import de.ug2t.kernel.*;
043: import de.ug2t.unifiedGui.*;
044: import de.ug2t.unifiedGui.interfaces.*;
045:
046: /**
047: * @author Dirk
048: *
049: * date: 20.01.2005
050: *
051: * <p>
052: * Purpose:
053: * </p>
054: */
055: public final class MuGenericSlider extends MuGenericComponent implements
056: IUnComponent, IUnSlider, IKePoolable {
057: private IKeView pem_view = new HtmlManualSliderRenderer();
058: private MuGenericDrawPane pem_dp = null;
059: private int pem_direction = IUnSlider.SLIDE_HORIZONTAL;
060: private JSlider pem_slider = null;
061: private Hashtable pem_labels = new Hashtable();
062: private int pem_slHi = 50;
063: private int pem_slWi = 170;
064: private IUnButton pem_lBut = null;
065: private IUnButton pem_llBut = null;
066: private IUnButton pem_mBut = null;
067: private IUnButton pem_mmBut = null;
068:
069: // @@
070:
071: class MuSliderPListener implements IUnGuiEventListener {
072: public void pcmf_execListener(UnComponent xParam) {
073: int l_val = Integer.parseInt(MuGenericSlider.this
074: .pcmf_getValue().toString());
075: int l_minVal = MuGenericSlider.this .pem_slider.getMinimum();
076: int l_newVal = --l_val;
077: if (l_newVal < l_minVal)
078: l_newVal = l_minVal;
079:
080: MuGenericSlider.this .pcmf_setValue(Integer
081: .toString(l_newVal));
082:
083: return;
084: };
085: };
086:
087: class MuSliderPPListener implements IUnGuiEventListener {
088: public void pcmf_execListener(UnComponent xParam) {
089: int l_val = Integer.parseInt(MuGenericSlider.this
090: .pcmf_getValue().toString());
091: int l_minVal = MuGenericSlider.this .pem_slider.getMinimum();
092: int l_newVal = l_val
093: - (MuGenericSlider.this .pem_slider
094: .getMajorTickSpacing() == 0 ? MuGenericSlider.this .pem_slider
095: .getMaximum() / 10
096: : MuGenericSlider.this .pem_slider
097: .getMajorTickSpacing());
098: if (l_newVal < l_minVal)
099: l_newVal = l_minVal;
100:
101: MuGenericSlider.this .pcmf_setValue(Integer
102: .toString(l_newVal));
103:
104: return;
105: };
106: };
107:
108: class MuSliderMListener implements IUnGuiEventListener {
109: public void pcmf_execListener(UnComponent xParam) {
110: int l_val = Integer.parseInt(MuGenericSlider.this
111: .pcmf_getValue().toString());
112: int l_maxVal = MuGenericSlider.this .pem_slider.getMaximum();
113: int l_newVal = ++l_val;
114: if (l_newVal > l_maxVal)
115: l_newVal = l_maxVal;
116:
117: MuGenericSlider.this .pcmf_setValue(Integer
118: .toString(l_newVal));
119:
120: return;
121: };
122: };
123:
124: class MuSliderMMListener implements IUnGuiEventListener {
125: public void pcmf_execListener(UnComponent xParam) {
126: int l_val = Integer.parseInt(MuGenericSlider.this
127: .pcmf_getValue().toString());
128: int l_maxVal = MuGenericSlider.this .pem_slider.getMaximum();
129: int l_newVal = l_val
130: + (MuGenericSlider.this .pem_slider
131: .getMajorTickSpacing() == 0 ? MuGenericSlider.this .pem_slider
132: .getMaximum() / 10
133: : MuGenericSlider.this .pem_slider
134: .getMajorTickSpacing());
135: if (l_newVal > l_maxVal)
136: l_newVal = l_maxVal;
137:
138: MuGenericSlider.this .pcmf_setValue(Integer
139: .toString(l_newVal));
140:
141: return;
142: };
143: };
144:
145: /**
146: * @param xName
147: * @param xTplGetter
148: * @param xTplName
149: * @param xAppl
150: * @throws Exception
151: */
152: public MuGenericSlider(String xName, ACoDataGetter xTplGetter,
153: Object xTplName, int xDirection, MuGenericApplication xAppl)
154: throws Exception {
155: super (xName, xTplGetter, xTplName, xAppl);
156: this .pem_direction = xDirection;
157:
158: if (xDirection == IUnSlider.SLIDE_HORIZONTAL)
159: pem_slider = new JSlider(JSlider.HORIZONTAL);
160: else
161: pem_slider = new JSlider(JSlider.VERTICAL);
162:
163: this .pcmf_setValue("0");
164: this .pcmf_setView(pem_view);
165:
166: this .pem_lBut = this .pcmf_getAppl().pcmf_getComponentFactory()
167: .pcmf_createButton(UnComponentFactory.MARKUP, "-",
168: this .pcmf_getAppl());
169: this .pem_llBut = this .pcmf_getAppl().pcmf_getComponentFactory()
170: .pcmf_createButton(UnComponentFactory.MARKUP, "--",
171: this .pcmf_getAppl());
172: this .pem_mBut = this .pcmf_getAppl().pcmf_getComponentFactory()
173: .pcmf_createButton(UnComponentFactory.MARKUP, "+",
174: this .pcmf_getAppl());
175: this .pem_mmBut = this .pcmf_getAppl().pcmf_getComponentFactory()
176: .pcmf_createButton(UnComponentFactory.MARKUP, "++",
177: this .pcmf_getAppl());
178:
179: this .pem_lBut.pcmf_addListener(new MuSliderPListener());
180: this .pem_llBut.pcmf_addListener(new MuSliderPPListener());
181: this .pem_mBut.pcmf_addListener(new MuSliderMListener());
182: this .pem_mmBut.pcmf_addListener(new MuSliderMMListener());
183: }
184:
185: // @@
186:
187: /**
188: * <p>
189: * Does...
190: * </p>
191: * <p>
192: *
193: * @return a Type with
194: * </p>
195: * <p>
196: * @param
197: * </p>
198: */
199: public void pcmf_setRange(int xMinVal, int xMaxVal, int xSteps) {
200: this .pem_slider.setMinimum(xMinVal);
201: this .pem_slider.setMaximum(xMaxVal);
202:
203: if (xSteps != 0) {
204: this .pem_slider.setMajorTickSpacing(xSteps);
205: this .pem_slider.setPaintTicks(true);
206: this .pem_slider.setPaintLabels(true);
207: }
208:
209: this .pcmf_setPropChanged(true);
210: }
211:
212: public int pcmf_getSteps() {
213: return (pem_slider.getMajorTickSpacing());
214: }
215:
216: public int pcmf_getMinimum() {
217: return (this .pem_slider.getMinimum());
218: }
219:
220: public int pcmf_getMaximum() {
221: return (this .pem_slider.getMaximum());
222: }
223:
224: public Map pcmf_getLabels() {
225: return (this .pem_labels);
226: }
227:
228: public int pcmf_getSliderWidth() {
229: return (this .pem_slWi);
230: }
231:
232: public int pcmf_getSliderHeight() {
233: return (this .pem_slHi);
234: }
235:
236: /**
237: * <p>
238: * Does...
239: * </p>
240: * <p>
241: *
242: * @return a Type with
243: * </p>
244: * <p>
245: * @param
246: * </p>
247: */
248: public void pcmf_setRange(Map xValues) {
249: Hashtable l_tab = new Hashtable();
250: l_tab.putAll(xValues);
251:
252: try {
253: this .pem_slider.setLabelTable(l_tab);
254: } catch (Exception e) {
255: KeLog
256: .pcmf_log(
257: "ug2t",
258: "slider can not be rendered from swing - not all labels are swing compatible",
259: this , KeLog.DEBUG);
260: }
261:
262: this .pcmf_setPropChanged(true);
263:
264: return;
265: }
266:
267: /**
268: * <p>
269: * Does...
270: * </p>
271: * <p>
272: *
273: * @return a Type with
274: * </p>
275: * <p>
276: * @param
277: * </p>
278: */
279: public void pcmf_setRange() {
280: try {
281: if (this .pem_labels.size() != 0)
282: this .pem_slider.setLabelTable(this .pem_labels);
283: } catch (Exception e) {
284: KeLog
285: .pcmf_log(
286: "ug2t",
287: "slider can not be rendered from swing - not all labels are swing compatible",
288: this , KeLog.DEBUG);
289: }
290:
291: this .pcmf_setPropChanged(true);
292:
293: return;
294: }
295:
296: /**
297: * <p>
298: * Does...
299: * </p>
300: * <p>
301: *
302: * @return a Type with
303: * </p>
304: * <p>
305: * @param
306: * </p>
307: */
308: public void pcmf_removeAllValues() {
309: this .pem_labels.clear();
310: }
311:
312: /**
313: * <p>
314: * Does...
315: * </p>
316: * <p>
317: *
318: * @return a Type with
319: * </p>
320: * <p>
321: * @param
322: * </p>
323: */
324: public void pcmf_addValue(String xKey, String xValue) {
325: this .pem_labels.put(new Integer(xKey), new JLabel(xValue));
326: }
327:
328: public void pcmf_addValueObj(String xKey, HoSwingComponent xValue) {
329: this .pem_labels.put(new Integer(xKey), xValue
330: .pcmf_getRealSwingObj());
331: }
332:
333: public void pcmf_addValueObj(String xKey, MuGenericComponent xValue) {
334: this .pem_labels.put(new Integer(xKey), xValue);
335: }
336:
337: public void pcmf_setValue(Object xValue) {
338: this .pem_slider.setValue(Math.round(Float.parseFloat(xValue
339: .toString())));
340: this .pcmf_setLocalValue(xValue);
341:
342: return;
343: };
344:
345: public void pcmf_commitSlider() {
346: this .pcmf_setRange();
347: }
348:
349: public void pcmf_addValueItem(String xName, Object xValue) {
350: if (xValue instanceof HoSwingComponent)
351: this .pcmf_addValueObj(xName, (HoSwingComponent) xValue);
352: else if (xValue instanceof MuGenericComponent)
353: this .pcmf_addValueObj(xName, (MuGenericComponent) xValue);
354: else
355: this .pcmf_addValue(xName, xValue.toString());
356: }
357:
358: public Object pcmf_getSliderOutPut() {
359: if (this .pem_dp == null)
360: this .pem_dp = (MuGenericDrawPane) this .pcmf_getAppl()
361: .pcmf_getComponentFactory().pcmf_createDrawPane(
362: UnComponentFactory.MARKUP, "MY_DP",
363: this .pem_slWi, this .pem_slWi,
364: this .pcmf_getAppl());
365:
366: if (this .pem_direction == IUnSlider.SLIDE_HORIZONTAL) {
367: this .pem_lBut.pcmf_setFixedSize(20, this .pem_slHi - 4,
368: UnFixedSize.FIX_SIZE);
369: this .pem_llBut.pcmf_setFixedSize(20, this .pem_slHi - 4,
370: UnFixedSize.FIX_SIZE);
371: this .pem_mBut.pcmf_setFixedSize(20, this .pem_slHi - 4,
372: UnFixedSize.FIX_SIZE);
373: this .pem_mmBut.pcmf_setFixedSize(20, this .pem_slHi - 4,
374: UnFixedSize.FIX_SIZE);
375: this .pem_slider.setSize(this .pem_slWi, this .pem_slHi);
376: this .pem_dp.pcmf_setDrawPaneSize(this .pem_slWi,
377: this .pem_slHi);
378: } else {
379: this .pem_lBut.pcmf_setFixedSize(this .pem_slHi - 4, 20,
380: UnFixedSize.FIX_SIZE);
381: this .pem_llBut.pcmf_setFixedSize(this .pem_slHi - 4, 20,
382: UnFixedSize.FIX_SIZE);
383: this .pem_mBut.pcmf_setFixedSize(this .pem_slHi - 4, 20,
384: UnFixedSize.FIX_SIZE);
385: this .pem_mmBut.pcmf_setFixedSize(this .pem_slHi - 4, 20,
386: UnFixedSize.FIX_SIZE);
387: this .pem_slider.setSize(this .pem_slHi, this .pem_slWi);
388: this .pem_dp.pcmf_setDrawPaneSize(this .pem_slHi,
389: this .pem_slWi);
390: }
391:
392: this .pem_dp.pcmf_clearDrawPane();
393: this .pem_slider.print(this .pem_dp.pcmf_getGraphics());
394: this .pem_dp.pcmf_commitDrawPane();
395:
396: return (this .pem_dp.pcmf_execView());
397: }
398:
399: public void pcmf_setSliderSize(int xWi, int xHi) {
400: if (xWi != this .pem_slWi || xHi != this .pem_slHi) {
401: this .pcmf_setPropChanged(true);
402: this .pem_slWi = xWi;
403: this .pem_slHi = xHi;
404: }
405: return;
406: }
407:
408: public Object pcmf_getLButOutPut() {
409: return (this .pem_lBut.pcmf_getUnComponent().pcmf_execView());
410: }
411:
412: public Object pcmf_getLLButOutPut() {
413: return (this .pem_llBut.pcmf_getUnComponent().pcmf_execView());
414: }
415:
416: public Object pcmf_getMButOutPut() {
417: return (this .pem_mBut.pcmf_getUnComponent().pcmf_execView());
418: }
419:
420: public Object pcmf_getMMButOutPut() {
421: return (this .pem_mmBut.pcmf_getUnComponent().pcmf_execView());
422: }
423:
424: public int pcmf_getDirection() {
425: return (this .pem_direction);
426: }
427:
428: public void pcmf_delete() throws Exception {
429: if (this .pdm_deleted == true)
430: return;
431:
432: if (this .pem_dp != null)
433: this .pem_dp.pcmf_delete();
434:
435: this .pem_lBut.pcmf_getUnComponent().pcmf_delete();
436: this .pem_llBut.pcmf_getUnComponent().pcmf_delete();
437: this .pem_mBut.pcmf_getUnComponent().pcmf_delete();
438: this .pem_mmBut.pcmf_getUnComponent().pcmf_delete();
439:
440: super .pcmf_delete();
441: };
442:
443: // @@
444:
445: /**
446: * <p>
447: * Does...
448: * </p>
449: * <p>
450: *
451: * @return a Type with
452: * </p>
453: * <p>
454: * @param
455: * </p>
456: */
457: public void pcmf_setFixedSize(int w, int h, int type) {
458: if (this .pcmf_getView() instanceof HtmlManualSliderRenderer) {
459: if (this .pcmf_getDirection() == IUnSlider.SLIDE_HORIZONTAL)
460: this .pcmf_setSliderSize(w - 80, h);
461: else
462: this .pcmf_setSliderSize(h - 80, w);
463: }
464:
465: super .pcmf_setFixedSize(w, h, type);
466: }
467:
468: /**
469: * <p>
470: * Does...
471: * </p>
472: * <p>
473: *
474: * @return a Type with
475: * </p>
476: * <p>
477: * @param
478: * </p>
479: */
480: public void pcmf_setBgColor(String xCol) {
481: try {
482: if (xCol.charAt(0) == '#') {
483: xCol = xCol.substring(1, xCol.length());
484: int r = Integer.parseInt(xCol.substring(0, 2), 16);
485: int g = Integer.parseInt(xCol.substring(2, 4), 16);
486: int b = Integer.parseInt(xCol.substring(4, 6), 16);
487: this .pem_slider.setBackground(new Color(r, g, b));
488: } else
489: this .pem_slider.setBackground(HoSwingComponent
490: .pcmf_createColor(xCol));
491: } catch (Exception e) {
492: KeLog.pcmf_logException("ug2t", this , e);
493: }
494: ;
495:
496: super .pcmf_setBgColor(xCol);
497:
498: return;
499: }
500:
501: /**
502: * <p>
503: * Does...
504: * </p>
505: * <p>
506: *
507: * @return a Type with
508: * </p>
509: * <p>
510: * @param
511: * </p>
512: */
513: public void pcmf_setFgColor(String xCol) {
514: try {
515: if (xCol.charAt(0) == '#') {
516: xCol = xCol.substring(1, xCol.length());
517: int r = Integer.parseInt(xCol.substring(0, 2), 16);
518: int g = Integer.parseInt(xCol.substring(2, 4), 16);
519: int b = Integer.parseInt(xCol.substring(4, 6), 16);
520: this .pem_slider.setForeground(new Color(r, g, b));
521: } else
522: this .pem_slider.setForeground(HoSwingComponent
523: .pcmf_createColor(xCol));
524: } catch (Exception e) {
525: KeLog.pcmf_logException("ug2t", this , e);
526: }
527: ;
528:
529: super .pcmf_setFgColor(xCol);
530:
531: return;
532: }
533:
534: /**
535: * <p>
536: * Does...
537: * </p>
538: * <p>
539: *
540: * @return a Type with
541: * </p>
542: * <p>
543: * @param
544: * </p>
545: */
546: public void pcmf_setFont(UnFontDescriptor xFont) {
547: Font l_font = Font.getFont(xFont.pcmf_getFontFullSpec(),
548: new Font(null, xFont.pcmf_getFontStyle(), xFont
549: .pcmf_getFontSize()));
550: this.pem_slider.setFont(l_font);
551: super.pcmf_setFont(xFont);
552:
553: return;
554: }
555: }
|