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.event.*;
034: import java.io.*;
035: import java.net.*;
036:
037: import javax.swing.*;
038:
039: import de.ug2t.channel.ho.*;
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042: import de.ug2t.xmlScript.*;
043:
044: public final class HoSwingEditor extends HoSwingComponent implements
045: IUnTextArea, IUnSyncComponent {
046: protected JEditorPane pdm_swingObj = null;
047: private JScrollPane pem_pane = null;
048: private String pem_mime = null;
049: protected char[] pdm_validSigns = null;
050:
051: class MyEditorPane extends JEditorPane {
052: public MyEditorPane() {
053: super ();
054: }
055:
056: public MyEditorPane(String arg0) throws IOException {
057: super (arg0);
058: }
059:
060: public MyEditorPane(String arg0, String arg1) {
061: super (arg0, arg1);
062: }
063:
064: public MyEditorPane(URL arg0) throws IOException {
065: super (arg0);
066: }
067:
068: protected void processKeyEvent(KeyEvent arg0) {
069: char l_char = arg0.getKeyChar();
070:
071: try {
072: if (HoSwingEditor.this .pdm_validSigns != null) {
073: for (int i = 0; i < HoSwingEditor.this .pdm_validSigns.length; i++)
074: if (HoSwingEditor.this .pdm_validSigns[i] == l_char) {
075: super .processKeyEvent(arg0);
076: return;
077: }
078: arg0.consume();
079: }
080: super .processKeyEvent(arg0);
081: } catch (Exception e) {
082: KeLog.pcmf_log("ug2t",
083: "error while dispatching key events", this ,
084: KeLog.DEBUG);
085: }
086: }
087: }
088:
089: public HoSwingEditor(String xName, String xValue, String xMime,
090: IUnApplication xAppl) throws Exception {
091: super (xName, xAppl);
092:
093: this .pdm_swingObj = new MyEditorPane(xMime, xValue);
094: this .pem_pane = new JScrollPane(this .pdm_swingObj);
095: super .pdm_realSwingCmp = this .pem_pane;
096:
097: this .pcmf_setLocalValue(xValue);
098: this .pem_mime = xMime;
099: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
100:
101: this .pemf_addScrollListeners();
102:
103: FocusListener l_f = new FocusAdapter() {
104: public void focusLost(FocusEvent ev) {
105: try {
106: String l_objName = HoSwingEditor.this
107: .pcmf_getObjName();
108:
109: // Lokale Listener aufrufen
110: HoSwingEditor.this
111: .pcmf_setLocalValue(HoSwingEditor.this .pdm_swingObj
112: .getText());
113: HoSwingEditor.this .pcmf_setRefresh();
114: HoSwingEditor.this .pcmf_dispatchEvent();
115:
116: if (HoSwingEditor.this .pem_session
117: .pcmf_isDisabled())
118: return;
119:
120: // Werte setzen um diese zum Server zu übertragen
121: ((HoSwingPage) HoSwingEditor.this .pcmf_getAppl()
122: .pcmf_getActive()).pcmf_setSubmitValue(
123: l_objName, HoSwingEditor.this
124: .pcmf_getValue().toString());
125: HoSwingEditor.this .pcmf_addSyncedWidgets(
126: (HoSwingPage) HoSwingEditor.this
127: .pcmf_getAppl().pcmf_getActive(),
128: HoSwingEditor.this );
129: if (HoSwingEditor.this .pcmf_getUnComponent()
130: .pcmf_isSubmit() == true)
131: ((HoSwingPage) HoSwingEditor.this
132: .pcmf_getAppl().pcmf_getActive())
133: .pcmf_submit();
134: } catch (Exception e) {
135: KeLog.pcmf_logException("ug2t", this , e);
136: }
137: ;
138: };
139: };
140: this .pdm_swingObj.addFocusListener(l_f);
141:
142: return;
143: };
144:
145: private void pemf_addScrollListeners() {
146: AdjustmentListener l_listen = new AdjustmentListener() {
147: private int pem_x = 0;
148: private int pem_y = 0;
149: private HoDelayedCall pem_call = null;
150:
151: public void adjustmentValueChanged(AdjustmentEvent e) {
152: if (this .pem_x == HoSwingEditor.this .pem_pane
153: .getHorizontalScrollBar().getValue()
154: && this .pem_y == HoSwingEditor.this .pem_pane
155: .getVerticalScrollBar().getValue())
156: return;
157:
158: if (pem_session != null) {
159: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
160: "");
161:
162: if (HoSwingEditor.this .pem_session
163: .pcmf_isInTransaction()) {
164: ScXmlScript.pcmf_createPBody(l_remCall);
165: } else {
166: ScXmlScript.pcmf_createxScriptString(l_remCall,
167: null);
168: ScXmlScript.pcmf_addProc(l_remCall, null);
169: }
170: ;
171:
172: this .pem_x = HoSwingEditor.this .pem_pane
173: .getHorizontalScrollBar().getValue();
174: this .pem_y = HoSwingEditor.this .pem_pane
175: .getVerticalScrollBar().getValue();
176:
177: ScXmlScript.pcmf_addCall(l_remCall, null,
178: HoSwingEditor.this .pcmf_getObjName(),
179: "pcmf_setScrollInfo");
180: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
181: .toString(this .pem_x), "false", "int");
182: ScXmlScript.pcmf_addCallPar(l_remCall, Integer
183: .toString(this .pem_y), "false", "int");
184: ScXmlScript.pcmf_endAll(l_remCall);
185:
186: if (this .pem_call == null
187: || this .pem_call.pcmf_isReady())
188: this .pem_call = new HoDelayedCall(l_remCall
189: .toString(),
190: HoSwingEditor.this .pem_session,
191: IUnComponent.EVENT_LATENCY_SCROLL,
192: HoSwingEditor.this , false);
193: else
194: this .pem_call.pcmf_refreshCall(l_remCall
195: .toString());
196: }
197: ;
198: }
199: };
200: this .pem_pane.getHorizontalScrollBar().addAdjustmentListener(
201: l_listen);
202: this .pem_pane.getVerticalScrollBar().addAdjustmentListener(
203: l_listen);
204: }
205:
206: public int pcmf_getCols() {
207: return (0);
208: };
209:
210: public int pcmf_getRows() {
211: return (0);
212: };
213:
214: public void pcmf_setValue(Object xValue) {
215: this .pdm_swingObj.setText(xValue.toString());
216: this .pdm_swingObj.setContentType(pem_mime);
217: this .pdm_swingObj.setCaretPosition(0);
218: this .pcmf_setLocalValue(xValue);
219:
220: return;
221: };
222:
223: public void pcmf_disable() {
224: this .pdm_swingObj.setEnabled(false);
225: super .pcmf_disable();
226: return;
227: };
228:
229: public void pcmf_enable() {
230: this .pdm_swingObj.setEnabled(true);
231: super .pcmf_enable();
232: return;
233: };
234:
235: public void pcmf_setFgColor(String xCol) {
236: try {
237: this .pdm_swingObj.setForeground(HoSwingComponent
238: .pcmf_createColor(xCol));
239:
240: super .pcmf_setFgColor(xCol);
241: } catch (Exception e) {
242: KeLog.pcmf_logException("ug2t", this , e);
243: }
244: ;
245:
246: return;
247: };
248:
249: public void pcmf_setBgColor(String xCol) {
250: try {
251: if (this .pdm_realSwingCmp instanceof JComponent) {
252: if (xCol.equals("transparent")) {
253: ((JComponent) this .pdm_swingObj).setOpaque(false);
254: return;
255: }
256:
257: ((JComponent) this .pdm_swingObj).setOpaque(true);
258: ((JComponent) this .pdm_swingObj)
259: .setBackground(HoSwingComponent
260: .pcmf_createColor(xCol));
261: }
262:
263: super .pcmf_setBgColor(xCol);
264: } catch (Exception e) {
265: KeLog.pcmf_logException("ug2t", this , e);
266: }
267: ;
268:
269: return;
270: };
271:
272: public void pcmf_setScroll(boolean xScroll) {
273: if (xScroll == true) {
274: super .pdm_realSwingCmp = this .pem_pane;
275: this .pem_pane.setViewportView(this .pdm_swingObj);
276: } else {
277: super .pdm_realSwingCmp = this .pdm_swingObj;
278: this .pem_pane.setViewportView(null);
279: }
280: };
281:
282: public boolean pcmf_getScroll() {
283: return (this .pem_pane.getViewport() == null ? false : true);
284: }
285:
286: public java.awt.Container pcmf_getSwingWidget() {
287: return (this .pdm_swingObj);
288: };
289:
290: public void pcmf_scrollXRel(int xPx) {
291: int l_x = this .pem_pane.getHorizontalScrollBar().getValue();
292: l_x += xPx;
293: this .pem_pane.getHorizontalScrollBar().setValue(l_x);
294: }
295:
296: public void pcmf_scrollXAbs(int xPx) {
297: this .pem_pane.getHorizontalScrollBar().setValue(xPx);
298: }
299:
300: public void pcmf_scrollYRel(int xPy) {
301: int l_y = this .pem_pane.getVerticalScrollBar().getValue();
302: l_y += xPy;
303: this .pem_pane.getVerticalScrollBar().setValue(l_y);
304: }
305:
306: public void pcmf_scrollYAbs(int xPy) {
307: this .pem_pane.getVerticalScrollBar().setValue(xPy);
308: }
309:
310: public int pcmf_getXScroll() {
311: return (this .pem_pane.getHorizontalScrollBar().getValue());
312: }
313:
314: public int pcmf_getYScroll() {
315: return (this .pem_pane.getVerticalScrollBar().getValue());
316: }
317:
318: public void pcmf_setReadOnly(boolean xReadOnly) {
319: this .pdm_swingObj.setEditable(!xReadOnly);
320: }
321:
322: public boolean pcmf_isReadOnly() {
323: return (!this .pdm_swingObj.isEditable());
324: }
325:
326: private int pem_syncCnt = 0;
327:
328: public Object pcmf_getValueToSync() {
329: return (this .pdm_swingObj.getText());
330: }
331:
332: public void pcmf_setSynced() {
333: this .pem_syncCnt++;
334: }
335:
336: public void pcmf_unSync() {
337: this .pem_syncCnt--;
338: if (this .pem_syncCnt < 0)
339: this .pem_syncCnt = 0;
340: }
341:
342: public boolean pcmf_isSynced() {
343: if (this .pem_syncCnt == 0)
344: return (false);
345: else
346: return (true);
347: }
348:
349: public void pcmf_setInputFilter(String xSigns) {
350: this .pdm_validSigns = xSigns.toCharArray();
351: }
352:
353: public void pcmf_removeInputFilter() {
354: this .pdm_validSigns = null;
355: }
356:
357: public String pcmf_getInputFilter() {
358: return (new String(this .pdm_validSigns));
359: }
360:
361: public void pcmf_setSelected() {
362: this .pdm_swingObj.select(0, this .pdm_swingObj.getText()
363: .length());
364: }
365:
366: public void pcmf_unSelect() {
367: this .pdm_swingObj.select(0, 0);
368: }
369:
370: public void pcmf_setCaretPosition(int xPos) {
371: this
372: .pcmf_setSelectionInterval(new SelectionInterval(xPos,
373: xPos));
374: }
375:
376: public void pcmf_setSelectionIntervall(int xBegin, int xLen) {
377: this .pdm_swingObj.select(xBegin, xBegin + xLen);
378: }
379:
380: public void pcmf_setSelectionInterval(SelectionInterval xIntervall) {
381: throw (new UnsupportedOperationException());
382: }
383: };
|