|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sub_arctic.lib.html_element
This is a class for keeping around enough state process an HTML document. It is probably not of interest to anyone other than programmers implementing support for new HTML tags. If you want to use HTML in your sub_arctic interfaces, look at the text_flow class.
This class keeps track of various display characteristics and the current contextual information. It also uses methods to generate the various interactors that go on the display and these may be overridden to provide support for new (and more complex) HTML tags.
Basically this class keeps a static variable which is the current "state" of the HTML parse. It is ostensibly a stack but because it is searched it various orders, it is implemented with a vector. You can use "push_element" and pop_element to pop elements of this class onto and off this stack. Thus, when a <B> tag is seen a new html_element is pushed onto the stack to note the font change; when the matching </B> tag is reached, the element is popped off the stack.
The static methods calculate_font(), calculate_color(), and calculate_indent() are used to compute the current font, color and indentation level whenever the stack is manipulated. Thus the variable _current_font is always the up-to-date value to use for creating new screen text. If you put values in the public slots of the html_element for your specific subclass, these methods will pick those values up and add them to the current "context" for drawing operations.
The static method calculate_functions performs an important speed optimization that users of this code must understand. Since you want your new subclasses of html_element to work "in context" with other instances of other subclasses, you must "advertise" which functions of the API you implement. Once you have done so, calculate_functions will determine when to call your object and when to ignore it. This is a speed optimization which allows us to avoid walking the state stack every time we want to insert a word of text (or do any other parsing operation). For example, the subclass numbered_element advertises that it implements the method list_item_prefix because all it cares about doing is inserting the correct prefix when a new LI tag is seen. A more complex example might be if you wanted some "context dependent" tag handling (such as supporting new tags which are only valid inside other tags) you would advertise that you implement the handle_tag operation.
The way you advertise what functions you implement is by overriding the method functions_implemented and returning a set of constants (bitwise ored together) from the static constants below.
The biggest weakness of this object right now is that it really can't handle anything that spans rows. Once we finish putting up a row, we throw everything about it away. This is probably going to make it hard in the future to do "align=RIGHT" type of stuff in IMG tags since to make it look nice it should span multiple rows of text.
Field Summary | |
protected static int |
_basic_font_size
This is the basic font size that the layout algorithm is going to use |
protected static html_element |
_current_add_list_item
This is a pointer to the html_element which is handling ADD_LIST_ITEM. |
protected static html_element |
_current_add_space
This is a pointer to the html_element which is handling ADD_SPACE |
protected static html_element |
_current_add_word
This is a pointer to the html_element which is handling ADD_WORD |
protected static java.lang.StringBuffer |
_current_buffer
This is where we hold the string we are currently building. |
protected static int |
_current_buffer_width
This is where we keep track of how wide the string is that we have buffered in _current_buffer. |
protected static color_pair |
_current_colors
This is the current set of colors in use. |
protected static column |
_current_column
This is the current column (which is really the current paragraph) we are building. |
protected static html_element |
_current_end_of_line
This is a pointer to the html_element which is handling END_OF_LINE |
protected static text_flow |
_current_flow
This the text flow we are actually working on. |
protected static java.awt.Font |
_current_font
This is where we store the current font as we are doing a layout pass. |
protected static html_element |
_current_handle_amp
This is a pointer to the html_element which is handling HANDLE_AMP. |
protected static html_element |
_current_handle_tag
This is a pointer to the html_element which is handling HANDLE_TAG |
protected static int |
_current_indent
This variable is the amount of indentation to use if a new line is called for. |
protected static html_element |
_current_list_item_prefix
This is a pointer to the html_element which is handling LIST_ITEM_PREFIX. |
protected static html_element |
_current_paragraph_end
This is a pointer to the html_element which is handling PARAGRAPH_END. |
protected static html_element |
_current_paragraph_start
This is a pointer to the html_element which is handling PARAGRAPH_START |
protected static row |
_current_row
This is the row that we are currently constructing. |
protected static html_element |
_current_string_end
This is a pointer to the html_element which is handling STRING_END |
protected static int |
_inter_child_space
This is the amount of space between children. |
protected static java.util.StringTokenizer |
_tokenizer
This is the string tokenizer we are using. |
static int |
ADD_LIST_ITEM
|
static int |
ADD_SPACE
|
static int |
ADD_WORD
|
color_pair |
colors
This is the color_pair to use for drawing the text. |
static int |
END_OF_LINE
|
int |
font_modifier
this is a font modifier for things like bold and italic it gets ORed into the font modifier mask ... |
java.lang.String |
font_name
use this for tags that actually change the base font |
int |
font_size
use this for tags that SET the size of the font |
static int |
HANDLE_AMP
|
static int |
HANDLE_TAG
|
int |
indent_contribution
this is the amount of indentation that is tag's contribution to future rows. |
static int |
LIST_ITEM_PREFIX
|
static int |
PARAGRAPH_END
|
static int |
PARAGRAPH_START
|
protected static java.util.Vector |
state
This is basically a data structure for keeping track of the current state of the HTML parse so we can image correctly. |
static int |
STRING_END
|
Constructor Summary | |
html_element()
Construct a html_element. |
|
html_element(boolean b)
Construct an HTML element which is the root of the state stack by passing true here. |
Method Summary | |
void |
add_list_item()
Insert a list item. |
protected void |
add_space()
This function gets called to add whitespace to the display. |
protected void |
add_word(java.lang.String word)
This function does a calculation to see if the new word will fit on this line. |
static void |
calculate_colors()
This function calculates the current color to be drawing in. |
protected static void |
calculate_font()
This function calculates the current font by walking the state vector. |
static void |
calculate_functions()
This function calculates the current set of objects which are handling parsing operations. |
protected static void |
calculate_indent()
This function computes the current indent level by walking down the state and adding up the current amount of indentation. |
void |
end_of_line(int shift,
boolean hard)
This function gets called to polish off the current line. |
protected static void |
finish()
This function is called to handle the end of the HTML parse and general close down operations. |
int |
functions_implemented()
Override this method to inform the system what parsing methods you handle. |
protected void |
handle_amp(java.lang.String tok)
This function gets called to handle putting things it that are used with the ampersand notation. |
protected void |
handle_tag(java.lang.String tag)
This function gets called to implement a tags behavior. |
protected static void |
init(text_flow tf,
java.lang.String text)
This function is called to initialize the parse and get the state stack set up for future things. |
interactor |
list_item_prefix()
This function is called to generate a prefix interactor for list elements. |
void |
paragraph_end()
Handle the end of the current paragraph. |
void |
paragraph_start()
Handle the start of a new paragraph. |
static void |
parse()
This is the main driver function for this parsing operation. |
protected static html_element |
pop_element()
This function removes things from the state vector. |
static html_element |
previous_function(int fn,
html_element elem)
This function is useful for "backchaining" in the state stack to an "older" version of a function. |
protected static void |
push_element(html_element he)
This function pushes things on the state vector. |
static boolean |
row_is_empty(row r)
This function determines if a row is empty or not. |
static void |
set_basic_font_size(int s)
We need this for people who want to have switches for setting the size. |
void |
string_end()
This function is called to inform us that the current string needs to be inserted into the row. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int LIST_ITEM_PREFIX
public static final int HANDLE_TAG
public static final int ADD_SPACE
public static final int ADD_WORD
public static final int END_OF_LINE
public static final int ADD_LIST_ITEM
public static final int HANDLE_AMP
public static final int STRING_END
public static final int PARAGRAPH_END
public static final int PARAGRAPH_START
protected static java.util.Vector state
protected static java.awt.Font _current_font
protected static int _current_indent
protected static row _current_row
protected static color_pair _current_colors
protected static text_flow _current_flow
protected static column _current_column
protected static html_element _current_list_item_prefix
protected static html_element _current_handle_tag
protected static html_element _current_add_space
protected static html_element _current_add_word
protected static html_element _current_end_of_line
protected static html_element _current_add_list_item
protected static html_element _current_handle_amp
protected static html_element _current_string_end
protected static html_element _current_paragraph_end
protected static html_element _current_paragraph_start
protected static java.util.StringTokenizer _tokenizer
protected static int _inter_child_space
protected static java.lang.StringBuffer _current_buffer
protected static int _current_buffer_width
protected static int _basic_font_size
public java.lang.String font_name
public int font_size
public int font_modifier
public int indent_contribution
public color_pair colors
Constructor Detail |
public html_element()
public html_element(boolean b)
boolean
- b true if this object is a root object.Method Detail |
public static void set_basic_font_size(int s)
int
- s the new basic font sizeprotected static void init(text_flow tf, java.lang.String text)
text_flow
- tf the text_flow we are laying outString
- text the text to put in the text_flowprotected static void finish()
protected static void push_element(html_element he)
html_element
- he the html element to push onto the stateprotected static html_element pop_element()
protected static void calculate_font()
protected static void calculate_indent()
public static void calculate_colors()
public static void calculate_functions()
public static html_element previous_function(int fn, html_element elem)
This function might also be useful for finding out who is "behind" you in the context. E.g. if you wanted to make the numbering tags do dots between subordinate lists. E.g. the second level list would 2.1, 2.2, 2.3, etc.
int
- fn the function code to find (must be one of the
static constants above.html_element
- elem the object to start looking "behind" (note that
this function will return null if the element is
the root).public static void parse()
public static boolean row_is_empty(row r)
row
- r the row to checkpublic int functions_implemented()
public interactor list_item_prefix()
protected void handle_tag(java.lang.String tag)
protected void add_space()
protected void add_word(java.lang.String word)
String
- word the text of the word to addpublic void string_end()
public void end_of_line(int shift, boolean hard)
int
- shift the amount you want subtracted from the indentation.boolean
- hard true if you are sure you want to force the
end of a line, even if you are at the beginning of
an empty row. Use false to indicate that you just
want to start at the beginning of a line.public void add_list_item()
protected void handle_amp(java.lang.String tok)
String
- s the string that was between the ampersand and the semicolonpublic void paragraph_end()
public void paragraph_start()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |