home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / HOTJAVA_ / HOTJAVA / CLASSSRC / BROWSER / INPUTT~1.JAV < prev    next >
Encoding:
Text File  |  1995-08-11  |  2.5 KB  |  87 lines

  1. /*
  2.  * @(#)InputTagRef.java    1.10 95/03/24 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package browser;
  21.  
  22. import browser.forms.FormItem;
  23. import net.www.html.Tag;
  24. import net.www.html.TagRef;
  25.  
  26. /**
  27.  * An instance of class InputTagRef is created for each occurrence of
  28.  * a <input> tag in an html form.  It serves as the definition of an
  29.  * html INPUT item as it appears in an html document.  This is the
  30.  * subclass of all <input> items which handles general book keeping,
  31.  * and default initialization, the creation of the FormItem which
  32.  * will handle the specifics of the type of form item this is.
  33.  * @see FormItem
  34.  * @see FormTagRef
  35.  * @version 1.10, 24 Mar 1995
  36.  * @author Jonathan Payne
  37.  */
  38.  
  39. public class InputTagRef extends WRTagRef {
  40.     FormItem    item;        /** input item we represent */
  41.  
  42.     public InputTagRef(Tag t, int pos, boolean isEnd) {
  43.     super(t, pos, isEnd);
  44.     }
  45.  
  46.     FormItem buildFormItem(WRFormatter f) {
  47.     FormItem    i = null;
  48.     FormTagRef  form;
  49.  
  50.     form = f.formContext();
  51.     if (form != null) {
  52.         String    type = getAttribute("type");
  53.  
  54.         if (type == null) {
  55.         type = "text";
  56.         } else {
  57.         type = type.toLowerCase();
  58.         }
  59.         try {
  60.  
  61.             i = (FormItem) new("browser.forms." + type);
  62.         } catch (NoClassDefFoundException e) {
  63.             System.out.println("Warning: bad type for input tag = \""+type+"\" - using type=text instead.");
  64.             i = (FormItem) new("browser.forms.text");
  65.         }
  66.         i.initialize(f, form, this);
  67.         form.addInputItem(i);
  68.     }
  69.     return i;
  70.     }
  71.  
  72.     public void addDisplayItem(WRFormatter f) {
  73.     if (item != null) {
  74.         f.addDisplayItem(item.getDisplayItem(), true);
  75.         f.addCharacterSpacing(' ');
  76.     }
  77.     }
  78.  
  79.     public void apply(WRFormatter f) {
  80.     if (item == null) {
  81.         item = buildFormItem(f);
  82.     }
  83.     item.prime(f);
  84.     addDisplayItem(f);
  85.     }
  86. }
  87.