001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.render.web;
029:
030: import java.util.HashMap;
031: import java.util.Map;
032:
033: import thinwire.ui.Component;
034: import thinwire.ui.Frame;
035: import thinwire.ui.Menu;
036: import thinwire.ui.Window;
037: import thinwire.ui.event.PropertyChangeEvent;
038:
039: /**
040: * @author Joshua J. Gertzen
041: */
042: class WindowRenderer extends ContainerRenderer {
043: private static final String SET_TITLE = "setTitle";
044: private static final String SET_MENU = "setMenu";
045:
046: private Map<Component, Integer> compToId;
047: private MenuRenderer mr;
048: WebApplication ai;
049:
050: void render(WindowRenderer wr, Component c,
051: ComponentRenderer container) {
052: setPropertyChangeIgnored(Component.PROPERTY_VISIBLE, true);
053: Window w = (Window) c;
054: addInitProperty(Window.PROPERTY_TITLE, w instanceof Frame ? w
055: .getTitle() : parseRichText(w.getTitle()));
056: if (compToId == null)
057: compToId = new HashMap<Component, Integer>(w.getChildren()
058: .size());
059: super .render(wr, c, container);
060: Menu m = w.getMenu();
061:
062: if (m != null) {
063: if (mr == null)
064: mr = (MenuRenderer) ai.getRenderer(m);
065: mr.render(wr, m, this );
066: }
067:
068: log.fine("Showing window with id:" + id);
069: }
070:
071: void destroy() {
072: ai.clientSideMethodCall(id, DESTROY);
073: if (mr != null)
074: mr.destroy();
075: super .destroy();
076: mr = null;
077: ai = null;
078: compToId.clear();
079: compToId = null;
080: }
081:
082: Integer getComponentId(Component comp) {
083: return compToId.get(comp);
084: }
085:
086: Integer addComponentId(Component comp) {
087: Integer id = compToId.get(comp);
088:
089: if (id == null) {
090: id = ai.getNextComponentId();
091: compToId.put(comp, id);
092: }
093:
094: return id;
095: }
096:
097: Integer removeComponentId(Component comp) {
098: return compToId.remove(comp);
099: }
100:
101: public void propertyChange(PropertyChangeEvent pce) {
102: String name = pce.getPropertyName();
103: if (isPropertyChangeIgnored(name))
104: return;
105: super .propertyChange(pce);
106: Object newValue = pce.getNewValue();
107:
108: if (name.equals(Window.PROPERTY_TITLE)) {
109: postClientEvent(SET_TITLE, newValue);
110: } else if (name.equals(Window.PROPERTY_MENU)) {
111: if (mr != null)
112: mr.destroy();
113:
114: if (newValue == null) {
115: mr = null;
116: postClientEvent(SET_MENU, newValue);
117: } else {
118: Menu m = (Menu) newValue;
119: (mr = (MenuRenderer) ai.getRenderer(m)).render(wr, m,
120: this);
121: }
122: }
123: }
124: }
|