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.interfaces.*;
040: import de.ug2t.unifiedGui.views.*;
041:
042: public final class HtmlMenuRenderer implements IKeView {
043: private MuGenericCache pem_cache = new MuGenericCache();
044:
045: private KeStringTemplate pem_mainTpl = null;
046: private KeStringTemplate pem_lineTpl = null;
047: private KeStringTemplate pem_menuTpl = null;
048: private KeStringTemplate pem_itemTpl = null;
049: private KeStringTemplate pem_itemdTpl = null;
050: private KeStringTemplate pem_aligntopTpl = null;
051: private KeStringTemplate pem_alignsubTpl = null;
052: private KeStringTemplate pem_handlesubTpl = null;
053: private KeStringTemplate pem_ifont = null;
054: private KeStringTemplate pem_sepTpl = null;
055: private KeStringTemplate pem_smTpl = null;
056: private KeStringTemplate pem_smeTpl = null;
057: private KeStringTemplate pem_keyTpl = null;
058: private IUnMenu pem_menu = null;
059: private MuGenericApplication pem_appl = null;
060: private StringBuffer pem_keys = null;
061:
062: public void pcmf_clearCache() {
063: this .pem_cache.pcmf_clearCache();
064: }
065:
066: public boolean pcmf_supportsCaching() {
067: return (true);
068: }
069:
070: public void pcmf_reset() {
071: pem_mainTpl = null;
072: pem_lineTpl = null;
073: pem_menuTpl = null;
074: pem_itemTpl = null;
075: pem_itemdTpl = null;
076: pem_aligntopTpl = null;
077: pem_alignsubTpl = null;
078: pem_handlesubTpl = null;
079: pem_ifont = null;
080: pem_menu = null;
081: pem_appl = null;
082: }
083:
084: private String pcmf_insertFont(String xName, UnFontDescriptor xFont) {
085: KeStringTemplate l_ret = new KeStringTemplate(pem_ifont);
086: l_ret = KeTools.pcmf_stringSubst(l_ret, "$XNAME", xName);
087:
088: UnFontDescriptor l_font = xFont;
089:
090: if (l_font == null)
091: l_font = this .pem_appl.pcmf_getFont();
092:
093: if (l_font == null) {
094: return (xName);
095: } else {
096: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FONT",
097: this .pem_appl.pcmf_getTemplateKit().getFONT());
098:
099: l_ret.pcmf_beginTR();
100:
101: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FNAME", l_font
102: .pcmf_getFontName());
103: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSIZE", Integer
104: .toString(l_font.pcmf_getFontSize()));
105:
106: switch (l_font.pcmf_getFontStyle()) {
107: case Font.ITALIC:
108: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
109: "italic");
110: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
111: "normal");
112: break;
113: case Font.BOLD:
114: l_ret = KeTools
115: .pcmf_stringSubst(l_ret, "$BOLD", "bold");
116: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
117: "normal");
118: break;
119: default:
120: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
121: "normal");
122: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
123: "normal");
124: }
125:
126: l_ret.pcmf_endTR(true);
127: }
128: return (l_ret.toString());
129: }
130:
131: public void pcmf_activateCache(boolean xAc) {
132: this .pem_cache.pcmf_activateThisCache(xAc);
133: return;
134: }
135:
136: public Object pcmf_output(KeTreeElement xTreeEl) {
137: MuGenericMenu html_xTreeEl = (MuGenericMenu) xTreeEl;
138: this .pem_keys = new StringBuffer();
139:
140: // @@
141:
142: this .pem_menu = html_xTreeEl;
143: pem_appl = (MuGenericApplication) html_xTreeEl.pcmf_getAppl();
144:
145: if (pem_mainTpl == null) {
146: pem_mainTpl = html_xTreeEl.pcmf_getMarkupString("MAIN");
147: pem_lineTpl = html_xTreeEl.pcmf_getMarkupString("LINE");
148: pem_menuTpl = html_xTreeEl.pcmf_getMarkupString("MENU");
149: pem_itemTpl = html_xTreeEl.pcmf_getMarkupString("ITEM");
150: pem_itemdTpl = html_xTreeEl.pcmf_getMarkupString("ITEMD");
151: pem_aligntopTpl = html_xTreeEl
152: .pcmf_getMarkupString("ALIGNTOP");
153: pem_alignsubTpl = html_xTreeEl
154: .pcmf_getMarkupString("ALIGNSUB");
155: pem_handlesubTpl = html_xTreeEl
156: .pcmf_getMarkupString("HANDLESUB");
157: pem_sepTpl = html_xTreeEl.pcmf_getMarkupString("SEP");
158: pem_smTpl = html_xTreeEl.pcmf_getMarkupString("SM");
159: pem_smeTpl = html_xTreeEl.pcmf_getMarkupString("SME");
160: pem_keyTpl = html_xTreeEl.pcmf_getMarkupString("KEYACC");
161: pem_ifont = html_xTreeEl.pcmf_getMarkupString("IFONT");
162: }
163:
164: KeStringTemplate l_string = this
165: .pcmf_createTopMenu(html_xTreeEl);
166:
167: l_string = html_xTreeEl.pcmf_insertToolTip(l_string);
168: l_string = html_xTreeEl
169: .pcmf_insertColorandFontandBorder(l_string);
170: l_string = html_xTreeEl.pcmf_insertPosition(l_string);
171: l_string = html_xTreeEl.pcmf_insertChannelandMenu(l_string);
172: l_string = l_string.pcmf_stringdirectSingleSubst("$KEYS",
173: this .pem_keys.toString());
174:
175: // @@
176:
177: return (l_string);
178: };
179:
180: private KeStringTemplate pcmf_createMenuItem(KeTreeNode xNode) {
181: KeStringTemplate l_string = null;
182:
183: String l_stringName = xNode.pcmf_getValue() == null ? ""
184: : xNode.pcmf_getValue().toString();
185:
186: if (l_stringName.equals("--") || l_stringName.equals("|"))
187: l_string = new KeStringTemplate(this .pem_sepTpl);
188: else {
189: if (xNode.pcmf_isDisabled())
190: l_string = new KeStringTemplate(this .pem_itemdTpl);
191: else
192: l_string = new KeStringTemplate(this .pem_itemTpl);
193:
194: if (xNode.pcmf_getChildCount() > 0) {
195: KeStringTemplate l_handleSub = new KeStringTemplate(
196: this .pem_handlesubTpl);
197: l_handleSub.pcmf_stringSubst("$SUBNAME", xNode
198: .pcmf_getObjName());
199:
200: if (xNode.pcmf_isDisabled() == false)
201: l_string.pcmf_stringSubst("$HANDLESUB", l_handleSub
202: .toString());
203: else
204: l_string.pcmf_stringSubst("$HANDLESUB", "");
205:
206: l_string.pcmf_stringSubst("$SUBMENU", this
207: .pcmf_createSubMenu(xNode).toString());
208: l_string = KeTools.pcmf_stringSubst(l_string, "$SM",
209: this .pem_smTpl.toString());
210: } else {
211: l_string.pcmf_stringSubst("$SUBMENU", "");
212: l_string.pcmf_stringSubst("$HANDLESUB", "");
213: l_string = KeTools.pcmf_stringSubst(l_string, "$SM",
214: this .pem_smeTpl.toString());
215: }
216:
217: l_string.pcmf_stringSubst("$SUBNAME", xNode
218: .pcmf_getObjName());
219:
220: IKeView l_view = xNode.pcmf_getView();
221:
222: if (l_view instanceof UnIconValueView) {
223: UnIconValueView l_iv = ((UnIconValueView) l_view);
224: l_stringName = this .pcmf_insertFont(l_stringName, l_iv
225: .pcmf_getFontDesc());
226: if (l_iv.pcmf_getFg() != null)
227: l_string = KeTools.pcmf_stringSubst(l_string,
228: "$FGCOL", l_iv.pcmf_getFg());
229: else
230: l_string = KeTools.pcmf_stringSubst(l_string,
231: "$FGCOL", this .pem_menu
232: .pcmf_getUnComponent()
233: .pcmf_getFgColor());
234: } else {
235: l_stringName = this .pcmf_insertFont(l_stringName, null);
236: l_string = KeTools.pcmf_stringSubst(l_string, "$FGCOL",
237: this .pem_menu.pcmf_getUnComponent()
238: .pcmf_getFgColor());
239: }
240:
241: if (l_view != null
242: && l_view instanceof UnIconValueView
243: && ((UnIconValueView) l_view).pcmf_getStdIcon() != null) {
244: StringBuffer l_buf = new StringBuffer();
245: l_buf.append(xNode.pcmf_getView().pcmf_execView(xNode)
246: .toString());
247: l_buf.append(" ");
248: l_buf.append(l_stringName);
249:
250: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
251: l_buf.toString());
252: } else if (xNode.pcmf_getValue() instanceof MuGenericComponent)
253: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
254: (String) ((MuGenericComponent) xNode
255: .pcmf_getValue()).pcmf_execView());
256: else
257: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
258: l_stringName);
259:
260: l_string = ((MuGenericComponent) this .pem_menu
261: .pcmf_getUnComponent())
262: .pcmf_insertColorandFontandBorder(l_string);
263:
264: l_string.pcmf_beginTR();
265:
266: if (xNode instanceof UnMenuFunction) {
267: int l_key = ((UnMenuFunction) xNode).pcmf_getAccKey();
268: if (l_key != ' ') {
269: KeStringTemplate l_keyTpl = new KeStringTemplate(
270: this .pem_keyTpl);
271: l_keyTpl = IUnKeyAccess.UnInsertHTMLString
272: .pcmf_insert(((UnMenuFunction) xNode),
273: l_keyTpl);
274: l_keyTpl.pcmf_stringSubst("$CLICKED", xNode
275: .pcmf_getObjName());
276: this .pem_keys.append(l_keyTpl.toString());
277: l_string.pcmf_stringSubst("$SC", "ALT+"
278: + Character.toString((char) l_key));
279: } else
280: l_string.pcmf_stringSubst("$SC", "");
281: } else
282: l_string.pcmf_stringSubst("$SC", "");
283:
284: l_string.pcmf_stringSubst("$BGCOL", this .pem_menu
285: .pcmf_getUnComponent().pcmf_getBgColor());
286: l_string.pcmf_stringSubst("$CLICKED", xNode
287: .pcmf_getObjName());
288: l_string.pcmf_stringSubst("$NAME", this .pem_menu
289: .pcmf_getUnComponent().pcmf_getObjName());
290:
291: l_string.pcmf_endTR(true);
292: }
293: return (l_string);
294: }
295:
296: public KeStringTemplate pcmf_createSubMenu(KeTreeNode xNode) {
297: KeStringTemplate l_string = new KeStringTemplate(
298: this .pem_menuTpl);
299: KeStringTemplate l_body = new KeStringTemplate("");
300:
301: Iterator l_it = xNode.pcmf_getSubIterator();
302: while (l_it.hasNext()) {
303: KeTreeNode l_node = (KeTreeNode) l_it.next();
304: l_body.pcmf_stringAddEnd(this .pcmf_createMenuItem(l_node)
305: .toString());
306: }
307:
308: KeTreeNode l_pnode = xNode.pcmf_getParentNode();
309:
310: l_string.pcmf_stringdirectSubst("$MITEMS", l_body);
311:
312: l_string.pcmf_stringSubst("$NAME", xNode.pcmf_getObjName());
313: l_string.pcmf_stringSubst("$FGCOL", this .pem_menu
314: .pcmf_getUnComponent().pcmf_getFgColor());
315: l_string.pcmf_stringSubst("$BGCOL", this .pem_menu
316: .pcmf_getUnComponent().pcmf_getBgColor());
317:
318: if (xNode.pcmf_getChildCount() > 0
319: && l_pnode instanceof IUnMenu == false) {
320: KeStringTemplate l_handleSub = new KeStringTemplate(
321: this .pem_handlesubTpl);
322: l_handleSub.pcmf_stringSubst("$SUBNAME", xNode
323: .pcmf_getObjName());
324:
325: if (xNode.pcmf_isDisabled() == false)
326: l_string.pcmf_stringSubst("$HANDLESUB", l_handleSub
327: .toString());
328: else
329: l_string.pcmf_stringSubst("$HANDLESUB", "");
330: } else {
331: l_string.pcmf_stringSubst("$SUBMENU", "");
332: l_string.pcmf_stringSubst("$HANDLESUB", "");
333: l_string.pcmf_stringdirectSubst("$MITEMS", "");
334: }
335:
336: l_string.pcmf_stringSubst("$SUBNAME", xNode.pcmf_getObjName());
337:
338: if (l_pnode instanceof IUnMenu) {
339: l_string.pcmf_stringdirectSubst("$MALIGN",
340: this .pem_aligntopTpl);
341: l_string.pcmf_stringSubst("$ALIGN", "inline");
342: } else {
343: l_string.pcmf_stringdirectSubst("$MALIGN",
344: this .pem_alignsubTpl);
345: l_string.pcmf_stringSubst("$ALIGN", "block");
346: }
347:
348: return (l_string);
349: }
350:
351: public KeStringTemplate pcmf_createTopMenu(KeTreeNode xNode) {
352: KeStringTemplate l_stringLine = null;
353: KeStringTemplate l_stringMain = new KeStringTemplate(
354: this .pem_mainTpl);
355: KeStringTemplate l_body = new KeStringTemplate("");
356:
357: Iterator l_it = xNode.pcmf_getSubIterator();
358: while (l_it.hasNext()) {
359: l_stringLine = new KeStringTemplate(this .pem_lineTpl);
360: KeTreeNode l_node = (KeTreeNode) l_it.next();
361:
362: l_stringLine = ((MuGenericComponent) this .pem_menu
363: .pcmf_getUnComponent())
364: .pcmf_insertToolTip(l_stringLine);
365: l_stringLine = ((MuGenericComponent) this .pem_menu
366: .pcmf_getUnComponent())
367: .pcmf_insertColorandFontandBorder(l_stringLine);
368:
369: l_stringLine.pcmf_beginTR();
370:
371: String l_stringName = l_node.pcmf_getValue() == null ? ""
372: : l_node.pcmf_getValue().toString();
373:
374: IKeView l_view = l_node.pcmf_getView();
375: if (l_view instanceof UnIconValueView) {
376: UnIconValueView l_iv = ((UnIconValueView) l_view);
377: l_stringName = this .pcmf_insertFont(l_stringName, l_iv
378: .pcmf_getFontDesc());
379: if (l_iv.pcmf_getFg() != null)
380: l_stringLine = KeTools.pcmf_stringSubst(
381: l_stringLine, "$FGCOL", l_iv.pcmf_getFg());
382: else
383: l_stringLine = KeTools.pcmf_stringSubst(
384: l_stringLine, "$FGCOL", this .pem_menu
385: .pcmf_getUnComponent()
386: .pcmf_getFgColor());
387: } else {
388: l_stringName = this .pcmf_insertFont(l_stringName, null);
389: l_stringLine = KeTools.pcmf_stringSubst(l_stringLine,
390: "$FGCOL", this .pem_menu.pcmf_getUnComponent()
391: .pcmf_getFgColor());
392: }
393:
394: if (l_view != null
395: && l_view instanceof UnIconValueView
396: && ((UnIconValueView) l_view).pcmf_getStdIcon() != null) {
397: StringBuffer l_buf = new StringBuffer();
398: l_buf.append(l_node.pcmf_getView()
399: .pcmf_execView(l_node).toString());
400: l_buf.append(" ");
401: l_buf.append(l_stringName);
402:
403: l_stringLine = KeTools.pcmf_stringSubst(l_stringLine,
404: "$VALUE", l_buf.toString());
405: } else if (l_node.pcmf_getValue() instanceof MuGenericComponent)
406: l_stringLine = KeTools.pcmf_stringSubst(l_stringLine,
407: "$VALUE", (String) ((MuGenericComponent) l_node
408: .pcmf_getValue()).pcmf_execView());
409: else if (l_stringName.indexOf("--") != -1)
410: l_stringLine = KeTools.pcmf_stringSubst(l_stringLine,
411: "$VALUE", "|");
412: else
413: l_stringLine = KeTools.pcmf_stringSubst(l_stringLine,
414: "$VALUE", l_stringName);
415:
416: l_stringLine.pcmf_stringSubst("$SUBMENU", this
417: .pcmf_createSubMenu(l_node).toString());
418: l_stringLine.pcmf_stringSubst("$SUBNAME", l_node
419: .pcmf_getObjName());
420: l_stringLine.pcmf_stringSubst("$BGCOL", this .pem_menu
421: .pcmf_getUnComponent().pcmf_getBgColor());
422:
423: l_stringLine.pcmf_endTR(true);
424:
425: l_body.pcmf_stringAddEnd(l_stringLine.toString());
426: }
427:
428: l_stringMain.pcmf_stringSubst("$BODY", l_body.toString());
429: l_stringMain.pcmf_stringdirectSubst("$NAME", xNode
430: .pcmf_getObjName());
431:
432: return (l_stringMain);
433: }
434:
435: public Object pcmf_execView(KeTreeElement xTreeEl) {
436: return (xTreeEl.pcmf_execView());
437: };
438: };
|