Package net.xoetrope.html

Source Code of net.xoetrope.html.XHtmlWidget

package net.xoetrope.html;

import com.sun.java.browser.dom.DOMAccessException;
import com.sun.java.browser.dom.DOMAccessor;
import com.sun.java.browser.dom.DOMAction;
import com.sun.java.browser.dom.DOMService;
import com.sun.java.browser.dom.DOMUnsupportedException;
import net.xoetrope.xui.XProject;
import net.xoetrope.xui.XProjectManager;
import netscape.javascript.JSObject;
import org.w3c.dom.html.HTMLDivElement;
import org.w3c.dom.html.HTMLDocument;
import org.w3c.dom.html.HTMLImageElement;
import org.w3c.dom.html.HTMLInputElement;
import org.w3c.dom.html.HTMLLabelElement;
import org.w3c.dom.html.HTMLMetaElement;
import org.w3c.dom.html.HTMLOListElement;
import org.w3c.dom.html.HTMLSelectElement;
import org.w3c.dom.html.HTMLTableElement;
import org.w3c.dom.html.HTMLTextAreaElement;
import org.w3c.dom.html.HTMLUListElement;

/**
*
* @author Romain
*/
public class XHtmlWidget
{
  /** @todo fix this and remove the call to getCurrentProject */
  protected XProject currentProject = XProjectManager.getCurrentProject( null );

  protected HTMLDocument htmlDoc;

  protected HTMLImageElement imageElement;

  protected HTMLOListElement olElement;

  protected HTMLUListElement ulElement;

  protected HTMLInputElement inputElement;

  protected HTMLLabelElement labelElement;

  protected HTMLSelectElement selectElement;

  protected HTMLMetaElement metaElement;

  protected HTMLTextAreaElement textareaElement;

  protected HTMLTableElement tableElement;

  protected HTMLDivElement divElement;

  /**
   * Create a new instance of XHtmlWidget
   */
  public XHtmlWidget()
  {
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param ie
   *          the HTML input tag
   */
  public XHtmlWidget( HTMLInputElement ie )
  {
    inputElement = ie;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param se
   *          the HTML select tag
   */
  public XHtmlWidget( HTMLSelectElement se )
  {
    selectElement = se;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param le
   *          the HTML label tag
   */
  public XHtmlWidget( HTMLLabelElement le )
  {
    labelElement = le;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param ime
   *          the HTML img tag
   */
  public XHtmlWidget( HTMLImageElement ime )
  {
    imageElement = ime;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param ole
   *          the HTML ol tag
   */
  public XHtmlWidget( HTMLOListElement ole )
  {
    olElement = ole;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param ule
   *          the HTML ul tag
   */
  public XHtmlWidget( HTMLUListElement ule )
  {
    ulElement = ule;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param me
   *          the HTML meta tag
   */
  public XHtmlWidget( HTMLMetaElement me )
  {
    metaElement = me;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param tae
   *          the HTML textarea tag
   */
  public XHtmlWidget( HTMLTextAreaElement tae )
  {
    textareaElement = tae;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param te
   *          the HTML table tag
   */
  public XHtmlWidget( HTMLTableElement te )
  {
    tableElement = te;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Create a new instance of XHtmlWidget based on an existing HTML element.
   *
   * @param de
   *          the HTML div tag
   */
  public XHtmlWidget( HTMLDivElement de )
  {
    divElement = de;
    if ( htmlDoc == null ) {
      DOMService service = null;
      try {
        service = DOMService.getService( XApplet.getApplet() );

        service.invokeAndWait( new DOMAction()
        {
          public Object run( DOMAccessor accessor )
          {
            htmlDoc = (HTMLDocument)accessor.getDocument( XApplet.getApplet() );
            return null;
          }
        } );
      }
      catch ( DOMUnsupportedException e1 ) {
      }
      catch ( DOMAccessException e2 ) {
      }
    }
  }

  /**
   * Set the value of an HTML element.
   *
   * @param ie
   *          the new object value
   */
  public void setObject( HTMLInputElement ie )
  {
    inputElement = ie;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param se
   *          the new object value
   */
  public void setObject( HTMLSelectElement se )
  {
    selectElement = se;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param le
   *          the new object value
   */
  public void setObject( HTMLLabelElement le )
  {
    labelElement = le;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param ime
   *          the new object value
   */
  public void setObject( HTMLImageElement ime )
  {
    imageElement = ime;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param ole
   *          the new object value
   */
  public void setObject( HTMLOListElement ole )
  {
    olElement = ole;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param ule
   *          the new object value
   */
  public void setObject( HTMLUListElement ule )
  {
    ulElement = ule;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param me
   *          the new object value
   */
  public void setObject( HTMLMetaElement me )
  {
    metaElement = me;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param tae
   *          the new object value
   */
  public void setObject( HTMLTextAreaElement tae )
  {
    textareaElement = tae;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param te
   *          the new object value
   */
  public void setObject( HTMLTableElement te )
  {
    tableElement = te;
  }

  /**
   * Set the value of an HTML element.
   *
   * @param de
   *          the new object value
   */
  public void setObject( HTMLDivElement de )
  {
    divElement = de;
  }

  /**
   * Attach an event to an HTML component
   *
   * @param idTarget
   *          the id of the HTML element to bind the event to
   * @param method
   *          the method executed during this event
   * @param eventType
   *          the type of event (click, blur, mouseOver...)
   */
  public void addEvent( String idTarget, String method, String eventType )
  {
    JSObject obj = JSObject.getWindow( XApplet.getApplet() );
    eventType = eventType.toLowerCase();
    String upper = eventType.substring( 0, 1 ).toUpperCase();
    String event = upper + eventType.substring( 1 );
    obj.eval( "add" + event + "Event( \"" + idTarget + "\", \"" + method + "\" )" );
  }

}
TOP

Related Classes of net.xoetrope.html.XHtmlWidget

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.