Class Document

  • All Implemented Interfaces:
    Scrollable

    public class Document
    extends ScrollContainer
    Represents a Html Document. Here is a sample of how to load an image of a document instead of downloading it from a URL:
     // Extends Document so that we can provide another way to load images, from our internal database
     class ArticleDocument extends Document
     {
        PDBFile cat;
        DataStream ds;
    
        /** The cat parameter should be an already open PDBFile which contains all the images.
          * Note that the image is in the form ".gif" or ".jpeg".
          * /
        public ArticleDocument(XmlReadable doc, PDBFile cat)
        {
           this.cat = cat;
           ds = new DataStream(cat);
           renderDoc(doc);
        }
    
        protected Image loadImage(String src, URI base)
        {
           int dot = src.indexOf('.');
           if (dot == -1) throw new RuntimeException("src image not in expected format: "+src);
           int idx = Convert.toInt(src.substring(0,dot));
           String ext = src.substring(dot+1).toLowerCase();
           if (cat.setRecordPos(idx))
           {
              int size = cat.getRecordSize();
              byte []data = new byte[size];
              ds.readBytes(data);
              return new Image(new ByteArrayStream(data));
          }
        }
     }
     
    And here's a sample on how to call it:
     String s = ...; // get the html from somewhere and store in a String
     if (!s.substring(0,10).toLowerCase().startsWith("";
     // Displays the xml
     hcView.setDocument(new ArticleDocument(new XmlReadableString(s),cat)); // cat must be already instantiated
     
    To change the font size, you must change Style.defaultFontSize. To change the default colors, change UIColors.htmlXXX fields, and don't forget to call htmlContainer.setBackForeColors with these colors.
    See Also:
    Style.defaultFontSize, UIColors.htmlContainerControlsBack, UIColors.htmlContainerControlsFore, UIColors.htmlContainerLink
    • Field Detail

      • baseURI

        public URI baseURI
        Base URL for this document
      • title

        public java.lang.String title
        Title associated with this document.
      • vForms

        public Vector vForms
        All forms in this document.
    • Method Detail

      • loadImage

        protected Image loadImage​(java.lang.String src,
                                  URI baseURI)
        Can be overridden by the caller in order to load an image from a different place. Must return null if not handled/not found. By default, searches for the given file at the loaded libraries (TCZ files).
        Parameters:
        src - The image name
        baseURI - The base URI
        Returns:
        an Image
      • initUI

        public void initUI()
        Layout the controls of this document.
        Overrides:
        initUI in class Container
      • scroll

        public void scroll​(int dir)
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class ScrollContainer