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.*;
034: import java.awt.event.*;
035:
036: import javax.swing.*;
037: import javax.swing.border.*;
038:
039: import de.ug2t.kernel.*;
040: import de.ug2t.unifiedGui.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042: import de.ug2t.unifiedGui.views.*;
043:
044: public class HoSwingAnchoredPopup extends HoSwingComponent implements
045: IUnAnchoredPopUp {
046:
047: private JLabel pem_swingObj = null;
048: private HoSwingImage pem_icon = null;
049: private JDialog pem_win = null;
050: private int pem_hoffs = 0;
051: private int pem_voffs = 2;
052: private long pem_ts = 0;
053:
054: class APopUpLabel extends JLabel {
055: public APopUpLabel(String text) {
056: super (text);
057: // TODO Auto-generated constructor stub
058: }
059:
060: public void paint(Graphics g) {
061: if (HoSwingAnchoredPopup.this .pem_win.isVisible())
062: HoSwingAnchoredPopup.this .pcmf_displayPopup();
063:
064: super .paint(g);
065: }
066: }
067:
068: public HoSwingAnchoredPopup(String xName, IUnApplication xAppl)
069: throws Exception {
070: super (xName, xAppl);
071:
072: this .pem_swingObj = new APopUpLabel("");
073: ((JComponent) this .pem_swingObj).setOpaque(true);
074:
075: this .pdm_realSwingCmp = this .pem_swingObj;
076: this .pem_win = new JDialog(
077: ((HoSwingClient) this .pcmf_getAppl())
078: .pcmf_getClientFrame());
079: this .pem_win.setUndecorated(true);
080: ((JComponent) this .pem_win.getContentPane())
081: .setBorder(new LineBorder(Color.BLACK, 1));
082: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
083:
084: MouseAdapter l_ml = new MouseAdapter() {
085: public void mousePressed(MouseEvent e) {
086: if (System.currentTimeMillis()
087: - HoSwingAnchoredPopup.this .pem_ts < 100)
088: return;
089:
090: if (!HoSwingAnchoredPopup.this .pem_win.isVisible())
091: HoSwingAnchoredPopup.this .pcmf_displayPopup();
092: else
093: HoSwingAnchoredPopup.this .pcmf_hidePopup();
094: }
095: };
096: this .pem_swingObj.addMouseListener(l_ml);
097:
098: WindowFocusListener l_fl = new WindowFocusListener() {
099: public void windowGainedFocus(WindowEvent e) {
100: return;
101: }
102:
103: public void windowLostFocus(WindowEvent e) {
104: HoSwingAnchoredPopup.this .pcmf_hidePopup();
105: HoSwingAnchoredPopup.this .pem_ts = System
106: .currentTimeMillis();
107: }
108: };
109: this .pem_win.addWindowFocusListener(l_fl);
110:
111: return;
112: };
113:
114: public void pcmf_setValue(Object xValue) {
115: if (xValue instanceof IKeViewable) {
116: Object l_view = ((IKeViewable) xValue).pcmf_getView();
117: if (l_view instanceof UnIconValueView)
118: ((UnIconValueView) l_view).pcmf_applyStdView(this );
119: } else if (this .pcmf_getValue() instanceof IKeViewable) {
120: Object l_view = ((IKeViewable) this .pcmf_getValue())
121: .pcmf_getView();
122: if (l_view instanceof UnIconValueView)
123: ((UnIconValueView) l_view).pcmf_restStdView(this );
124: }
125:
126: this .pcmf_setLocalValue(xValue);
127: this .pem_swingObj.setText(this .pcmf_getValue().toString());
128:
129: return;
130: };
131:
132: public void pcmf_setComponent(IUnComponent xComp) {
133: this .pcmf_clear();
134: this .pcmf_addNode("POPUP", xComp.pcmf_getUnComponent());
135: }
136:
137: public void pcmf_setComponent(UnComponent xComp) {
138: this .pcmf_clear();
139: this .pcmf_addNode("POPUP", xComp);
140: }
141:
142: public void pcmf_setPopUpHorizontalOffset(int xOffs) {
143: this .pem_hoffs = xOffs;
144: }
145:
146: public int pcmf_getPopUpHorizontalOffset() {
147: return (this .pem_hoffs);
148: }
149:
150: public void pcmf_setPopUpVerticalOffset(int xOffs) {
151: this .pem_voffs = xOffs;
152: }
153:
154: public int pcmf_getPopUpVerticalOffset() {
155: return (this .pem_voffs);
156: }
157:
158: public boolean pcmf_isDisplay() {
159: return (this .pem_win.isVisible());
160: }
161:
162: private boolean pem_testModal(Component xComp) {
163: Component l_p = xComp.getParent();
164: if (l_p != null) {
165: if (l_p instanceof JDialog && ((JDialog) l_p).isModal())
166: return (true);
167: else
168: return (this .pem_testModal(l_p));
169: }
170: return (false);
171: }
172:
173: public void pcmf_displayPopup() {
174: if (this .pem_testModal(this .pem_swingObj))
175: this .pem_win.setModal(true);
176: else
177: this .pem_win.setModal(false);
178:
179: Point l_pt = this .pem_swingObj.getLocationOnScreen();
180: l_pt.translate(this .pem_hoffs, this .pem_swingObj.getHeight()
181: + this .pem_voffs);
182: this .pem_win.setLocation(l_pt);
183: HoSwingComponent l_cmp = (HoSwingComponent) this
184: .pcmf_getNodeAt(0);
185: if (l_cmp != null)
186: this .pem_win.setSize(l_cmp.pcmf_getRealSwingObj()
187: .getPreferredSize());
188: else
189: this .pem_win.setSize(100, 50);
190:
191: this .pem_win.getContentPane().removeAll();
192: this .pem_win.getContentPane().add(l_cmp.pcmf_getRealSwingObj());
193:
194: if (this .pem_win.isModal()) {
195: Thread l_vsbl = new Thread() {
196: public void run() {
197: pem_win.setVisible(true);
198: pem_win.toFront();
199: pem_win.requestFocus();
200: }
201: };
202: javax.swing.SwingUtilities.invokeLater(l_vsbl);
203: } else {
204: this .pem_win.setVisible(true);
205: this .pem_win.toFront();
206: this .pem_win.requestFocus();
207: }
208: }
209:
210: public void pcmf_hidePopup() {
211: this .pem_win.setVisible(false);
212: }
213:
214: public void pcmf_setIcon(IUnImage xIcon) {
215: pem_icon = (HoSwingImage) xIcon;
216: this .pem_swingObj.setIcon(((JLabel) pem_icon
217: .pcmf_getRealSwingObj()).getIcon());
218: }
219:
220: public IUnImage pcmf_getIcon() {
221: return (pem_icon);
222: };
223:
224: public java.awt.Container pcmf_getRealSwingObj() {
225: return (this .pdm_realSwingCmp);
226: };
227:
228: public java.awt.Container pcmf_getSwingWidget() {
229: return (this.pdm_realSwingCmp);
230: };
231: }
|