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 thinwire.ui.Component;
031: import thinwire.ui.DropDown;
032: import thinwire.ui.event.PropertyChangeEvent;
033:
034: /**
035: * @author Joshua J. Gertzen
036: */
037: final class DropDownRenderer extends MaskEditorComponentRenderer {
038: private static final String DROPDOWN_CLASS = "tw_DropDown";
039: private static final String SET_EDIT_ALLOWED = "setEditAllowed";
040: private static final String SET_COMPONENT = "setComponent";
041: private static final int MIN_SIZE = 25;
042: private ComponentRenderer ddcr;
043:
044: void render(WindowRenderer wr, Component c,
045: ComponentRenderer container) {
046: init(DROPDOWN_CLASS, wr, c, container);
047: DropDown dd = (DropDown) c;
048: addInitProperty(DropDown.PROPERTY_EDIT_ALLOWED, dd
049: .isEditAllowed());
050: super .render(wr, c, container);
051: Component ddc = dd.getComponent();
052: if (ddc.getWidth() == 0 || ddc.getWidth() < dd.getWidth())
053: ddc.setWidth(dd.getView().getOptimalWidth());
054: if (ddc.getHeight() == 0 || ddc.getHeight() < MIN_SIZE)
055: ddc.setHeight(dd.getView().getOptimalHeight());
056: ddc.setVisible(false);
057:
058: //TODO REFRESH Is this ok in a refresh scenario?
059: ddcr = wr.ai.getRenderer(ddc);
060: ddcr.setPropertyChangeIgnored(Component.PROPERTY_FOCUS, true);
061: ddcr.setPropertyChangeIgnored(Component.PROPERTY_ENABLED, true);
062: ddcr.setPropertyChangeIgnored(Component.PROPERTY_X, true);
063: ddcr.setPropertyChangeIgnored(Component.PROPERTY_Y, true);
064: ddcr.render(wr, ddc, this );
065:
066: postClientEvent(SET_COMPONENT, wr.ai.getComponentId(ddc));
067: }
068:
069: void destroy() {
070: super .destroy();
071: ddcr.destroy();
072: ddcr = null;
073: }
074:
075: public void propertyChange(PropertyChangeEvent pce) {
076: String name = pce.getPropertyName();
077: if (isPropertyChangeIgnored(name))
078: return;
079: Object newValue = pce.getNewValue();
080:
081: if (name.equals(DropDown.PROPERTY_EDIT_ALLOWED)) {
082: postClientEvent(SET_EDIT_ALLOWED, newValue);
083: } else if (name.equals(DropDown.PROPERTY_COMPONENT)) {
084: if (ddcr != null)
085: ddcr.destroy();
086: DropDown dd = (DropDown) comp;
087: Component ddc = dd.getComponent();
088: if (ddc.getWidth() == 0 || ddc.getWidth() < dd.getWidth())
089: ddc.setWidth(dd.getView().getOptimalWidth());
090: if (ddc.getHeight() == 0 || ddc.getHeight() < MIN_SIZE)
091: ddc.setHeight(dd.getView().getOptimalHeight());
092: ddc.setVisible(false);
093: ddcr = wr.ai.getRenderer(ddc);
094: ddcr.setPropertyChangeIgnored(Component.PROPERTY_FOCUS,
095: true);
096: ddcr.setPropertyChangeIgnored(Component.PROPERTY_ENABLED,
097: true);
098: ddcr.setPropertyChangeIgnored(Component.PROPERTY_X, true);
099: ddcr.setPropertyChangeIgnored(Component.PROPERTY_Y, true);
100: ddcr.render(wr, ddc, this);
101: postClientEvent(SET_COMPONENT, wr.ai.getComponentId(ddc));
102: } else {
103: super.propertyChange(pce);
104: }
105: }
106: }
|