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