Package net.xoetrope.swing

Source Code of net.xoetrope.swing.SwingComponentFactory

package net.xoetrope.swing;

import net.xoetrope.xui.XComponentConstructor;
import net.xoetrope.xui.XComponentFactory;
import java.awt.Component;
import java.util.Hashtable;
import net.xoetrope.registry.ComponentAdapter;
import net.xoetrope.swing.toolbar.XToolbarButton;
import net.xoetrope.xui.XProject;
import net.xoetrope.xui.XTextHolder;


/**
  * @todo put these components into the registry and remove this factory
  */

/**
* A factory for non-base Swing components such as trees, tables and split panes
* <p>Copyright: Copyright (c) Xoetrope Ltd., 2001-2004</p>
* <p>$Revision: 2.7 $ </p>
* License see license.txt
*/
public class SwingComponentFactory implements XComponentConstructor
{
//  private String packageName = "net.xoetrope.swing";
  private XProject currentProject;

  /**
   * Create a new component factory
   * @param project the owner project
   */
  public SwingComponentFactory( XProject project )
  {
  }

  /**
   * A generic factory for adding XComponents. The component is constructed, positioned and
   * added to the parent panel if one exists. The component is named with a counter value
   * to uniquely identify the control.
   * @param cf the calling component factory
   * @param type a name identifying the type of component to be created
   * @param content the component text/content
   * @return the new component
   */
  public Object constructComponent( XComponentFactory cf, String type, String content )
  {
    Component comp = null;
    if ( type.charAt( 0 ) == 'X' )
      type = type.substring( 1, type.length() );

    String lwrCaseType = type.toLowerCase();
    if ( lwrCaseType.equals( "tree" ))
      comp = new XTree();
    else if ( lwrCaseType.equals( "table" ) || lwrCaseType.equals( "table2" ))
      comp = new XTable();
    else if ( lwrCaseType.equals( "splitpane" ))
      comp = new XSplitPane();
    else if ( lwrCaseType.equals( "imagebutton" ))
      comp = new XImageButton();
    else if ( lwrCaseType.equals( "textpane" )) {
      comp = new XTextPane();
      ((XTextHolder)comp).setText( cf.translate( content ));
    }
    else if ( lwrCaseType.equals( "editorpane" )) {
      comp = new XEditorPane();
      ((XTextHolder)comp).setText( cf.translate( content ));
    }
    else if ( lwrCaseType.equals( "toolbarbutton" )) {
      comp = new XToolbarButton();
      ((XToolbarButton)comp).setText( content );
    }

    return comp;
  }

  /**
   * A generic factory method for adding non component elements. The method can
   * be useful in conjunction with the 'repeat' and 'include' keywords where
   * a component may not have a one to one relationship with the XML element.
   * @param cf the calling component factory
   * @param type the object type
   * @param name a name identifying the element to be created
   * @param content the component text/content
   * @param attribs the element attributes if any
   * @return the new component
   */
  public Object addElement( XComponentFactory cf, String type, String name, String content, Hashtable attribs )
  {
    return null;
  }

  /**
   * Notify the component factories that some of their settings may have changed.
   * This factory does not yet use any startup properties or parameters
   */
  public void update() {}

  /**
   * Set the package name for the factory's widgets.
   * @param defPackage the default package name
   */
  public void setPackageName( String defPackage )
  {
//    packageName = defPackage;
  }

  /**
   * Get the component adapter for this type
   * @param type the component type name
   * @return the ComponentAdapter
   */
  public ComponentAdapter getComponentAdapter( String type )
  {
    return null;
  }
}
TOP

Related Classes of net.xoetrope.swing.SwingComponentFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.