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.markup.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.channel.markup.html.renderer.*;
040: import de.ug2t.connector.*;
041: import de.ug2t.kernel.*;
042: import de.ug2t.unifiedGui.interfaces.*;
043:
044: public final class MuGenericDrawPane extends MuGenericComponent
045: implements IUnDrawPane, IKePoolable {
046: private IKeView pem_view = new HtmlDrawPaneRenderer();
047: private transient BufferedImage pem_image = null;
048: private int pem_width = 0;
049: private int pem_height = 0;
050: private int pem_cnt = 0;
051:
052: private String pdm_imageNameURL = "";
053: private String pem_imageName = "";
054:
055: /**
056: * @param xName
057: * @param xTplGetter
058: * @param xTplName
059: * @param xAppl
060: * @throws Exception
061: */
062: public MuGenericDrawPane(String xName, int xWidth, int xHeight,
063: ACoDataGetter xTplGetter, Object xTplName,
064: MuGenericApplication xAppl) throws Exception {
065: super (xName, xTplGetter, xTplName, xAppl);
066:
067: this .pcmf_setView(pem_view);
068: this .pcmf_setValue(xName);
069:
070: this .pemf_buidImageURL();
071:
072: this .pem_width = xWidth;
073: this .pem_height = xHeight;
074: this .pem_image = new BufferedImage(xWidth, xHeight,
075: BufferedImage.TYPE_INT_RGB);
076: this .pcmf_commitDrawPane();
077:
078: return;
079: };
080:
081: // @@
082:
083: private void pemf_buidImageURL() {
084: String l_tmp = KeEnvironment.pcmf_getTmpDir();
085: String l_root = KeEnvironment.pcmf_getRootDir();
086: l_tmp = l_tmp.replace('\\', '/');
087: l_root = l_root.replace('\\', '/');
088: l_tmp = KeTools.pcmf_stringSubst(l_tmp, l_root, "");
089: this .pdm_imageNameURL = this .pcmf_getAppl().pcmf_getHostName()
090: + ":"
091: + Integer.toString(this .pcmf_getAppl().pcmf_getPort())
092: + "/" + this .pcmf_getAppl().pcmf_getRootUrl() + "/"
093: + l_tmp + this .pcmf_getUniqueName() + this .pem_cnt
094: + ".jpg";
095: this .pem_imageName = KeEnvironment.pcmf_getTmpDir()
096: + this .pcmf_getUniqueName() + this .pem_cnt + ".jpg";
097: }
098:
099: /**
100: * <p>
101: * Does...
102: * </p>
103: * <p>
104: *
105: * @return a Type with
106: * </p>
107: * <p>
108: * @param
109: * </p>
110: */
111: public void pcmf_clearDrawPane() {
112: this .pem_image.flush();
113: this .pem_image = new BufferedImage(this .pem_width,
114: this .pem_height, BufferedImage.TYPE_INT_RGB);
115: }
116:
117: /**
118: * <p>
119: * Does...
120: * </p>
121: * <p>
122: *
123: * @return a Type with
124: * </p>
125: * <p>
126: * @param
127: * </p>
128: */
129: public Graphics pcmf_getGraphics() {
130: return (this .pem_image.getGraphics());
131: }
132:
133: /**
134: * <p>
135: * Does...
136: * </p>
137: * <p>
138: *
139: * @return a Type with
140: * </p>
141: * <p>
142: * @param
143: * </p>
144: */
145: public void pcmf_commitDrawPane() {
146: try {
147: new File(this .pem_imageName).delete();
148: this .pem_cnt++;
149: this .pemf_buidImageURL();
150: ImageIO.write(this .pem_image, "jpg", new File(
151: this .pem_imageName));
152: this .pcmf_setPropChanged(true);
153: } catch (Exception e) {
154: KeLog.pcmf_log("ug2t",
155: "error writing drawPane image to temp", this ,
156: KeLog.ERROR);
157: }
158: }
159:
160: public Object pcmf_execView() {
161: try {
162: if (this .pem_image == null)
163: this .pcmf_commitDrawPane();
164:
165: if (this .pcmf_isHidden() || this .pcmf_isDisabled())
166: return (((MuGenericApplication) this .pcmf_getAppl())
167: .pcmf_getRenderer().pcmf_wrapMarkup("", this ));
168:
169: return (((MuGenericApplication) this .pcmf_getAppl())
170: .pcmf_getRenderer().pcmf_wrapMarkup(pdm_NodeView
171: .pcmf_output(this ).toString()
172: + pcmf_evChannelandMenuOut(), this ));
173: } catch (Exception e) {
174: KeLog.pcmf_logException("ug2t", this , e);
175: return ("ERROR");
176: }
177: };
178:
179: public void pcmf_setDrawPaneSize(int x, int y) {
180: this .pem_width = x;
181: this .pem_height = y;
182: this .pem_image = new BufferedImage(x, y,
183: BufferedImage.TYPE_INT_RGB);
184: }
185:
186: public int pcmf_getDrawPaneSizeX() {
187: return this .pem_width;
188: }
189:
190: public int pcmf_getDrawPaneSizeY() {
191: return this .pem_height;
192: }
193:
194: public void pcmf_setFixedSize(int w, int h, int type) {
195: this .pcmf_setDrawPaneSize(w, h);
196: super .pcmf_setFixedSize(w, h, type);
197: }
198:
199: public void pcmf_delete() throws Exception {
200: if (this .pdm_deleted == true)
201: return;
202:
203: if (this .pem_image != null)
204: this .pem_image.flush();
205:
206: new File(this .pem_imageName).delete();
207:
208: super .pcmf_delete();
209: };
210:
211: public String pcmf_getImageNameURL() {
212: return (this .pdm_imageNameURL);
213: }
214:
215: // @@
216: }
|