001: package net.xoetrope.builder.editor.components;
002:
003: import java.util.Vector;
004:
005: import java.awt.Component;
006:
007: import net.xoetrope.builder.editor.XComponentSizer;
008: import net.xoetrope.xui.XPage;
009: import net.xoetrope.builder.editor.components.swing.XComponentProxy;
010:
011: /**
012: * <p>Copyright (c) Xoetrope Ltd., 2002-2003</p>
013: * <p>$Revision: 1.10 $</p>
014: */
015: public class ComponentHelper {
016: private static ComponentHelper componentHelper;
017:
018: protected static Vector componentHelpers;
019: protected static XUnknownHelper unknownHelper;
020: protected static MultipleSelectionHelper multipleSelectionHelper;
021:
022: public ComponentHelper() {
023: if (componentHelpers == null) {
024: componentHelpers = new Vector();
025: unknownHelper = new XUnknownHelper();
026: multipleSelectionHelper = new MultipleSelectionHelper();
027: }
028: }
029:
030: public static ComponentHelper getComponentHelpers() {
031: if (componentHelper == null)
032: componentHelper = new ComponentHelper();
033:
034: return componentHelper;
035: }
036:
037: /**
038: * Get the property helper for a component
039: * @return the helper
040: */
041: public static PropertyHelper getPropertyHelper(Object comp) {
042: if (comp != null) {
043: if (comp instanceof XComponentSizer)
044: return null;
045:
046: String targetClass;
047: if (comp instanceof XPage)
048: targetClass = XPage.class.toString();
049: else if (comp instanceof XComponentProxy)
050: targetClass = ((XComponentProxy) comp)
051: .getProxiedComponent().getClass().toString();
052: else
053: targetClass = comp.getClass().toString();
054:
055: int numTypes = componentHelpers.size();
056: for (int i = 0; i < numTypes; i++) {
057: PropertyHelper propHelper = (PropertyHelper) componentHelpers
058: .elementAt(i);
059: if (propHelper.getClassName().equals(targetClass))
060: return propHelper;
061: }
062:
063: // If the component is an AWT component then it will try to find the swing
064: // equivalent
065: if (targetClass.indexOf(".awt.") > 0) {
066: targetClass.replaceFirst(".awt.", ".swing.");
067: for (int i = 0; i < numTypes; i++) {
068: PropertyHelper propHelper = (PropertyHelper) componentHelpers
069: .elementAt(i);
070: if (propHelper.getClassName().equals(targetClass)) {
071: propHelper.setSwing(false);
072: return propHelper;
073: }
074: }
075: }
076: } else
077: return null;
078:
079: if (comp instanceof Vector)
080: return multipleSelectionHelper;
081:
082: unknownHelper.setComponent((Component) comp);
083: return unknownHelper;
084: }
085:
086: public void addComponentType(PropertyHelper propHelper) {
087: componentHelpers.add(propHelper);
088: }
089:
090: public void addComponentType(PropertyHelper propHelper,
091: boolean isSwing) {
092: if (!isSwing) {
093: if (propHelper.className == null)
094: propHelper.className = propHelper.getClassName();
095: propHelper.className.replaceFirst(".swing.", ".awt.");
096: }
097:
098: propHelper.setSwing(isSwing);
099: componentHelpers.add(propHelper);
100: }
101: }
|