sub_arctic.lib
Class text_display

java.lang.Object
  |
  +--sub_arctic.lib.min_interactor
        |
        +--sub_arctic.lib.base_interactor
              |
              +--sub_arctic.lib.text_display
Direct Known Subclasses:
text_edit

public class text_display
extends base_interactor

Text edit area displayer. This class displays a multi-line area of text with a selection point or area in a fashion suitable for use by a small text editor interactor. Selection positions are given as a line number and position with a line. Positions with a line refer to the spaces before the characters (numbered from 0). So for example a selection from line 0, character 0 to line 0, character 0 places the cursor before the first character being displayed, while a selection from line 1 character 1 to line 2 character 2 selects from the second character of the second line, up to and including the second character of the third line.


Field Summary
protected  int _first_line
          First line to display.
protected  java.awt.Font _font
          Font that interactor displays in
protected  int _h_spacing
          Extra horizontal spacing at left and right of text
protected  java.awt.FontMetrics _metric
          Cached font metrics object for the current font
protected  int _selection_end_line
          Ending line of the current selection.
protected  int _selection_end_pos
          Position of end of selection within the ending line.
protected  int _selection_start_line
          Start line of the current selection.
protected  int _selection_start_pos
          Position of start of selection within the start line.
protected  java.util.Vector _text
          Text to be displayed stored as a Vector of Strings
protected  int _v_spacing
          Extra vertical spacing at top and bottom of text
static int BOXED
          Constant used to store boxed flag within interactor flags
static int NO_SELECTION
          Constant for a special selection point used to denote that there is no selection.
static int SELECT_END
          Constant used to denote that the selection is at the end of a line or line is the last one in the text.
protected static int xpos
          X position of current line.
protected static int ypos
          Y position of current line .
protected static int ypos_cutoff
          Max Y position we need to do text drawing at (taking into account the ascent of the font).
 
Fields inherited from class sub_arctic.lib.base_interactor
_child_index, _child_list, _clip_bounds, _constraint_flags, _enabled_constraint, _flags, _h, _h_constraint, _parent, _part_a_constraint, _part_b_constraint, _user_data, _visible_constraint, _w, _w_constraint, _x, _x_constraint, _y, _y_constraint, default_child_hint
 
Constructor Summary
text_display(int xv, int yv, int wv, int hv, java.lang.String contents, java.awt.Font fnt, boolean boxed)
          Full constructor with explicit size.
text_display(int xv, int yv, java.lang.String contents)
          Constructor with computed size, default font, and default boxed status.
text_display(int xv, int yv, java.lang.String contents, java.awt.Font fnt, boolean boxed)
          Full constructor with size determined by initial text.
 
Method Summary
 boolean boxed()
          Does the interactor have a box drawn around it.
static java.util.Vector break_into_lines(java.lang.String all_text)
          Convert a single string into a series of line strings stored in a Vector.
protected  void draw_highlighted_lines(drawable d, int first_ln, int last_ln)
          Draw a series of fully highlighted lines.
protected  void draw_norm_lines(drawable d, int st_ln, int end_ln)
          Draw a series of lines of unhighlighted text.
protected  void draw_self_local(drawable d)
          Draw image of text with selection and optional box
protected  void draw_split_line(drawable d, int ln_num, int st_pos, int end_pos)
          Draw line that is partially highlighted.
 void dump_text()
          Do a human readable dump of the text and selection to System.out
 int first_line()
          First line to display.
 void first_line(int frst_ln)
          Set the first line to display.
 java.awt.Font font()
          Font that interactor displays in
 java.lang.String get_string(java.lang.String terminator)
          Get a single string with lines terminated by the given string.
 int h_spacing()
          Extra horizontal spacing at left and right of text.
 int intrinsic_constraints()
          Parts that we intrinsically constrain.
 int part_a()
          Return the value of the part_a component of this object.
 int selection_end_line()
          Ending line of the current selection.
protected  int selection_end_pos()
          Position of end of selection within the ending line.
 int selection_start_line()
          Start line of the current selection.
protected  int selection_start_pos()
          Position of start of selection within the start line.
 void set_boxed(boolean bxv)
          Set the flag indicating whether interactor is drawn with a surrounding box.
 void set_font(java.awt.Font fnt)
          Set font that interactor displays in
 void set_h_spacing(int v)
          Set extra horizontal spacing at left and right of text.
 void set_part_a(int v)
          Set the part_a component of this object.
protected  void set_raw_part_a(int v)
          Set part_a value directly bypassing the constraint system (but doing damage).
 void set_selection(int st_line, int st_pos, int end_line, int end_pos)
          Set the current selection.
 void set_text(java.lang.String txt)
          Set text contents from a single string with lines terminated by newlines or carriage returns.
 void set_text(java.util.Vector txt)
          Set text contents from Vector of Strings.
 void set_v_spacing(int v)
          Set extra vertical spacing at top and bottom of text.
 void size_by_content()
          Compute a size based on current content.
 java.util.Vector text()
          Text to be displayed stored as a Vector of Strings.
 int v_spacing()
          Extra vertical spacing at top and bottom of text.
 
Methods inherited from class sub_arctic.lib.base_interactor
active_constraints, add_child, add_user_datum, attach_dependent, bound, callback_obj, child_index, child, clear_child_list, clear_constraint_flag_bit, clear_flag_bit, configure, constraint_flag_is_set, constraint_flag_string, constraint_on, custom_fun1, custom_fun2, damage_fixed, damage_from_child, damage_self, damage_self, damage_self, damage_self, damage_self, detach_dependent, do_action, do_action, do_callback, do_callback, drag_feature_point, draw_children, draw_self, enabled_constraint, enabled, enter_local_coordinates, eval_enabled, eval_h, eval_part_a, eval_part_b, eval_visible, eval_w, eval_x, eval_y, eval, exit_local_coords, feature_point_enabled, feature_point, filter_pt, find_child, first_callback_num, fixed_children, flag_is_set, flag_string, focus_set_enter, focus_set_exit, get_awt_component, get_external_constraint, get_part, get_top_level, get_value, global_to_local, global_to_local, h_constraint, h, handle_cycle, inform_ood, insert_child, inside_bounds, into_local, into_local, into_parent, into_parent, is_constrained, last_callback_num, local_to_global, local_to_global, mark_all_ood, mark_enabled_ood, mark_h_ood, mark_ood, mark_part_a_ood, mark_part_b_ood, mark_reparented_ood, mark_visible_ood, mark_w_ood, mark_x_ood, mark_y_ood, marked_ood, move_child_downward, move_child_downward, move_child_to_bottom, move_child_to_bottom, move_child_to_top, move_child_to_top, move_child_upward, move_child_upward, move_downward, move_to_bottom, move_to_top, move_upward, new_look_configure, next_sibling, num_actions, num_children, num_feature_points, ood_inform_all, parent, part_a_constraint, part_b_constraint, part_b, pick_within_children, pick, picked_by, pos, prev_sibling, register_resource_names, remove_child, remove_child, remove_user_datum, restyle_look_resources, restyle, set_callback_obj, set_child_index, set_child, set_constraint_flag_bit, set_constraint_flag_bit, set_constraint, set_constraint, set_enabled_constraint, set_enabled_constraint, set_enabled_constraint, set_enabled, set_flag_bit, set_flag_bit, set_h_constraint, set_h_constraint, set_h_constraint, set_h, set_intrinsic_h, set_intrinsic_size, set_intrinsic_w, set_parent, set_part_a_constraint, set_part_a_constraint, set_part_a_constraint, set_part_b_constraint, set_part_b_constraint, set_part_b_constraint, set_part_b, set_pos, set_pos, set_raw_enabled, set_raw_h, set_raw_part_b, set_raw_visible, set_raw_w, set_raw_x, set_raw_y, set_size, set_style_lock, set_user_info, set_visible_constraint, set_visible_constraint, set_visible_constraint, set_visible, set_w_constraint, set_w_constraint, set_w_constraint, set_w, set_x_constraint, set_x_constraint, set_x_constraint, set_x, set_y_constraint, set_y_constraint, set_y_constraint, set_y, setup_for_children, setup_for_children, setup_for_fixed_children, size, style_change_local, style_change, supports_children, tag_str, toString, traverse_and_collect_children, traverse_and_collect_parent, traverse_and_collect, trivial_reject, trivial_reject, user_data, user_info, value_ood, visible_constraint, visible, w_constraint, w, x_constraint, x_into_local, x_into_parent, x, y_constraint, y_into_local, y_into_parent, y
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_v_spacing

protected int _v_spacing
Extra vertical spacing at top and bottom of text

_h_spacing

protected int _h_spacing
Extra horizontal spacing at left and right of text

_metric

protected java.awt.FontMetrics _metric
Cached font metrics object for the current font

_font

protected java.awt.Font _font
Font that interactor displays in

_text

protected java.util.Vector _text
Text to be displayed stored as a Vector of Strings

NO_SELECTION

public static final int NO_SELECTION
Constant for a special selection point used to denote that there is no selection.

SELECT_END

public static final int SELECT_END
Constant used to denote that the selection is at the end of a line or line is the last one in the text.

_selection_start_line

protected int _selection_start_line
Start line of the current selection.

_selection_start_pos

protected int _selection_start_pos
Position of start of selection within the start line.

_selection_end_line

protected int _selection_end_line
Ending line of the current selection.

_selection_end_pos

protected int _selection_end_pos
Position of end of selection within the ending line.

BOXED

public static final int BOXED
Constant used to store boxed flag within interactor flags

_first_line

protected int _first_line
First line to display. This is tied to part_a of this object so it can be constrained and/or exported to constraint. If this is negative, we still display the 0th line at the top and if this goes past the end we display nothing.

xpos

protected static int xpos
X position of current line. This is used internally only during drawing.

ypos

protected static int ypos
Y position of current line . This is used internally only during drawing.

ypos_cutoff

protected static int ypos_cutoff
Max Y position we need to do text drawing at (taking into account the ascent of the font). Any line of text whose baseline is past this value will not show up and doesn't need to be drawn. This is used internally only during drawing and is normally set to the height of the area plus the ascent of the font.
Constructor Detail

text_display

public text_display(int xv,
                    int yv,
                    int wv,
                    int hv,
                    java.lang.String contents,
                    java.awt.Font fnt,
                    boolean boxed)
Full constructor with explicit size. Text contents is provided by one string with lines separated by newlines or carriage returns.
Parameters:
int - xv x position of this interactor.
int - yv y position of this interactor.
int - wv width of this interactor.
int - hv height of this interactor.
String - contents the text to display in this box.
Font - fnt the font to use for drawing these strings.
boolean - boxed true if this object should have a box around it.

text_display

public text_display(int xv,
                    int yv,
                    java.lang.String contents,
                    java.awt.Font fnt,
                    boolean boxed)
Full constructor with size determined by initial text. Text contents is provided by one string with lines separated by newlines or carriage returns.
Parameters:
int - xv x position of this interactor.
int - yv y position of this interactor.
String - contents the text to display in this box.
Font - fnt the font to use for drawing these strings.
boolean - boxed true if this object should have a box around it.

text_display

public text_display(int xv,
                    int yv,
                    java.lang.String contents)
Constructor with computed size, default font, and default boxed status.
Parameters:
int - xv x position of this interactor.
int - yv y position of this interactor.
String - contents the text to display in this box.
Method Detail

v_spacing

public int v_spacing()
Extra vertical spacing at top and bottom of text.
Returns:
int the vertical spacing value.

set_v_spacing

public void set_v_spacing(int v)
Set extra vertical spacing at top and bottom of text.
Parameters:
int - v the new spacing value.

h_spacing

public int h_spacing()
Extra horizontal spacing at left and right of text.
Returns:
int the horizontal spacing value.

set_h_spacing

public void set_h_spacing(int v)
Set extra horizontal spacing at left and right of text.
Parameters:
int - v the new spacing value.

font

public java.awt.Font font()
Font that interactor displays in
Returns:
Font the font this interactor is using; will return the system's default font if you don't specify a font

set_font

public void set_font(java.awt.Font fnt)
Set font that interactor displays in
Parameters:
Font - fnt the font to use for this interactor (use null to get the system's default font

text

public java.util.Vector text()
Text to be displayed stored as a Vector of Strings. This should normally be treated as read-only.
Returns:
Vector the array of strings that this object is displaying.

set_text

public void set_text(java.lang.String txt)
Set text contents from a single string with lines terminated by newlines or carriage returns.
Parameters:
String - text the text to display.

set_text

public void set_text(java.util.Vector txt)
Set text contents from Vector of Strings.
Parameters:
Vector - txt the array of strings to display.

get_string

public java.lang.String get_string(java.lang.String terminator)
Get a single string with lines terminated by the given string.
Parameters:
String - terminator the line terminator for the return value.
Returns:
String a string with the contents of this object (separated by the parameter).

dump_text

public void dump_text()
Do a human readable dump of the text and selection to System.out

break_into_lines

public static java.util.Vector break_into_lines(java.lang.String all_text)
Convert a single string into a series of line strings stored in a Vector. Lines are delimited by newlines or carriage returns.
Parameters:
String - all_text the text to break up into lines
Vector - the array of lines of the broken up text

selection_start_line

public int selection_start_line()
Start line of the current selection.

selection_start_pos

protected int selection_start_pos()
Position of start of selection within the start line.

selection_end_line

public int selection_end_line()
Ending line of the current selection.

selection_end_pos

protected int selection_end_pos()
Position of end of selection within the ending line.

set_selection

public void set_selection(int st_line,
                          int st_pos,
                          int end_line,
                          int end_pos)
Set the current selection. The special value NO_SELECTION can be coded in any position to denote that there is no current selection (in that case the other parameters are ignored). The special value SELECT_END may be applied to either a line or a character position to denote the last line, or the position after the last character respectively.
Parameters:
int - st_line the starting line of the new selection.
int - st_pos the starting position of the new selection.
int - end_line the ending line of the new selection.
int - end_pos the ending position of the new selection.

boxed

public boolean boxed()
Does the interactor have a box drawn around it.
Returns:
boolean true if this interactor is boxed.

set_boxed

public void set_boxed(boolean bxv)
Set the flag indicating whether interactor is drawn with a surrounding box.
Parameters:
boolean - box true if this interactor is boxed.

size_by_content

public void size_by_content()
Compute a size based on current content.

intrinsic_constraints

public int intrinsic_constraints()
Parts that we intrinsically constrain. Here we modify what our super types result by removing part_a from the set.
Returns:
int a bitset indicating all parts that are intrinsically constrained.
Overrides:
intrinsic_constraints in class base_interactor

part_a

public int part_a()
Return the value of the part_a component of this object. In our case this is stored in _first_line.
Returns:
int the value of part_a (AKA first_line).
Overrides:
part_a in class base_interactor

set_raw_part_a

protected void set_raw_part_a(int v)
Set part_a value directly bypassing the constraint system (but doing damage). This should normally only be done by the constraint system or some other part of the system which takes care of marking things out-of-date, etc. itself. In this case part_a is stored in _first_line.
Parameters:
int - v the new value.
Overrides:
set_raw_part_a in class base_interactor

set_part_a

public void set_part_a(int v)
Set the part_a component of this object. In our case this is stored in _first_line.
Parameters:
int - v the new value
Overrides:
set_part_a in class base_interactor

first_line

public int first_line()
First line to display. This is tied to part_a of this object so it can be constrained and/or exported to constraint. If this is negative, we still display the 0th line at the top and if this goes past the end we display nothing.
Returns:
int the first line offset.

first_line

public void first_line(int frst_ln)
Set the first line to display. This is tied to part_a of this object so it can be constrained and/or exported to constraint. If this is negative, we still display the 0th line at the top and if this goes past the end we display nothing.
Parameters:
int - frst_ln the first line to display.

draw_norm_lines

protected void draw_norm_lines(drawable d,
                               int st_ln,
                               int end_ln)
Draw a series of lines of unhighlighted text. The static variables xpos and ypos are used here to keep track of current line position and communicate that between subsequent calls. We assume here that the background has been cleared, the font has been set and that the current color is set right for drawing text.
Parameters:
drawable - d the surface to do the drawing on.
int - st_ln starting line.
int - end_ln ending line.

draw_split_line

protected void draw_split_line(drawable d,
                               int ln_num,
                               int st_pos,
                               int end_pos)
Draw line that is partially highlighted. The highlight runs from the given starting position to the given ending position (or SELECT_END if the highlight goes past end of line). The static variables xpos and ypos are used here to keep track of current line position and communicate that between subsequent calls. We assume here that the background has been cleared and the font set.
Parameters:
drawable - d the surface to do the drawing on.
int - ln_num the line number of the split line.
int - st_pos the position in the line of the start of the split.
int - end_pos the position in the line of the end of the split.

draw_highlighted_lines

protected void draw_highlighted_lines(drawable d,
                                      int first_ln,
                                      int last_ln)
Draw a series of fully highlighted lines. The static variables xpos and ypos are used here to keep track of current line position and communicate that between subsequent calls. We assume here that the background has been cleared and the font set.
Parameters:
drawable - d the surface to do the drawing on.
int - first_ln the line number of the first highlighted line.
int - last_ln the line number of the last highlighted line.

draw_self_local

protected void draw_self_local(drawable d)
Draw image of text with selection and optional box
Parameters:
drawable - d the drawable to work on
Overrides:
draw_self_local in class base_interactor