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.server.generic;
032:
033: import java.awt.*;
034: import java.awt.image.*;
035: import java.io.*;
036:
037: import javax.imageio.*;
038:
039: import de.ug2t.kernel.*;
040: import de.ug2t.unifiedGui.interfaces.*;
041: import de.ug2t.xmlScript.*;
042:
043: /**
044: * @author Dirk
045: *
046: * date: 11.06.2004
047: *
048: * <p>
049: * Purpose:
050: * </p>
051: */
052: public final class HoSrvGenericDrawPane extends AHoSrvGenericComponent
053: implements IUnDrawPane {
054: private BufferedImage pem_image = null;
055: private int pem_width = 0;
056: private int pem_height = 0;
057: private String pem_imageName = "";
058: private String pem_imageNameURL = "";
059:
060: /**
061: * @param xName
062: * @param xSess
063: * @throws Exception
064: */
065: public HoSrvGenericDrawPane(String xName, int xWidth, int xHeight,
066: IUnApplication xAppl, String xClass) throws Exception {
067: super (xName);
068: this .pcmf_setAppl(xAppl);
069:
070: this .pem_width = xWidth;
071: this .pem_height = xHeight;
072: this .pem_imageNameURL = this .pcmf_buildUrl(this
073: .pcmf_getUniqueName());
074: this .pem_imageName = KeEnvironment.pcmf_getTmpDir()
075: + this .pcmf_getUniqueName() + ".jpg";
076: this .pcmf_setLocalValue(pem_imageNameURL);
077:
078: this .pem_image = new BufferedImage(xWidth, xHeight,
079: BufferedImage.TYPE_INT_RGB);
080:
081: if (xClass == null)
082: pdm_clientClass = "de.ug2t.channel.ho.client.swing.HoSwingDrawPane";
083: else
084: pdm_clientClass = xClass;
085:
086: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
087: "");
088:
089: if (this .pdm_session.pcmf_isInTransaction()) {
090: ScXmlScript.pcmf_createPBody(l_remCall);
091: } else {
092: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
093: ScXmlScript.pcmf_addProc(l_remCall, null);
094: }
095: ;
096: ScXmlScript.pcmf_addDecl(l_remCall, this .pcmf_getRemName(),
097: this .pdm_clientClass, "global");
098: ScXmlScript.pcmf_addDeclPar(l_remCall, xName, "false",
099: "java.lang.String");
100: ScXmlScript.pcmf_addDeclPar(l_remCall, this .pem_imageNameURL,
101: "false", "java.lang.String");
102: ScXmlScript.pcmf_addDeclPar(l_remCall,
103: ((HoSrvGenericApplication) xAppl).pcmf_getRemName(),
104: "true", "de.ug2t.unifiedGui.interfaces.IUnApplication");
105:
106: ScXmlScript.pcmf_endAll(l_remCall);
107:
108: this .pdm_session.pcmf_call(l_remCall.toString(), this );
109:
110: this .pcmf_commitDrawPane();
111: this .pcmf_enableSubmit();
112:
113: return;
114: }
115:
116: private String pcmf_buildUrl(String xValue) {
117: HoSrvGenericApplication l_appl = (HoSrvGenericApplication) this
118: .pcmf_getAppl();
119:
120: if (l_appl.pcmf_isMixedMode()) {
121: String l_tmp = KeEnvironment.pcmf_getTmpDir();
122: String l_root = KeEnvironment.pcmf_getRootDir();
123: l_tmp = l_tmp.replace('\\', '/');
124: l_root = l_root.replace('\\', '/');
125: l_tmp = KeTools.pcmf_stringSubst(l_tmp, l_root, "");
126:
127: return ("http://" + l_appl.pcmf_getHostName() + ":"
128: + Integer.toString(l_appl.pcmf_getPort()) + "/"
129: + l_appl.pcmf_getRootUrl() + "/" + l_tmp + xValue + ".jpg");
130: } else
131: return ("file:" + KeEnvironment.pcmf_getTmpDir() + xValue + ".jpg");
132: }
133:
134: /**
135: * <p>
136: * Does...
137: * </p>
138: * <p>
139: *
140: * @return a Type with
141: * </p>
142: * <p>
143: * @param
144: * </p>
145: */
146: public AHoSrvGenericComponent pcmf_buildRefObj() throws Exception {
147: AHoSrvGenericComponent l_obj = new HoSrvGenericDrawPane(this
148: .pcmf_getValue().toString(), pem_width, pem_height,
149: this .pcmf_getAppl(), this .pdm_clientClass);
150: l_obj.pcmf_setGlobal(true);
151: this .pcmf_setGlobal(true);
152: l_obj.pcmf_setAutoEcho(this .pcmf_doAutoEcho());
153: l_obj.pcmf_setRefFrom(this );
154: this .pcmf_addRef(l_obj);
155:
156: return l_obj;
157: }
158:
159: /**
160: * <p>
161: * Does...
162: * </p>
163: * <p>
164: *
165: * @return a Type with
166: * </p>
167: * <p>
168: * @param
169: * </p>
170: */
171: public void pcmf_clearDrawPane() {
172: this .pem_image.flush();
173: this .pem_image = new BufferedImage(this .pem_width,
174: this .pem_height, BufferedImage.TYPE_INT_RGB);
175: }
176:
177: /**
178: * <p>
179: * Does...
180: * </p>
181: * <p>
182: *
183: * @return a Type with
184: * </p>
185: * <p>
186: * @param
187: * </p>
188: */
189: public Graphics pcmf_getGraphics() {
190: return (this .pem_image.getGraphics());
191: }
192:
193: /**
194: * <p>
195: * Does...
196: * </p>
197: * <p>
198: *
199: * @return a Type with
200: * </p>
201: * <p>
202: * @param
203: * </p>
204: */
205: public void pcmf_commitDrawPane() {
206: try {
207: ImageIO.write(this .pem_image, "jpg", new File(
208: this .pem_imageName));
209: } catch (Exception e) {
210: KeLog.pcmf_log("ug2t",
211: "error writing drawPane image to temp", this ,
212: KeLog.ERROR);
213: return;
214: }
215:
216: KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper(
217: "");
218:
219: if (this .pdm_session.pcmf_isInTransaction()) {
220: ScXmlScript.pcmf_createPBody(l_remCall);
221: } else {
222: ScXmlScript.pcmf_createxScriptString(l_remCall, null);
223: ScXmlScript.pcmf_addProc(l_remCall, null);
224: }
225: ;
226: ScXmlScript.pcmf_addCall(l_remCall, null, this
227: .pcmf_getRemName(), "pcmf_commitDrawPane");
228: ScXmlScript.pcmf_endAll(l_remCall);
229:
230: this .pdm_session.pcmf_call(l_remCall.toString(), this );
231:
232: return;
233: }
234:
235: public void pcmf_setDrawPaneSize(int x, int y) {
236: this .pem_width = x;
237: this .pem_height = y;
238: this .pem_image = new BufferedImage(x, y,
239: BufferedImage.TYPE_INT_RGB);
240: this .pcmf_commitDrawPane();
241: }
242:
243: public int pcmf_getDrawPaneSizeX() {
244: return this .pem_width;
245: }
246:
247: public int pcmf_getDrawPaneSizeY() {
248: return this .pem_height;
249: }
250:
251: public void pcmf_setFixedSize(int w, int h, int type) {
252: super .pcmf_setFixedSize(w, h, type);
253: this .pcmf_setDrawPaneSize(w, h);
254: }
255:
256: public void pcmf_delete() throws Exception {
257: if (this .pdm_deleted == true)
258: return;
259:
260: this .pem_image.flush();
261: new File(this.pem_imageName).delete();
262:
263: super.pcmf_delete();
264: };
265: }
|