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

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

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

import net.xoetrope.builder.w3c.html.XHtmlBuilder;
import java.util.Enumeration;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
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 Div extends XHtmlTagHandler
  protected String style, startStyle, endStyle;   
  protected HTML.Tag tag;
 
  /**
   * Creates a new instance of Div
   * @param t the actual tag being handler
   */
  public Div( HTML.Tag t )
  {
    tag = t;
    style = startStyle = endStyle = "";
  }
 
  /**
   * 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 )
  {
    Div i = new Div( tag );
    i.setParent( parent );
    i.setBuilder( builder );
    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 FlowLayout());
    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( "style" ))
          style = attribValue.toString().toLowerCase();
        else
          processCommonAttributes( attribName, attribValue );
      }
    }
   
    if ( style.length() > 0 ) {
      if ( style.indexOf( "italic" ) > 0 ) {
        startStyle += "<i>";
        endStyle += "</i>";
      }
      if ( style.indexOf( "bold" ) > 0 ) {
        startStyle += "<b>";
        endStyle += "</b>";
      }
      if ( style.indexOf( "underline" ) > 0 ) {
        startStyle += "<u>";
        endStyle += "</u>";
      }
    }
   
    ((XLabel)comp).setText( startStyle + content + endStyle );
   
    // Reset the parent component to its state prior to this call
    cf.setParentComponent( parentComponent );
  }
 
  /**
   * Does this tag break the flow?
   * @return true if the flow is broken, otherwsie false
   */
  public boolean breaksFlow()
  {
    return tag.breaksFlow();
  }
}
TOP

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

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.