sub_arctic.output
Class text_extractor

java.lang.Object
  |
  +--java.awt.Graphics
        |
        +--sub_arctic.output.drawable
              |
              +--sub_arctic.output.drawable_wrapper
                    |
                    +--sub_arctic.output.text_extractor

public class text_extractor
extends drawable_wrapper

This class creates a drawable_wrapper object which extracts any text drawn (including text within images created by the style system). All drawing operations are forwarded to the wrapped drawable.

Currently, this does not create a spatial model of the text drawing to try to paste things together in the right order (and with the right word breaks), it just saves the text in a Vector in the order it is drawn.

Note: this drawable (and many others) will not work with a top_level object (because top_level draws to its in-memory image which it creates its own drawable for).

See Also:
Graphics

Field Summary
protected  java.util.Vector _captured_text
          Vector containing strings extracted from the drawing.
protected  boolean _extraction_enabled
          Is string extraction turned on
 
Fields inherited from class sub_arctic.output.drawable_wrapper
_wrappee
 
Fields inherited from class sub_arctic.output.drawable
_ignore, g
 
Constructor Summary
text_extractor(drawable rappee)
          Simple constructor that creates a new internal vector to capture text into.
text_extractor(drawable rappee, java.util.Vector capture)
          Full constructor.
text_extractor(java.awt.Graphics rappee)
          Constructor working from a Graphics.
text_extractor(java.awt.Graphics rappee, java.util.Vector capture)
          Constructor working from a Graphics.
 
Method Summary
protected  void alternate_report_string(java.lang.String str, int x, int y)
          "Manually" report a string.
 java.util.Vector captured_text()
          Vector containing strings extracted from the drawing.
 void clear_captured_text()
          Clear the captured text.
 java.awt.Graphics create()
          Override create() to create the properly typed wrapper around a copy of the object we wrap.
 java.awt.Graphics create(int x, int y, int w, int h)
          Override create() to create the properly typed wrapper around a copy of the object we wrap.
 void draw_bytes(byte[] data, int off, int len, int x, int y)
          Draw an array of bytes as a string (sets high byte of char to 0).
 void draw_chars(char[] data, int off, int len, int x, int y)
          Draw an array of characters as a string.
 void draw_string(java.lang.String str, int x, int y)
          Draw a string.
 void drawBytes(byte[] data, int off, int len, int x, int y)
          Draw an array of bytes as a string (sets high byte of char to 0).
 void drawChars(char[] data, int off, int len, int x, int y)
          Draw an array of characters as a string.
 boolean drawImage(loaded_image img, int x, int y)
          Extended draw image that can deal with a loaded_image w/o an observer.
 boolean drawImage(loaded_image img, int x, int y, java.awt.Color bgcolor)
          Extended draw image that can deal with a loaded_image w/o an observer.
 boolean drawImage(loaded_image img, int x, int y, int w, int h)
          Extended draw image that can deal with a loaded_image w/o an observer.
 boolean drawImage(loaded_image img, int x, int y, int w, int h, java.awt.Color bgcolor)
          Extended draw image that can deal with a loaded_image w/o an observer.
 void drawString(java.lang.String str, int x, int y)
          Draw a string.
protected  void extract_bytes(byte[] data, int off, int len, int x, int y)
          Extract a string being drawn as an array of bytes at the given location.
protected  void extract_chars(char[] data, int off, int len, int x, int y)
          Extract a string being drawn as an array of chars at the given location.
protected  void extract_image_text(loaded_image img, int x, int y)
          Extract text from an image.
protected  void extract_string(java.lang.String str, int x, int y)
          Extract a string being drawn at the given location.
 boolean extraction_enabled()
          Is string extraction turned on
protected  void report_string(java.lang.String str, int x, int y)
          This method is called to report the output of a string at a given location.
 void set_captured_text(java.util.Vector external_vector)
          Replace the captured text vector with another.
 void set_extraction_enabled(boolean val)
          Turn string extraction on or off.
 java.lang.String toString()
          Convert to a human readable string.
 
Methods inherited from class sub_arctic.output.drawable_wrapper
arrowhead_bound, clearRect, clipRect, copy, copy, copyArea, dispose, draw_arrowhead, draw3DRect, drawArc, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolygon, drawRect, drawRoundRect, end_interactor_draw, fill_arrowhead, fill3DRect, fillArc, fillOval, fillPolygon, fillPolygon, fillRect, fillRoundRect, finalize, getClipBounds, getColor, getFont, getFontMetrics, getFontMetrics, graphics, mark_interactor_draw, setClip, setColor, setFont, setPaintMode, setXORMode, start_interactor_draw, tileImage, translate, wrappee
 
Methods inherited from class sub_arctic.output.drawable
arrowhead_bound, clear_rect, clip_rect, copy_area, draw_3D_rect, draw_arc, draw_arrowhead, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_image, draw_line, draw_oval, draw_polygon, draw_polygon, draw_polyline, draw_rect, draw_round_rect, drawImage, drawImage, drawImage, drawImage, drawPolyline, drawString, fill_3D_rect, fill_arc, fill_arrowhead, fill_oval, fill_polygon, fill_polygon, fill_rect, fill_round_rect, get_clip_bounds, get_clip, get_color, get_font_metrics, get_font_metrics, get_font, getClip, set_clip, set_clip, set_color, set_font, set_paint_mode, set_XOR_mode, setClip, tile_image
 
Methods inherited from class java.awt.Graphics
getClipBounds, getClipRect, hitClip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_captured_text

protected java.util.Vector _captured_text
Vector containing strings extracted from the drawing. This retains its contents until explicitly cleared (with clear_captured_text()).

_extraction_enabled

protected boolean _extraction_enabled
Is string extraction turned on
Constructor Detail

text_extractor

public text_extractor(drawable rappee)
Simple constructor that creates a new internal vector to capture text into.
Parameters:
drawable - rappee the drawable we create a wrapper around.

text_extractor

public text_extractor(drawable rappee,
                      java.util.Vector capture)
Full constructor.
Parameters:
drawable - rappee the drawable we create a wrapper around.
Vector - capture Where we place captured text (if this is null, an internal vector will be allocated).

text_extractor

public text_extractor(java.awt.Graphics rappee,
                      java.util.Vector capture)
Constructor working from a Graphics. We will basically create a plain drawable wrapping the given Graphics object, then use that as the drawable we wrap.
Parameters:
Graphics - rappee the object we are wrapper around.
Vector - capture Where we place captured text (if this is null, an internal vector will be allocated).

text_extractor

public text_extractor(java.awt.Graphics rappee)
Constructor working from a Graphics. We will basically create a plain drawable wrapping the given Graphics object, then use that as the drawable we wrap. Here we also default to an internal capture vector.
Parameters:
Graphics - rappee the object we are wrapper around.
Method Detail

create

public java.awt.Graphics create()
Override create() to create the properly typed wrapper around a copy of the object we wrap. Important Note: copies created with this method all share the same capture vector. If you want a completely independent copy (i.e., with a new capture vector) then you must set the captured_text vector explicitly. Note: subclasses will typically need to do this also.
Returns:
Graphics a new text_extractor object copied from this one.
Overrides:
create in class drawable_wrapper
See Also:
set_captured_text(java.util.Vector)

create

public java.awt.Graphics create(int x,
                                int y,
                                int w,
                                int h)
Override create() to create the properly typed wrapper around a copy of the object we wrap. Important Note: copies created with this method all share the same capture vector. If you want a completely independent copy (i.e., with a new capture vector) then you must set the captured_text vector explicitly. Note: subclasses will typically need to do this also.
Parameters:
int - x x component of origin of new drawable
int - y y component of origin of new drawable
int - w width of new drawable
int - h height of new drawable
Returns:
Graphics a new text_extractor object derived from this one.
Overrides:
create in class drawable_wrapper
See Also:
set_captured_text(java.util.Vector)

captured_text

public java.util.Vector captured_text()
Vector containing strings extracted from the drawing. This retains its contents until explicitly cleared (with clear_captured_text()).
Returns:
Vector containing strings that were captured during drawing.
See Also:

clear_captured_text

public void clear_captured_text()
Clear the captured text. Text continues to accumulate in the order it is drawn until it is explicitly cleared. Typical use of this drawable is to clear the captured text. Draw the interactor(s) of interest. Exctracting/using the captured text, then clearing it again. (Very space concious applications can set safely set the Vector's size to zero after clearing it).
See Also:

set_captured_text

public void set_captured_text(java.util.Vector external_vector)
Replace the captured text vector with another. This vector will be used for all subsequent text capture and can be used to capture text into a partially filled external vector.
Parameters:
Vector - external_vector new Vector to place captured text.

extraction_enabled

public boolean extraction_enabled()
Is string extraction turned on
Returns:
boolean indicating enabled status.

set_extraction_enabled

public void set_extraction_enabled(boolean val)
Turn string extraction on or off. This would normally be used by a string extraction aware interactor which would turn off string extraction and call alternate_report_string() at the start of its draw, then turn extraction back on at the end in order to report a custom string.
Parameters:
boolean - val new enable status.
See Also:
alternate_report_string(java.lang.String, int, int)

alternate_report_string

protected void alternate_report_string(java.lang.String str,
                                       int x,
                                       int y)
"Manually" report a string. This would normally be used by a string extraction aware interactor which would turn off string extraction and call this method at the start of its draw, then turn extraction back on at the end in order to report a custom string. This method reports the string whether string extraction is enabled or not.
Parameters:
String - str the string being (virtually) drawn
int - x x coodinate where we (virtually) draw it.
int - y y coodinate where we (virtually) draw it.
See Also:
set_extraction_enabled(boolean), report_string(java.lang.String, int, int)

report_string

protected void report_string(java.lang.String str,
                             int x,
                             int y)
This method is called to report the output of a string at a given location. All the various extraction types end up here (except alternate_report_string()). If string reporting has turned off this has no effect.
Parameters:
String - str the string being drawn
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.

extract_image_text

protected void extract_image_text(loaded_image img,
                                  int x,
                                  int y)
Extract text from an image. This looks to see if we have an image created by the style system. If we do, then we look in the bookkeeping information associated with it and see if we can find text there.
Parameters:
loaded_image - img the image in question
int - x x coordinate where image is being drawn
int - y y coordinate where image is being drawn

extract_string

protected void extract_string(java.lang.String str,
                              int x,
                              int y)
Extract a string being drawn at the given location.
Parameters:
String - str the string being drawn
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.

extract_chars

protected void extract_chars(char[] data,
                             int off,
                             int len,
                             int x,
                             int y)
Extract a string being drawn as an array of chars at the given location.
Parameters:
char[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.

extract_bytes

protected void extract_bytes(byte[] data,
                             int off,
                             int len,
                             int x,
                             int y)
Extract a string being drawn as an array of bytes at the given location. The high byte of each character is set to 0.
Parameters:
byte[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.

drawImage

public boolean drawImage(loaded_image img,
                         int x,
                         int y)
Extended draw image that can deal with a loaded_image w/o an observer. If the image has not actually been loaded yet, this will block until it has.
Parameters:
loaded_image - img the image to be drawn.
int - x x position to place the image at.
int - y y position to place the image at.
Returns:
boolean undocumented return value from AWT drawImage() routine.
Overrides:
drawImage in class drawable_wrapper

drawImage

public boolean drawImage(loaded_image img,
                         int x,
                         int y,
                         int w,
                         int h)
Extended draw image that can deal with a loaded_image w/o an observer. If the image has not actually been loaded yet, this will block until it has.
Parameters:
loaded_image - img the image to be drawn.
int - x x position to place the image at.
int - y y position to place the image at.
int - w width image will be scaled to.
int - h height image will be scaled to.
Returns:
boolean undocumented return value from AWT drawImage() routine.
Overrides:
drawImage in class drawable_wrapper

drawImage

public boolean drawImage(loaded_image img,
                         int x,
                         int y,
                         java.awt.Color bgcolor)
Extended draw image that can deal with a loaded_image w/o an observer. If the image has not actually been loaded yet, this will block until it has.
Parameters:
loaded_image - img the image to be drawn.
int - x x position to place the image at.
int - y y position to place the image at.
Color - bgcolor background color.
Returns:
boolean undocumented return value from AWT drawImage() routine.
Overrides:
drawImage in class drawable_wrapper

drawImage

public boolean drawImage(loaded_image img,
                         int x,
                         int y,
                         int w,
                         int h,
                         java.awt.Color bgcolor)
Extended draw image that can deal with a loaded_image w/o an observer. If the image has not actually been loaded yet, this will block until it has.
Parameters:
loaded_image - img the image to be drawn.
int - x x position to place the image at.
int - y y position to place the image at.
int - w width image will be scaled to.
int - h height image will be scaled to.
Color - bgcolor background color.
Returns:
boolean undocumented return value from AWT drawImage() routine.
Overrides:
drawImage in class drawable_wrapper

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
Draw a string. Here we extract the text and then pass operation on.
Parameters:
String - str the string being drawn
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
drawString in class drawable_wrapper

draw_string

public void draw_string(java.lang.String str,
                        int x,
                        int y)
Draw a string. Here we extract the text and then pass operation on.
Parameters:
String - str the string being drawn
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
draw_string in class drawable

drawChars

public void drawChars(char[] data,
                      int off,
                      int len,
                      int x,
                      int y)
Draw an array of characters as a string. Here we extract the text and then pass operation on.
Parameters:
char[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
drawChars in class drawable_wrapper

draw_chars

public void draw_chars(char[] data,
                       int off,
                       int len,
                       int x,
                       int y)
Draw an array of characters as a string. Here we extract the text and then pass operation on.
Parameters:
char[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
draw_chars in class drawable

drawBytes

public void drawBytes(byte[] data,
                      int off,
                      int len,
                      int x,
                      int y)
Draw an array of bytes as a string (sets high byte of char to 0). Here we extract the text and then pass operation on.
Parameters:
byte[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
drawBytes in class drawable_wrapper

draw_bytes

public void draw_bytes(byte[] data,
                       int off,
                       int len,
                       int x,
                       int y)
Draw an array of bytes as a string (sets high byte of char to 0). Here we extract the text and then pass operation on.
Parameters:
byte[] - data the string being drawn
int - off offset into array to start drawing with
int - len number of characters to draw
int - x x coodinate where we draw it.
int - y y coodinate where we draw it.
Overrides:
draw_bytes in class drawable

toString

public java.lang.String toString()
Convert to a human readable string.
Overrides:
toString in class drawable_wrapper