Package net.xoetrope.builder.w3c.html.tags

Source Code of net.xoetrope.builder.w3c.html.tags.P

package net.xoetrope.builder.w3c.html.tags;

import net.xoetrope.builder.w3c.html.XHtmlBuilder;
import net.xoetrope.builder.w3c.html.XHtmlFormLayout;
import java.util.Enumeration;
import javax.swing.text.MutableAttributeSet;
import net.xoetrope.swing.XLabel;
import net.xoetrope.xui.XComponentFactory;

/**
* Processing for the html P element
* <p> Copyright (c) Xoetrope Ltd., 2002-2006</p>
* <p> $Revision: 1.2 $</p>
* <p> License: see License.txt</p>
*/
public class P extends XHtmlTagHandler
{  
  /**
   * Creates a new instance of P
   */
  public P()
  {
  }
 
  /**
   * Create a new instance of this object
   * @param builder the html builder and processor for the document
   * @param parent the parent handler
   * @return the new handler
   */
  public XHtmlTagHandler newInstance( XHtmlBuilder builder, XHtmlTagHandler parent )
  {
    P i = new P();
    i.setBuilder( builder );
    i.setParent( parent );
    return i;
  }
 
  /**
   * Process the element text
   * @param cf the component factory to use for the creation of individual components
   * @param text the content
   */
  public void processText( XComponentFactory cf, String text )
  {   
    if ( content.length() == 0 ) {
      content = "<html";
//      String alignment = (String)attribSet.getAttribute( HTML.Attribute.ALIGN );
//      if ( alignment != null )
//        content += " align=\"" + alignment + "\"";
      content += ">";
    }
       
    content += text;
  }
 
  /**
   * Process the opening html P tag/element
   * @param builder the xui builder instance that is processing the html file
   * @param cf the component factory to use for the creation of individual components
   * @param as the attributes of this html tag.
   */
  public void startProcessing( XHtmlBuilder builder, XComponentFactory cf, MutableAttributeSet as )
  {
    super.startProcessing( builder, cf, as );

    comp = new XLabel();
    parentComponent.add( comp );
    comp.setLayout( new XHtmlFormLayout( builder ));
    cf.setParentComponent( comp );
  }
   
  /**
   * The closing tag has been parsed and now the element can calulate its complete setup
   * should it be dependant on its children for any information. In the case of a table,
   * the table determines the row and column count from the child elements and
   * cannot calculate its layout till all the children have been initially processed.
   * @param cf the component factory to use for the creation of individual components
   */
  public void endProcessing( XComponentFactory cf )
  {
    super.endProcessing( cf );
    ((XLabel)comp).setText( content + "</html>" );
       
    Enumeration attribNames = attribSet.getAttributeNames();
    while ( attribNames.hasMoreElements()) {
      Object key = attribNames.nextElement();
      String attribName = key.toString();
      Object attribValue = attribSet.getAttribute( key );
     
      if ( attribValue != null ) {       
        if ( attribName.equals( "align" )) {
          ((XLabel)comp).setHorizontalAlignment( builder.getSwingConstant( attribValue.toString()));
        }
        else
          processCommonAttributes( attribName, attribValue );
      }
    }
   
    // Reset the parent component to its state prior to this call
    cf.setParentComponent( parentComponent );
  }
}
TOP

Related Classes of net.xoetrope.builder.w3c.html.tags.P

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.