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.html.renderer;
032:
033: import java.awt.*;
034: import java.util.*;
035:
036: import de.ug2t.channel.markup.generic.*;
037: import de.ug2t.kernel.*;
038: import de.ug2t.unifiedGui.*;
039: import de.ug2t.unifiedGui.views.*;
040:
041: public final class HtmlJsMenuRenderer implements IKeView {
042: private KeStringTemplate pem_menuv = null;
043: private KeStringTemplate pem_menuh = null;
044: private KeStringTemplate pem_item = null;
045: private KeStringTemplate pem_nmenu = null;
046: private KeStringTemplate pem_sep = null;
047: private KeStringTemplate pem_ifont = null;
048: private int pem_mCnt = 0;
049:
050: private int pem_width = 25;
051:
052: private MuGenericApplication pem_appl = null;
053:
054: public void pcmf_activateCache(boolean xAc) {
055: this .pem_cache.pcmf_activateThisCache(xAc);
056: return;
057: }
058:
059: public KeStringTemplate pcmf_addMenu(KeTreeNode xTreeEl, int xMCnt) {
060: this .pem_mCnt++;
061: Iterator l_it = null;
062: KeTreeNode l_sub = null;
063: int l_iCnt = 1;
064: KeStringTemplate l_string = null;
065: int l_deep = this .pem_mCnt;
066:
067: if (xMCnt == 0) {
068: l_string = new KeStringTemplate(this .pem_nmenu);
069: l_string.pcmf_stringAddEnd(this .pem_menuh);
070: } else {
071: l_string = new KeStringTemplate(this .pem_nmenu);
072: l_string.pcmf_stringAddEnd(this .pem_menuv);
073: }
074:
075: l_string = KeTools.pcmf_stringSubst(l_string, "$X", Integer
076: .toString(this .pem_mCnt));
077: l_it = xTreeEl.pcmf_getSubIterator();
078: int l_mlen = 80;
079: int l_alen = 0;
080: int l_fw = 0;
081:
082: while (l_it.hasNext()) {
083: l_fw = 5;
084: l_sub = (KeTreeNode) l_it.next();
085:
086: IKeView l_view = l_sub.pcmf_getView();
087: if (l_view instanceof UnIconValueView) {
088: UnFontDescriptor l_font = ((UnIconValueView) l_view)
089: .pcmf_getFontDesc();
090: if (l_font == null)
091: l_font = this .pem_appl.pcmf_getFont();
092:
093: if (l_font != null)
094: l_fw = l_font.pcmf_getFontSize() >> 1;
095: }
096:
097: l_alen = l_sub.pcmf_getValue().toString().length() * l_fw
098: + 30;
099: if (l_alen > l_mlen)
100: l_mlen = l_alen;
101: }
102: ;
103: l_string = KeTools.pcmf_stringSubst(l_string, "$MWIDTH",
104: Integer.toString(l_mlen));
105:
106: l_it = xTreeEl.pcmf_getSubIterator();
107: while (l_it.hasNext()) {
108: l_sub = (KeTreeNode) l_it.next();
109: if (l_sub.pcmf_getChildCount() > 0) {
110: l_string.pcmf_stringAddEnd(this .pcmf_addItem(l_sub,
111: l_iCnt++, l_deep, true));
112: l_string.pcmf_stringAddEnd(this .pcmf_addMenu(l_sub,
113: xMCnt + 1));
114: } else
115: l_string.pcmf_stringAddEnd(this .pcmf_addItem(l_sub,
116: l_iCnt++, l_deep, false));
117:
118: xMCnt++;
119: }
120:
121: return (l_string);
122: };
123:
124: private String pcmf_insertFont(String xName,
125: UnFontDescriptor xFont, KeTreeElement xNode) {
126: KeStringTemplate l_ret = new KeStringTemplate(pem_ifont);
127: l_ret = KeTools.pcmf_stringSubst(l_ret, "$XNAME", xName);
128:
129: UnFontDescriptor l_font = xFont;
130:
131: if (l_font == null)
132: l_font = this .pem_appl.pcmf_getFont();
133:
134: if (l_font == null) {
135: return (xName);
136: } else {
137: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FONT", pem_appl
138: .pcmf_getTemplateKit().getFONT());
139:
140: l_ret.pcmf_beginTR();
141:
142: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FNAME", l_font
143: .pcmf_getFontName());
144: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSIZE", Integer
145: .toString(l_font.pcmf_getFontSize()));
146:
147: if (xNode.pcmf_isDisabled()) {
148: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
149: "italic");
150: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
151: "normal");
152: } else
153: switch (l_font.pcmf_getFontStyle()) {
154: case Font.ITALIC:
155: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
156: "italic");
157: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
158: "normal");
159: break;
160: case Font.BOLD:
161: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
162: "bold");
163: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
164: "normal");
165: break;
166: default:
167: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
168: "normal");
169: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
170: "normal");
171: }
172:
173: l_ret.pcmf_endTR(true);
174: }
175: return l_ret.toString();
176: }
177:
178: public KeStringTemplate pcmf_addItem(KeTreeElement xTreeEl,
179: int xICnt, int xDeep, boolean isMenu) {
180: KeStringTemplate l_string = new KeStringTemplate(this .pem_item);
181:
182: l_string.pcmf_beginTR();
183:
184: l_string = KeTools.pcmf_stringSubst(l_string, "$X", Integer
185: .toString(xDeep));
186: l_string = KeTools.pcmf_stringSubst(l_string, "$Y", Integer
187: .toString(xICnt));
188: l_string = KeTools.pcmf_stringSubst(l_string, "$CLICKED",
189: xTreeEl.pcmf_getObjName());
190: l_string = KeTools.pcmf_stringSubst(l_string, "$SUB",
191: isMenu ? Integer.toString(this .pem_mCnt + 1) : "0");
192: l_string = KeTools.pcmf_stringSubst(l_string, "$WIDTH",
193: xDeep == 0 ? Integer.toString(this .pem_width) : "0");
194:
195: l_string.pcmf_endTR(true);
196:
197: if (isMenu && xDeep != 0)
198: l_string = KeTools
199: .pcmf_stringSubstAppend(l_string, "$VALUE",
200: "$VALUE", " <b>></b>");
201:
202: String l_stringName = xTreeEl.pcmf_getValue() == null ? ""
203: : xTreeEl.pcmf_getValue().toString();
204: if (xTreeEl.pcmf_getView() != null) {
205: IKeView l_view = xTreeEl.pcmf_getView();
206: if (l_view instanceof UnIconValueView) {
207: l_stringName = this .pcmf_insertFont(l_stringName,
208: ((UnIconValueView) l_view).pcmf_getFontDesc(),
209: xTreeEl);
210: if (((UnIconValueView) l_view).pcmf_getStdIcon() != null) {
211: StringBuffer l_buf = new StringBuffer();
212: l_buf.append(xTreeEl.pcmf_getView().pcmf_execView(
213: xTreeEl).toString());
214: l_buf.append(" ");
215: if (xTreeEl.pcmf_isDisabled()) {
216: l_buf.append("<i>");
217: l_buf.append(l_stringName);
218: l_buf.append("</i>");
219: } else
220: l_buf.append(l_stringName);
221:
222: l_string = KeTools.pcmf_stringSubst(l_string,
223: "$VALUE", l_buf.toString());
224: } else
225: l_string = KeTools.pcmf_stringSubst(l_string,
226: "$VALUE",
227: (xTreeEl.pcmf_isDisabled() ? "<i>"
228: + l_stringName + "</i>"
229: : l_stringName));
230: }
231: } else if (xTreeEl.pcmf_getValue() instanceof MuGenericComponent
232: && !(xTreeEl instanceof MuGenericMenu))
233: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
234: (String) ((MuGenericComponent) xTreeEl
235: .pcmf_getValue()).pcmf_execView());
236: else if (l_stringName.equals("--") || l_stringName.equals("|"))
237: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
238: this .pem_sep);
239: else
240: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
241: (xTreeEl.pcmf_isDisabled() ? "<i>" + l_stringName
242: + "</i>" : l_stringName));
243:
244: return (l_string);
245: };
246:
247: private MuGenericCache pem_cache = new MuGenericCache();
248:
249: public Object pcmf_output(KeTreeElement xTreeEl) {
250: MuGenericMenu html_xTreeEl = (MuGenericMenu) xTreeEl;
251:
252: // @@
253:
254: this .pem_mCnt = -1;
255:
256: // @@
257:
258: pem_appl = (MuGenericApplication) html_xTreeEl.pcmf_getAppl();
259:
260: KeStringTemplate l_string = html_xTreeEl
261: .pcmf_getMarkupString("MAIN");
262:
263: pem_menuh = html_xTreeEl.pcmf_getMarkupString("MENUOBJH");
264: pem_menuv = html_xTreeEl.pcmf_getMarkupString("MENUOBJV");
265: pem_item = html_xTreeEl.pcmf_getMarkupString("MENUITEM");
266: pem_nmenu = html_xTreeEl.pcmf_getMarkupString("NEWMENU");
267: pem_sep = html_xTreeEl.pcmf_getMarkupString("SEP");
268: pem_ifont = html_xTreeEl.pcmf_getMarkupString("IFONT");
269:
270: KeStringTemplate l_retval = this .pcmf_addMenu(html_xTreeEl
271: .pcmf_getRoot(), 0);
272:
273: l_string.pcmf_beginTR();
274:
275: l_string = KeTools.pcmf_stringSubst(l_string, "$MENUTREE",
276: l_retval);
277: l_string = KeTools.pcmf_stringSubst(l_string, "$URL", pem_appl
278: .pcmf_getHostName()
279: + ":"
280: + Integer.toString(pem_appl.pcmf_getPort())
281: + "/"
282: + pem_appl.pcmf_getRootUrl());
283: l_string = KeTools.pcmf_stringSubst(l_string, "$NAME",
284: html_xTreeEl.pcmf_getObjName());
285: l_string = KeTools.pcmf_stringSubst(l_string, "$OID",
286: html_xTreeEl.pcmf_getObjName());
287: l_string = KeTools.pcmf_stringSubst(l_string, "$FGCOL",
288: html_xTreeEl.pcmf_getFgColor());
289:
290: l_string = KeTools.pcmf_stringSubst(l_string, "$BGCOL",
291: html_xTreeEl.pcmf_getBgColor());
292:
293: l_string.pcmf_endTR(true);
294:
295: // @@
296:
297: return (l_string);
298: };
299:
300: public Object pcmf_execView(KeTreeElement xTreeEl) {
301: return (xTreeEl.pcmf_execView());
302: };
303:
304: public void pcmf_setMenuWidth(int xWi) {
305: this .pem_width = xWi;
306: }
307:
308: public boolean pcmf_supportsCaching() {
309: return (true);
310: }
311:
312: public void pcmf_clearCache() {
313: this.pem_cache.pcmf_clearCache();
314: }
315: };
|