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.beans.*;
035:
036: import javax.swing.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.interfaces.*;
040:
041: final class MySplitPane extends JSplitPane {
042: protected HoSwingSplitPane pdm_myPane = null;
043:
044: public MySplitPane(HoSwingSplitPane xMyPane) {
045: super ();
046: this .pdm_myPane = xMyPane;
047: }
048:
049: public void paint(Graphics g) {
050: if (this .pdm_myPane != null) {
051: if (this .pdm_myPane.pcmf_getSliderPercent() >= 0)
052: this .pdm_myPane.pcmf_setSliderPercent(this .pdm_myPane
053: .pcmf_getSliderPercent());
054: else
055: this .pdm_myPane.pcmf_setSliderAbs(this .pdm_myPane
056: .pcmf_getSliderAbs());
057:
058: this .pdm_myPane.pcmf_setSplitInDraw(this .pdm_myPane
059: .pcmf_getSplitPercent(), g);
060: this .pdm_myPane = null;
061: }
062: super .paint(g);
063: }
064: }
065:
066: public final class HoSwingSplitPane extends HoSwingComponent implements
067: IUnSplitPane {
068: private int pem_percent = 20;
069: private int pem_mode = VSPLIT;
070: private int pem_slider = 2;
071: private int pem_sAbs = -1;
072:
073: private KeTreeNode pem_form1 = null;
074: private KeTreeNode pem_form2 = null;
075:
076: private MySplitPane pem_swingObj = null;
077:
078: class MyPropListener implements PropertyChangeListener {
079: public void propertyChange(PropertyChangeEvent evt) {
080: int l_size = 0;
081: if (HoSwingSplitPane.this .pem_mode == IUnSplitPane.VSPLIT)
082: l_size = HoSwingSplitPane.this .pem_swingObj.getWidth();
083: else
084: l_size = HoSwingSplitPane.this .pem_swingObj.getHeight();
085:
086: int l_wi = l_size
087: - HoSwingSplitPane.this .pem_swingObj
088: .getDividerSize();
089: float l_ss = 0;
090:
091: if (l_wi != 0)
092: l_ss = (float) HoSwingSplitPane.this .pem_swingObj
093: .getDividerLocation()
094: / (l_wi) * 100;
095:
096: try {
097: HoSwingSplitPane.this .pcmf_setValue(Float
098: .toString(l_ss));
099:
100: HoSwingSplitPane.this .pcmf_setRefresh();
101: HoSwingSplitPane.this .pcmf_getUnComponent()
102: .pcmf_dispatchEvent();
103:
104: if (HoSwingSplitPane.this .pem_session.pcmf_isDisabled())
105: return;
106:
107: // Werte setzen um diese zum Server zu übertragen
108: if ((HoSwingPage) HoSwingSplitPane.this .pcmf_getAppl()
109: .pcmf_getActive() == null)
110: return;
111:
112: ((HoSwingPage) HoSwingSplitPane.this .pcmf_getAppl()
113: .pcmf_getActive()).pcmf_setSubmitValue(
114: HoSwingSplitPane.this .pcmf_getUnComponent()
115: .pcmf_getObjName(),
116: HoSwingSplitPane.this .pcmf_getValue()
117: .toString());
118:
119: if (HoSwingSplitPane.this .pcmf_isSubmit() == true)
120: ((HoSwingPage) HoSwingSplitPane.this .pcmf_getAppl()
121: .pcmf_getActive()).pcmf_submit();
122: } catch (Exception e) {
123: KeLog.pcmf_logException("ug2t", this , e);
124: }
125: ;
126:
127: }
128: }
129:
130: public HoSwingSplitPane(String xName, IUnApplication xAppl)
131: throws Exception {
132: super (xName, xAppl);
133: this .pcmf_setLocalValue(xName);
134:
135: this .pem_swingObj = new MySplitPane(this );
136: this .pem_swingObj
137: .addPropertyChangeListener(new MyPropListener());
138: this .pem_swingObj.setBorder(null);
139: this .pem_swingObj.setOneTouchExpandable(true);
140: this .pdm_realSwingCmp = this .pem_swingObj;
141:
142: this .pcmf_setSplitMode(IUnSplitPane.VSPLIT);
143: this .pcmf_setSplitPercent(20);
144: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
145: }
146:
147: public KeTreeNode pcmf_addNode(String xName, KeTreeNode xNode) {
148: if (xNode instanceof HoSwingComponent
149: && xNode instanceof IUnMenu != true) {
150: if (this .pem_mode == IUnSplitPane.VSPLIT) {
151: if (xName.equals(IUnSplitPane.FNAME)
152: || (this .pem_form1 == null
153: && xName.equals(IUnSplitPane.FNAME) == false && xName
154: .equals(IUnSplitPane.SNAME) == false)) {
155: this .pem_swingObj
156: .setLeftComponent(((HoSwingComponent) xNode).pdm_realSwingCmp);
157: this .pem_form1 = xNode;
158: } else if (this .pem_form2 == null) {
159: this .pem_swingObj
160: .setRightComponent(((HoSwingComponent) xNode).pdm_realSwingCmp);
161: this .pem_form2 = xNode;
162: } else
163: KeLog
164: .pcmf_log(
165: "ug2t",
166: "can not set form to splitpane, remove inserted form first",
167: this , KeLog.MESSAGE);
168: } else {
169: if (xName.equals(IUnSplitPane.FNAME)
170: || (this .pem_form1 == null
171: && xName.equals(IUnSplitPane.FNAME) == false && xName
172: .equals(IUnSplitPane.SNAME) == false)) {
173: this .pem_swingObj
174: .setTopComponent(((HoSwingComponent) xNode).pdm_realSwingCmp);
175: this .pem_form1 = xNode;
176: } else if (this .pem_form2 == null) {
177: this .pem_swingObj
178: .setBottomComponent(((HoSwingComponent) xNode).pdm_realSwingCmp);
179: this .pem_form2 = xNode;
180: } else
181: KeLog
182: .pcmf_log(
183: "ug2t",
184: "can not set form to splitpane, remove inserted form first",
185: this , KeLog.MESSAGE);
186: }
187: }
188:
189: return (null);
190: };
191:
192: public KeTreeNode pcmf_removeNode(String xName) {
193: if (this .pem_mode == IUnSplitPane.VSPLIT) {
194: if (xName.equals(IUnSplitPane.FNAME)) {
195: this .pem_swingObj.setLeftComponent(null);
196: this .pem_form1 = null;
197: } else {
198: this .pem_swingObj.setRightComponent(null);
199: this .pem_form2 = null;
200: }
201: } else {
202: if (xName.equals(IUnSplitPane.FNAME)) {
203: this .pem_swingObj.setTopComponent(null);
204: this .pem_form1 = null;
205: } else {
206: this .pem_swingObj.setBottomComponent(null);
207: this .pem_form2 = null;
208: }
209: }
210:
211: return (null);
212: };
213:
214: public KeTreeNode pcmf_removeNode(KeTreeNode xNode) {
215: if (this .pem_form1 == xNode) {
216: if (this .pem_mode == IUnSplitPane.VSPLIT) {
217: this .pem_swingObj.setLeftComponent(null);
218: this .pem_form1 = null;
219: } else {
220: this .pem_swingObj.setTopComponent(null);
221: this .pem_form1 = null;
222: }
223: } else if (this .pem_form2 == xNode) {
224: if (this .pem_mode == IUnSplitPane.VSPLIT) {
225: this .pem_swingObj.setRightComponent(null);
226: this .pem_form2 = null;
227: } else {
228: this .pem_swingObj.setBottomComponent(null);
229: this .pem_form2 = null;
230: }
231: }
232:
233: return (null);
234: };
235:
236: public void pcmf_addFirst(IUnForm xForm) {
237: this .pcmf_removeFirst();
238: this .pcmf_addNode(FNAME, xForm.pcmf_getUnComponent());
239: return;
240: }
241:
242: public void pcmf_addSecond(IUnForm xForm) {
243: this .pcmf_removeSecond();
244: this .pcmf_addNode(SNAME, xForm.pcmf_getUnComponent());
245: return;
246: }
247:
248: public void pcmf_removeFirst() {
249: this .pcmf_removeNode(FNAME);
250: return;
251: }
252:
253: public void pcmf_removeSecond() {
254: this .pcmf_removeNode(SNAME);
255: return;
256: }
257:
258: public void pcmf_setSplitPercent(int xPercent) {
259: this .pem_swingObj.pdm_myPane = this ;
260: this .pem_percent = xPercent;
261: this .pem_swingObj.repaint();
262: }
263:
264: protected void pcmf_setSplitInDraw(int xPercent, Graphics g) {
265: int l = 0;
266: int l_size = 0;
267: if (this .pem_mode == IUnSplitPane.VSPLIT)
268: l_size = this .pem_swingObj.getWidth();
269: else
270: l_size = this .pem_swingObj.getHeight();
271:
272: if (pem_slider >= 0)
273: l = (l_size * xPercent / 100)
274: - (this .pem_swingObj.getWidth() * pem_slider / 200);
275: else
276: l = (l_size * xPercent / 100) - (pem_sAbs / 2);
277:
278: if (l <= this .pem_swingObj.getMaximumDividerLocation())
279: this .pem_swingObj.setDividerLocation(l);
280: else
281: this .pem_swingObj.setDividerLocation(this .pem_swingObj
282: .getMaximumDividerLocation());
283:
284: this .pem_percent = xPercent;
285: }
286:
287: public void pcmf_setSplitMode(int xSplit) {
288: if (xSplit == IUnSplitPane.VSPLIT)
289: this .pem_swingObj
290: .setOrientation(JSplitPane.HORIZONTAL_SPLIT);
291: else
292: this .pem_swingObj.setOrientation(JSplitPane.VERTICAL_SPLIT);
293:
294: this .pem_mode = xSplit;
295: }
296:
297: public int pcmf_getSplitPercent() {
298: return (this .pem_percent);
299: }
300:
301: public int pcmf_getSplitMode() {
302: return (this .pem_mode);
303: }
304:
305: public void pcmf_delete() throws Exception {
306: if (this .pdm_deleted == true)
307: return;
308:
309: super .pcmf_delete();
310:
311: if (pem_form1 != null && this .pcmf_isOwner())
312: pem_form1.pcmf_delete();
313:
314: if (pem_form2 != null && this .pcmf_isOwner())
315: pem_form2.pcmf_delete();
316:
317: return;
318: };
319:
320: public void pcmf_setSliderPercent(int xPercent) {
321: this .pem_slider = xPercent;
322: this .pem_sAbs = -1;
323:
324: int l_size = 0;
325: if (this .pem_mode == IUnSplitPane.VSPLIT)
326: l_size = this .pem_swingObj.getWidth();
327: else
328: l_size = this .pem_swingObj.getHeight();
329:
330: this .pem_swingObj.setDividerSize(l_size * xPercent / 100);
331:
332: return;
333: }
334:
335: public int pcmf_getSliderPercent() {
336: return (this .pem_slider);
337: }
338:
339: public int pcmf_getSliderAbs() {
340: return (this .pem_sAbs);
341: }
342:
343: public final void pcmf_clearAndRelease() {
344: if (this .pem_mode == IUnSplitPane.VSPLIT) {
345: this .pem_swingObj.setLeftComponent(null);
346: this .pem_swingObj.setRightComponent(null);
347: } else {
348: this .pem_swingObj.setTopComponent(null);
349: this .pem_swingObj.setBottomComponent(null);
350: }
351: super .pcmf_clearAndRelease();
352:
353: return;
354: }
355:
356: public final void pcmf_clear() {
357: if (this .pem_mode == IUnSplitPane.VSPLIT) {
358: this .pem_swingObj.setLeftComponent(null);
359: this .pem_swingObj.setRightComponent(null);
360: } else {
361: this .pem_swingObj.setTopComponent(null);
362: this .pem_swingObj.setBottomComponent(null);
363: }
364: super .pcmf_clear();
365:
366: return;
367: }
368:
369: public java.awt.Container pcmf_getSwingWidget() {
370: return (this .pem_swingObj);
371: };
372:
373: public void pcmf_setSliderAbs(int xPixel) {
374: this .pem_slider = -1;
375: this.pem_swingObj.setDividerSize(xPixel);
376: this.pem_sAbs = xPixel;
377:
378: return;
379: }
380:
381: }
|