HTML Tables

The Proteus Html Library Extension provides a set of classes to encapsulate HTML attributes and tags. These Html object classes can be used to generate HTML tables.

 

The display of an HTML table involves the following steps:

 

 

Building the Table

To build an HTML table it must be built up in the following sequence:

 

  1. Text
  2. Data
  3. Header (optional)
  4. Row
  5. Caption (optional)
  6. Table

 

Each of these steps encapsulates a preceding step in an associated object class representing an HTML tag. Each object class possesses an associated attributes object that represents the attributes of that particular HTML tag.

 

Text

Text must be encapsulated in an HtmlTextFont object. To encapsulate the string ‘Hello World!’ in an HtmlTextFont object using default text attributes we would use code similar to the following:

 

        f = new HtmlTextFont(nil, ‘Hello World!’);

 

The first argument must either be an object of class HtmlAttributes or nil, meaning we are to use the default HtmlAttributes object associated with this class. Further arguments should be double-quoted strings that are the text we want this object to encapsulate.

 

Data

Data represent individual columns in the HTML table. Each HtmlTextFont object encapsulated by an HtmlTableData object displays within that single column represented by the HtmlTableData object.

 

For our ‘Hello World!’ display, we need only one column – one HtmlTableData object, and it will encapsulate our single HtmlTextFont object, which encapsulates our ‘Hello World!’ double-quoted string. To do this, we would use something like the following code:

 

d = new HtmlTableData(nil, f);

 

Again, the first argument, nil, indicates that we wish to use the default HtmlAttributes object associated with this class. The argument f is the HtmlTextFont object created from the previous step.

Header

Headers are an extension of Data, they have the default of being displayed in bold and centered across the column. For ‘Hello World!’ we could choose to use an HtmlTableHeader, instead of the more generic HtmlTableData, to encapsulate our HtmlTextFont. In that case we would code something like the following:

 

h = new HtmlTableHeader(nil, f);

 

Row

Rows are built from columns – either in the form of Data or Headers. Each row can encapsulate one or more columns, and each row is independent of those preceding or following. However, you may find that for neat and clean display it is best to keep the number of columns consistent in throughout the table.

 

For our ‘Hello World!’ example we only need one row, and we can create it with the following code:

 

r = new HtmlTableRow(nil, d);

 

Again, nil indicates that the default HtmlAttributes object is to be used for this class, and the second argument, d, is our Data created from the previous step.

 

Caption

Captions are displayed outside of the table, either above or below. An Html Table can have only one caption. Captions encapsulate HtmlTextFont objects, just as Data or Headers do.

 

To create the caption object we would use code similar to the following:

 

c = new HtmlTableCaption(nil, f);

 

The nil argument indicates that the default HtmlAttributes object for this class is to be used, and f represents the HtmlTextFont we want to display in the caption.

 

Table

Tables are built up from rows and an optional caption. For our ‘Hello World!’ example we need only one row. The following code could do the job for us:

 

t = new HtmlTable(nil, r);

 

The nil argument indicates that this table will use the default HtmlAttributes object for the class, and r is the HtmlTableRow object we created in the previous steps.

 

Displaying the Table

When we want to display an HTML table we must send the message generate() to the HtmlTable object that we have previously built. The HtmlTable “unravels”, producing the appropriate HTML tags for the table, caption, rows, headers, data, and fonts necessary to display the table. We can now display our ‘Hello World!’ message in table form:

 

t.generate();

 

The result is the somewhat unspectacular:

 

Hello World!

 

This is because we have selected the default HtmlAttributes object for each element of the table. For borders, background color, font size, and other aspects of table display we need to tailor the attributes of individual HTML tags.

 

HTML Attributes

The attributes for HTML tags vary from tag to tag. There are two ways to set the attributes for a tag. Each HtmlTag class provides methods appropriate for that tag that can be invoked with specific values. Also, when the HtmlTag is created an appropriate HtmlAttributes object can be associated with the tag by passing the HtmlAttributes object as the first argument in the new message.

 

Signs

Signs are special HTML tables of the class HtmlSign. A sign already has default background color, border, cell padding, color, and text size. In addition an HtmlSign extends Readable class, which makes the sign an integral part of the game world.

 

Generating an HtmlSign is easier than generating an HtmlTable because the steps for table creation listed above are automatically handled by the HtmlSign class. So our ‘Hello World!’ example could have been done using the following object definition:

 

sign: HtmlSign

{

       ‘sign’ ‘sign’ @entryway

       initText = ‘Hello World!’

}

 

The result is something like the following:

 

Welcome to the TADS 3 Starter Game!

 

 

Entryway

This large, formal entryway is slightly intimidating: the walls are lined with somber portraits of gray-haired men from decades past; a medieval suit of armor, posed with a battle axe at the ready, towers over a single straight-backed wooden chair. The front door leads back outside to the south. A hallway leads north.

 

You see a sign here.

 

>x sign

 

 

      

Hello World!

 

 

>

 

The sign will by default have a border, cell padding, background color and color somewhat like the display above.

 

 

This file is part of the TADS 3 Proteus Library Extension

Copyright © 2001-2004 Kevin Forchione. All rights reserved.