001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.gui.components;
031:
032: import com.jeta.forms.gui.common.FormUtils;
033: import com.jeta.forms.gui.form.GridComponent;
034: import com.jeta.forms.gui.formmgr.FormManager;
035: import com.jeta.open.registry.JETARegistry;
036:
037: /**
038: * A specialization of ComponentFactory that maintains a reference to a
039: * component source. This is a common requirement of most ComponentFactories.
040: *
041: * @author Jeff Tassin
042: */
043: abstract public class AbstractComponentFactory implements
044: ComponentFactory {
045: /**
046: * The object that is responsible for managing the component factories
047: */
048: private ComponentSource m_compsrc;
049:
050: /**
051: * Default <code>AbstractComponentFactory</code> constructor.
052: */
053: public AbstractComponentFactory() {
054: }
055:
056: /**
057: * Creates an <code>AbstractComponentFactory</code> instance with the
058: * specified ComponentSource.
059: *
060: * @param compsrc
061: * the component source associated with this factory.
062: */
063: public AbstractComponentFactory(ComponentSource compsrc) {
064: FormUtils.safeAssert(compsrc != null);
065: m_compsrc = compsrc;
066: }
067:
068: /**
069: * Returns the component source associated with this factory.
070: *
071: * @return the component source.
072: */
073: public ComponentSource getComponentSource() {
074: return m_compsrc;
075: }
076:
077: /**
078: * Installs event listeners on the specified GridComponent. This is only
079: * used in design mode.
080: *
081: * @param comp
082: * the component to install event listeners on.
083: */
084: public void installHandlers(GridComponent comp) {
085: FormManager fmgr = (FormManager) JETARegistry
086: .lookup(FormManager.COMPONENT_ID);
087: if (fmgr != null) {
088: fmgr.installHandlers(getComponentSource(), comp);
089: }
090: }
091:
092: /**
093: * Sets the component source associated with this factory.
094: *
095: * @param compsrc
096: * the component source to set.
097: */
098: public void setComponentSource(ComponentSource compsrc) {
099: m_compsrc = compsrc;
100: }
101: }
|