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 HtmlContextMenuRenderer implements IKeView {
043: private KeStringTemplate pem_menuv = null;
044: private KeStringTemplate pem_menud = null;
045: private KeStringTemplate pem_menu = null;
046: private KeStringTemplate pem_ifont = null;
047: private KeStringTemplate pem_sep = null;
048: private KeStringTemplate pem_sm = null;
049: private KeStringTemplate pem_sme = null;
050: private KeStringTemplate pem_key = null;
051:
052: private MuGenericApplication pem_appl = null;
053:
054: private StringBuffer pem_keys = null;
055:
056: public void pcmf_reset() {
057: this .pem_appl = null;
058: };
059:
060: public boolean pcmf_supportsCaching() {
061: return (true);
062: }
063:
064: public void pcmf_clearCache() {
065: this .pem_cache.pcmf_clearCache();
066: }
067:
068: public void pcmf_activateCache(boolean xAc) {
069: this .pem_cache.pcmf_activateThisCache(xAc);
070: return;
071: }
072:
073: private String pcmf_insertFont(String xName, UnFontDescriptor xFont) {
074: KeStringTemplate l_ret = new KeStringTemplate(pem_ifont);
075: l_ret = KeTools.pcmf_stringSubst(l_ret, "$XNAME", xName);
076:
077: UnFontDescriptor l_font = xFont;
078:
079: if (l_font == null)
080: l_font = this .pem_appl.pcmf_getFont();
081:
082: if (l_font == null) {
083: return (xName);
084: } else {
085: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FONT",
086: this .pem_appl.pcmf_getTemplateKit().getFONT());
087:
088: l_ret.pcmf_beginTR();
089:
090: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FNAME", l_font
091: .pcmf_getFontName());
092: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSIZE", Integer
093: .toString(l_font.pcmf_getFontSize()));
094:
095: switch (l_font.pcmf_getFontStyle()) {
096: case Font.ITALIC:
097: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
098: "italic");
099: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
100: "normal");
101: break;
102: case Font.BOLD:
103: l_ret = KeTools
104: .pcmf_stringSubst(l_ret, "$BOLD", "bold");
105: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
106: "normal");
107: break;
108: default:
109: l_ret = KeTools.pcmf_stringSubst(l_ret, "$BOLD",
110: "normal");
111: l_ret = KeTools.pcmf_stringSubst(l_ret, "$FSTYLE",
112: "normal");
113: }
114:
115: l_ret.pcmf_endTR(true);
116: }
117: return (l_ret.toString());
118: }
119:
120: public KeStringTemplate pcmf_addMenus(KeTreeNode xTreeEl,
121: int depth, IUnContextMenu xMenu) {
122: Iterator l_it = xTreeEl.pcmf_getSubIterator();
123: KeStringTemplate l_res = new KeStringTemplate("");
124:
125: if (xTreeEl.pcmf_getChildCount() == 0)
126: return (l_res);
127:
128: while (l_it.hasNext())
129: l_res.pcmf_stringAddEnd(pcmf_addItem((KeTreeElement) l_it
130: .next(), depth, xMenu));
131:
132: KeTreeNode l_parent = null;
133: if (depth == 0)
134: l_parent = xTreeEl.pcmf_getParentNode();
135: else
136: l_parent = xTreeEl;
137:
138: KeStringTemplate l_string = KeTools.pcmf_stringSubst(
139: new KeStringTemplate(pem_menu), "$MENUTREE", l_res);
140: l_string = KeTools.pcmf_stringSubst(l_string, "$ID", "CTX"
141: + l_parent.pcmf_getObjName());
142:
143: l_it = xTreeEl.pcmf_getSubIterator();
144: l_res = l_string;
145: while (l_it.hasNext())
146: l_res.pcmf_stringAddEnd(pcmf_addMenus((KeTreeNode) l_it
147: .next(), ++depth, xMenu));
148:
149: return (l_res);
150: };
151:
152: public KeStringTemplate pcmf_addItem(KeTreeElement xTreeEl,
153: int depth, IUnContextMenu xMenu) {
154: KeStringTemplate l_string = null;
155:
156: String l_stringName = xTreeEl.pcmf_getValue() == null ? ""
157: : xTreeEl.pcmf_getValue().toString();
158:
159: if (l_stringName.equals("--") || l_stringName.equals("|"))
160: l_string = new KeStringTemplate(this .pem_sep);
161: else {
162: if (xTreeEl.pcmf_isDisabled())
163: l_string = new KeStringTemplate(this .pem_menud);
164: else
165: l_string = new KeStringTemplate(this .pem_menuv);
166:
167: l_string = KeTools.pcmf_stringSubst(l_string, "$CLICKED",
168: xTreeEl.pcmf_getObjName());
169: l_string = KeTools.pcmf_stringSubst(l_string, "$SUBID",
170: "CTX" + xTreeEl.pcmf_getObjName());
171:
172: IKeView l_view = xTreeEl.pcmf_getView();
173: if (l_view instanceof UnIconValueView) {
174: UnIconValueView l_iv = ((UnIconValueView) l_view);
175: l_stringName = this .pcmf_insertFont(l_stringName, l_iv
176: .pcmf_getFontDesc());
177: if (l_iv.pcmf_getFg() != null)
178: l_string = KeTools.pcmf_stringSubst(l_string,
179: "$ICOL", l_iv.pcmf_getFg());
180: else
181: l_string = KeTools.pcmf_stringSubst(l_string,
182: "$ICOL", xMenu.pcmf_getFgColor());
183: } else {
184: l_stringName = this .pcmf_insertFont(l_stringName, null);
185: l_string = KeTools.pcmf_stringSubst(l_string, "$ICOL",
186: xMenu.pcmf_getFgColor());
187: }
188:
189: if (xTreeEl.pcmf_getView() != null
190: && ((UnIconValueView) l_view).pcmf_getStdIcon() != null) {
191: StringBuffer l_buf = new StringBuffer();
192: l_buf.append(xTreeEl.pcmf_getView().pcmf_execView(
193: xTreeEl).toString());
194: l_buf.append(" ");
195: if (xTreeEl.pcmf_isDisabled()) {
196: l_buf.append("<i>");
197: l_buf.append(l_stringName);
198: l_buf.append("</i>");
199: } else
200: l_buf.append(l_stringName);
201:
202: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
203: l_buf.toString());
204: } else if (xTreeEl.pcmf_getValue() instanceof MuGenericComponent
205: && !(xTreeEl instanceof MuGenericContextMenu))
206: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
207: (String) ((MuGenericComponent) xTreeEl
208: .pcmf_getValue()).pcmf_execView());
209:
210: l_string = KeTools.pcmf_stringSubst(l_string, "$VALUE",
211: (xTreeEl.pcmf_isDisabled() ? "<i>" + l_stringName
212: + "</i>" : l_stringName));
213:
214: if (xTreeEl instanceof UnMenuFunction) {
215: int l_key = ((UnMenuFunction) xTreeEl).pcmf_getAccKey();
216: if (l_key != ' ') {
217: KeStringTemplate l_keyTpl = new KeStringTemplate(
218: this .pem_key);
219: l_keyTpl = IUnKeyAccess.UnInsertHTMLString
220: .pcmf_insert(((UnMenuFunction) xTreeEl),
221: l_keyTpl);
222: l_keyTpl.pcmf_stringSubst("$CLICKED", xTreeEl
223: .pcmf_getObjName());
224: this .pem_keys.append(l_keyTpl.toString());
225: l_string.pcmf_stringSubst("$SC", "ALT+"
226: + Character.toString((char) l_key));
227: } else
228: l_string.pcmf_stringSubst("$SC", "");
229: } else
230: l_string.pcmf_stringSubst("$SC", "");
231:
232: if (xTreeEl instanceof KeTreeNode
233: && ((KeTreeNode) xTreeEl).pcmf_getChildCount() > 0)
234: l_string = KeTools.pcmf_stringSubst(l_string, "$SM",
235: this .pem_sm);
236: else
237: l_string = KeTools.pcmf_stringSubst(l_string, "$SM",
238: this .pem_sme);
239:
240: l_string = KeTools.pcmf_stringSubst(l_string, "$DEPTH",
241: Integer.toString(depth + 1));
242:
243: if (xTreeEl.pcmf_isDisabled())
244: l_string = KeTools.pcmf_stringSubst(l_string,
245: "$DISABLED", "disabled");
246: else
247: l_string = KeTools.pcmf_stringSubst(l_string,
248: "$DISABLED", "");
249: }
250:
251: return (l_string);
252: };
253:
254: private MuGenericCache pem_cache = new MuGenericCache();
255:
256: public Object pcmf_output(KeTreeElement xTreeEl) {
257: MuGenericContextMenu l_menu = (MuGenericContextMenu) xTreeEl;
258: pem_appl = (MuGenericApplication) l_menu.pcmf_getAppl();
259: this .pem_keys = new StringBuffer();
260:
261: // @@
262:
263: pem_menu = l_menu.pcmf_getMarkupString("MAIN");
264: pem_menuv = l_menu.pcmf_getMarkupString("MENUOBJV");
265: pem_menud = l_menu.pcmf_getMarkupString("MENUOBJD");
266: pem_ifont = l_menu.pcmf_getMarkupString("IFONT");
267: pem_sep = l_menu.pcmf_getMarkupString("SEP");
268: pem_sm = l_menu.pcmf_getMarkupString("SM");
269: pem_sme = l_menu.pcmf_getMarkupString("SME");
270: pem_key = l_menu.pcmf_getMarkupString("KEYACC");
271:
272: KeStringTemplate l_retval = this .pcmf_addMenus(l_menu
273: .pcmf_getRoot(), 0, l_menu);
274:
275: l_retval.pcmf_beginTR();
276:
277: l_retval = KeTools.pcmf_stringSubst(l_retval, "$URL", pem_appl
278: .pcmf_getHostName()
279: + ":"
280: + Integer.toString(pem_appl.pcmf_getPort())
281: + "/"
282: + pem_appl.pcmf_getRootUrl());
283: l_retval = KeTools.pcmf_stringSubst(l_retval, "$OID",
284: ((MuGenericComponent) xTreeEl).pcmf_getObjName());
285: l_retval = KeTools.pcmf_stringSubst(l_retval, "$NAME", l_menu
286: .pcmf_getObjName());
287: l_retval = KeTools.pcmf_stringSubst(l_retval, "$FGCOL", l_menu
288: .pcmf_getFgColor());
289: l_retval = KeTools.pcmf_stringSubst(l_retval, "$BGCOL", l_menu
290: .pcmf_getBgColor());
291: l_retval = KeTools.pcmf_stringSubst(l_retval, "$KEYS",
292: this .pem_keys.toString());
293:
294: l_retval.pcmf_endTR(true);
295:
296: String l_return = l_retval.toString();
297:
298: // @@
299:
300: return (l_return);
301: };
302:
303: public Object pcmf_execView(KeTreeElement xTreeEl) {
304: return (xTreeEl.pcmf_execView());
305: };
306: };
|