sub_arctic.text
Class paragraph

java.lang.Object
  |
  +--sub_arctic.text.paragraph

public class paragraph
extends java.lang.Object

This class the internal representation of a paragraph that is part of a text editor. This paragraph has several important invariants: 1) It contains no (hard) carriage returns. Paragraphs are created when the user hits the enter (c/r) key, so this object does not contain this character. 2) This object can shift itself in x or y without affecting its contents or their state. 3) If the cursor is present in the list of runs (see below) it is always either the first object in the list of runs or its is immediately to the right (the successor) of a text_run. This class retains a linked list of objects which are its "runs". These runs are the raw text data which it is displaying, and possibly markers within that data (such as the current selection start, end point and the cursor). It also maintains a vector of rectangles. This vector of rectangles represents all the pixels in its screen area. When this paragraph gets clicked on, it consults its list of rectangles to find the one which was actually moused on. Once that is discovered, the rectangle is "mapped back" to the run which it represents to determine what text object was clicked on. The runs are what the user edits, not the rectangles. The rectangles are generated from the runs as needed.


Field Summary
protected  java.util.Vector _display_list
          This is where we store the current list of rectangles for display.
protected  int _height
          This is the height of this paragraph.
protected  run _run_list_head
          This is the head of list of runs in this object.
protected  int _width
          This is the width of this paragraph, in pixels.
 
Constructor Summary
paragraph()
          Constructor for a paragraph.
 
Method Summary
 linebreak break_word(text_run current_run, int current_position)
          This is the function that actually breaks a word out of the list of runs.
 void do_layout(int width)
          This is the routine that actually performs the layout.
 void draw_self_local(drawable d)
          Blit the current list of rectangles onto the screen.
 void dump_words(java.util.Vector v)
          Dump out a list of words in a vector.
 int height()
          Return the height of this object (in pixels) following a layout.
 int last_character(word w)
          This function returns the next character from the last run of a word.
 text_run last_run(word w)
          This function returns the last run from a word.
 int next_index(int old, boolean noinc)
          This function returns a new value from an old one.
 text_run next_text_run(run r)
          This function finds the next text_run successor of a given run.
 java.util.Vector place_words(java.util.Vector words, int width)
          This is the process of placing each of the words.
 screen_rect rect_covering_point(int x, int y)
          This function takes a screen coordinate and maps it to a screen rect.
 run run_list_head()
          Return the first object in the list of runs.
 int width()
          Return the width of this paragraph in pixels.
 void xxx_bogus_init()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_run_list_head

protected run _run_list_head
This is the head of list of runs in this object.

_height

protected int _height
This is the height of this paragraph. It is only valid after a layout.

_width

protected int _width
This is the width of this paragraph, in pixels.

_display_list

protected java.util.Vector _display_list
This is where we store the current list of rectangles for display.
Constructor Detail

paragraph

public paragraph()
Constructor for a paragraph.
Method Detail

run_list_head

public run run_list_head()
Return the first object in the list of runs.
Returns:
run the first object in the list of runs or null if there are no runs

height

public int height()
Return the height of this object (in pixels) following a layout. If you modify the contents of the paragraph, this value is not recomputing until you call do_layout.
Returns:
int height of this paragraph in pixels

width

public int width()
Return the width of this paragraph in pixels.

break_word

public linebreak break_word(text_run current_run,
                            int current_position)
This is the function that actually breaks a word out of the list of runs.
Parameters:
text_run - current_run the current run we are working on
int - current_position the current_location within the run
Returns:
linebreak the next break point of this stream of text

next_text_run

public text_run next_text_run(run r)
This function finds the next text_run successor of a given run. If there are no text_run successors of the the given run, then null is returned.

do_layout

public void do_layout(int width)
This is the routine that actually performs the layout. It does this in two phases, first it does line breaking to get a Vector full of word objects. It then does the actual layout of boxes (representing the words) on the screen.
Parameters:
int - width the layout width of this paragraph

next_index

public int next_index(int old,
                      boolean noinc)
This function returns a new value from an old one. If its first parameter is true the new value is same as the old value. If its first parameter is false, the new value is one more than the old value.
Parameters:
int - old value the previous value of the counter
boolean - noinc true if we should not increment
Returns:
int the next index value

place_words

public java.util.Vector place_words(java.util.Vector words,
                                    int width)
This is the process of placing each of the words.
Parameters:
Vector - words a vector of all the words
int - width how many pixels of space do we have. We actually use all the pixels in this space.
Returns:
Vector a vector of screen_rects with all the words laid out.

dump_words

public void dump_words(java.util.Vector v)
Dump out a list of words in a vector.

xxx_bogus_init

public void xxx_bogus_init()

last_character

public int last_character(word w)
This function returns the next character from the last run of a word. This is used to determine the character associated with the dead space at the end of a line.
Returns:
int the index of the next character of the last text run (the one just after the word we are checking)

last_run

public text_run last_run(word w)
This function returns the last run from a word. This function is used find the "rightmost" character in a run by the layout algorithm.

draw_self_local

public void draw_self_local(drawable d)
Blit the current list of rectangles onto the screen.
Parameters:
drawable - d the drawable surface to draw on

rect_covering_point

public screen_rect rect_covering_point(int x,
                                       int y)
This function takes a screen coordinate and maps it to a screen rect. This screen rect is the rectangle which covers that point on the screen. If the point is "out of bounds" with respect to this paragraph, we return null.
Parameters:
int - x the x coord to check (in our coordinate system)
int - y the y coord to check (in our coordinate system)