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.awt.event.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038:
039: import de.ug2t.channel.ho.*;
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.*;
042: import de.ug2t.unifiedGui.interfaces.*;
043:
044: public final class HoSwingDialog extends HoSwingContainer implements
045: IUnDialog {
046: private JDialog pem_swingObj = null;
047: private boolean pem_submitReshapes = false;
048: private Point pem_pos = null;
049:
050: protected class MyComponentListener extends ComponentAdapter {
051: private HoDelayedCall pem_callM = null;
052: private HoDelayedCall pem_callR = null;
053:
054: public void componentMoved(ComponentEvent e) {
055: if (HoSwingDialog.this .pcmf_getGenerateReshapeEvents())
056: this .pcmf_handle(IUnDialog.DIALOG_MOVED, (Component) e
057: .getSource());
058: }
059:
060: public void componentResized(ComponentEvent e) {
061: if (HoSwingDialog.this .pcmf_getGenerateReshapeEvents())
062: this .pcmf_handle(IUnDialog.DIALOG_RESIZED,
063: (Component) e.getSource());
064: }
065:
066: public void pcmf_handle(String xValue, Component xComp) {
067: try {
068: if (HoSwingDialog.this .pcmf_isDeleted())
069: return;
070:
071: if (xValue.equals(IUnDialog.DIALOG_MOVED))
072: HoSwingDialog.this .pcmf_setValue(xValue + ":"
073: + (int) xComp.getBounds().getX() + "px,"
074: + (int) xComp.getBounds().getY() + "px");
075: else
076: HoSwingDialog.this .pcmf_setValue(xValue + ":"
077: + xComp.getWidth() + "px,"
078: + xComp.getHeight() + "px");
079:
080: HoSwingDialog.this .pcmf_setRefresh();
081: HoSwingDialog.this .pcmf_getUnComponent()
082: .pcmf_dispatchEvent();
083:
084: if (HoSwingDialog.this .pem_session.pcmf_isDisabled())
085: return;
086:
087: // Werte setzen um diese zum Server zu übertragen
088: if ((HoSwingPage) HoSwingDialog.this .pcmf_getAppl()
089: .pcmf_getActive() == null)
090: return;
091:
092: if (xValue.equals(IUnDialog.DIALOG_MOVED)) {
093: if (this .pem_callM == null
094: || this .pem_callM.pcmf_isReady())
095: this .pem_callM = new HoDelayedCall(null,
096: HoSwingDialog.this .pem_session,
097: IUnComponent.EVENT_LATENCY_MOVE,
098: HoSwingDialog.this , HoSwingDialog.this
099: .pcmf_getValue().toString());
100: else
101: this .pem_callM.pcmf_refreshCall(null,
102: HoSwingDialog.this .pcmf_getValue()
103: .toString());
104: } else {
105: if (this .pem_callR == null
106: || this .pem_callR.pcmf_isReady())
107: this .pem_callR = new HoDelayedCall(null,
108: HoSwingDialog.this .pem_session,
109: IUnComponent.EVENT_LATENCY_RESIZE,
110: HoSwingDialog.this , HoSwingDialog.this
111: .pcmf_getValue().toString());
112: else
113: this .pem_callR.pcmf_refreshCall(null,
114: HoSwingDialog.this .pcmf_getValue()
115: .toString());
116: }
117: } catch (Exception e) {
118: KeLog.pcmf_logException("ug2t", this , e);
119: }
120: ;
121:
122: return;
123: }
124: }
125:
126: class MyWindowListener extends WindowAdapter {
127:
128: public void pcmf_handle(String xValue) {
129: try {
130: HoSwingDialog.this .pcmf_setValue(xValue);
131: HoSwingDialog.this .pcmf_setRefresh();
132: HoSwingDialog.this .pcmf_dispatchEvent();
133:
134: if (HoSwingDialog.this .pem_session.pcmf_isDisabled()
135: || HoSwingDialog.this .pcmf_isDeleted())
136: return;
137:
138: // Werte setzen um diese zum Server zu übertragen
139: if ((HoSwingPage) HoSwingDialog.this .pcmf_getAppl()
140: .pcmf_getActive() == null)
141: return;
142:
143: ((HoSwingPage) HoSwingDialog.this .pcmf_getAppl()
144: .pcmf_getActive()).pcmf_setSubmitValue(
145: HoSwingDialog.this .pcmf_getObjName(),
146: HoSwingDialog.this .pcmf_getValue().toString());
147: if (HoSwingDialog.this .pcmf_isSubmit() == true)
148: ((HoSwingPage) HoSwingDialog.this .pcmf_getAppl()
149: .pcmf_getActive()).pcmf_submit();
150: } catch (Exception e) {
151: KeLog.pcmf_logException("ug2t", this , e);
152: }
153: ;
154:
155: return;
156: }
157:
158: public void windowActivated(WindowEvent arg0) {
159: this .pcmf_handle(IUnDialog.DIALOG_ACTIVATED);
160: }
161:
162: public void windowClosed(WindowEvent arg0) {
163: this .pcmf_handle(IUnDialog.DIALOG_CLOSED);
164: }
165:
166: public void windowClosing(WindowEvent arg0) {
167: this .pcmf_handle(IUnDialog.DIALOG_CLOSING);
168: HoSwingDialog.this .pcmf_setValue(IUnDialog.DIALOG_CLOSED);
169: }
170:
171: public void windowDeactivated(WindowEvent arg0) {
172: this .pcmf_handle(IUnDialog.DIALOG_DEACTIVATED);
173: }
174:
175: public void windowDeiconified(WindowEvent arg0) {
176: this .pcmf_handle(IUnDialog.DIALOG_DEICONIFIED);
177: }
178:
179: public void windowGainedFocus(WindowEvent arg0) {
180: this .pcmf_handle(IUnDialog.DIALOG_GETFOCUS);
181: }
182:
183: public void windowIconified(WindowEvent arg0) {
184: this .pcmf_handle(IUnDialog.DIALOG_ICONIFIED);
185: }
186:
187: public void windowLostFocus(WindowEvent arg0) {
188: this .pcmf_handle(IUnDialog.DIALOG_LOSTFOCUS);
189: }
190:
191: public void windowOpened(WindowEvent arg0) {
192: this .pcmf_handle(IUnDialog.DIALOG_OPENED);
193: }
194: }
195:
196: /**
197: * @param xName
198: * @param xAppl
199: * @throws Exception
200: */
201: public HoSwingDialog(String xName, boolean xNoLayout,
202: IUnApplication xAppl) throws Exception {
203: super (xName, xAppl);
204:
205: if (xNoLayout) {
206: this .pdm_layout = null;
207: pdm_mainPanel.setLayout(null);
208: pdm_mainPanel.setMinimumSize(new Dimension(480, 400));
209: pdm_mainPanel.setMaximumSize(new Dimension(480, 400));
210: pdm_mainPanel.setPreferredSize(new Dimension(480, 400));
211: pdm_mainPane.setViewportView(pdm_mainPanel);
212: }
213: ;
214:
215: this .pem_swingObj = new JDialog(((HoSwingClient) xAppl)
216: .pcmf_getClientFrame());
217: this .pem_swingObj.addWindowListener(new MyWindowListener());
218: this .pem_swingObj
219: .addComponentListener(new MyComponentListener());
220: this .pem_swingObj.setTitle(xName);
221: this .pem_swingObj.setModal(false);
222: this .pem_swingObj.getContentPane().add(this .pdm_mainPane);
223:
224: this .pcmf_setLocalValue(xName);
225:
226: this .pem_swingObj.setBounds(200, 200, 400, 400);
227: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
228:
229: return;
230: }
231:
232: public void pcmf_setPosition(int xPos, int yPos, int xWi, int xHi) {
233: this .pcmf_setDialogPos(xPos, yPos, xWi, xHi);
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_displayDialog() {
249: if (this .pem_pos != null) {
250: Point l_p = ((HoSwingClient) this .pcmf_getAppl())
251: .pcmf_getClientFrame().getLocationOnScreen();
252: Rectangle l_rect = this .pem_swingObj.getBounds();
253: this .pem_swingObj.setBounds(l_p.x + l_rect.x, l_p.y
254: + l_rect.y, l_rect.width, l_rect.height);
255: this .pem_pos = null;
256: }
257: Iterator l_it = this .pcmf_getUnComponent()
258: .pcmf_getSubIterator();
259: Object l_obj = null;
260: while (l_it.hasNext()) {
261: l_obj = l_it.next();
262: if (l_obj instanceof HoSwingMenu) {
263: this .pem_swingObj
264: .setJMenuBar((JMenuBar) ((HoSwingMenu) l_obj)
265: .pcmf_getSwingWidget());
266: break;
267: }
268: }
269: if (this .pem_swingObj.isModal()) {
270: Thread l_vsbl = new Thread() {
271: public void run() {
272: pem_swingObj.setVisible(true);
273: pem_swingObj.toFront();
274: }
275: };
276: javax.swing.SwingUtilities.invokeLater(l_vsbl);
277: } else {
278: this .pem_swingObj.setVisible(true);
279: this .pem_swingObj.toFront();
280: }
281: }
282:
283: /**
284: * <p>
285: * Does...
286: * </p>
287: * <p>
288: *
289: * @return a Type with
290: * </p>
291: * <p>
292: * @param
293: * </p>
294: */
295: public void pcmf_hideDialog() {
296: this .pem_swingObj.setVisible(false);
297: }
298:
299: /**
300: * <p>
301: * Does...
302: * </p>
303: * <p>
304: *
305: * @return a Type with
306: * </p>
307: * <p>
308: * @param
309: * </p>
310: */
311: public boolean pcmf_isDisplay() {
312: return (this .pem_swingObj.isShowing());
313: }
314:
315: public void pcmf_setDialogPos(int xP, int yP, int xW, int xH) {
316: if (this .pem_swingObj.isShowing()) {
317: Point l_p = ((HoSwingClient) this .pcmf_getAppl())
318: .pcmf_getClientFrame().getLocationOnScreen();
319: this .pem_swingObj.setBounds(xP + l_p.x, yP + l_p.y, xW, xH);
320: } else {
321: this .pem_pos = new Point(xP, yP);
322: this .pem_swingObj.setBounds(xP, yP, xW, xH);
323: }
324: }
325:
326: public void pcmf_toFront() {
327: this .pem_swingObj.toFront();
328: }
329:
330: /**
331: * <p>
332: * Sets the dialogue to be resizable
333: * </p>
334: * <p>
335: *
336: * </p>
337: * <p>
338: *
339: * @param xSizable
340: * true indicates that the dialogue is resizable, false does the
341: * opposite
342: * </p>
343: */
344: public void pcmf_setResizable(boolean xSizable) {
345: this .pem_swingObj.setResizable(xSizable);
346: }
347:
348: /**
349: * <p>
350: * Informs about the resizability of the dialogue
351: * </p>
352: * <p>
353: *
354: * </p>
355: * <p>
356: * </p>
357: */
358: public boolean pcmf_isResizable() {
359: return (this .pem_swingObj.isResizable());
360: }
361:
362: public void pcmf_setDecoration(boolean xDeco) {
363: this .pem_swingObj.setUndecorated(!xDeco);
364: }
365:
366: public void pcmf_setScroll(boolean xScroll) {
367: if (xScroll == true) {
368: super .pdm_realSwingCmp = this .pdm_mainPane;
369: this .pdm_mainPane.setViewportView(this .pdm_mainPanel);
370: this .pem_swingObj.getContentPane().remove(
371: this .pdm_mainPanel);
372: this .pem_swingObj.getContentPane().add(this .pdm_mainPane);
373: } else {
374: super .pdm_realSwingCmp = this .pdm_mainPanel;
375: this .pdm_mainPane.setViewportView(null);
376: this .pem_swingObj.getContentPane()
377: .remove(this .pdm_mainPane);
378: this .pem_swingObj.getContentPane().add(this .pdm_mainPanel);
379: }
380: };
381:
382: public void pcmf_delete() throws Exception {
383: if (this .pdm_deleted == true)
384: return;
385:
386: this .pem_swingObj.dispose();
387:
388: super .pcmf_delete();
389: };
390:
391: public void pcmf_execListener(UnComponent xParam) throws Exception {
392: this .pcmf_displayDialog();
393: }
394:
395: public void pcmf_setModal(boolean xModal) {
396: this .pem_swingObj.setModal(xModal);
397: }
398:
399: public String pcmf_getTitle() {
400: return (this .pem_swingObj.getTitle());
401: }
402:
403: public void pcmf_setTitle(String xTitle) {
404: this .pem_swingObj.setTitle(xTitle);
405: }
406:
407: public boolean pcmf_isModal() {
408: return (this .pem_swingObj.isModal());
409: }
410:
411: public void pcmf_setGenerateReshapeEvents(boolean xReshapes) {
412: this .pem_submitReshapes = xReshapes;
413: return;
414: }
415:
416: public boolean pcmf_getGenerateReshapeEvents() {
417: return (this.pem_submitReshapes);
418: }
419: }
|