jfig.objects
Class FigParser

java.lang.Object
  extended byjfig.objects.FigParser
All Implemented Interfaces:
java.lang.Runnable

public class FigParser
extends java.lang.Object
implements java.lang.Runnable

FIG 2.1, 3.1, 3.2 format parser.

This class parses input files in FIG 2.1, FIG 3.1, and FIG 3.2 formats and generates a corresponding representation built from the jfig.objects classes. For a direct interface to the jfig editor, the objects read are inserted into a jfig.objects.FigObjectList object list, which keeps the hierarchical structure of the input with its possibly nested compound objects. To parse a FIG file, call parse_fig_file() and supply the necessary input stream, default attributes and transformation, and an empty object list to be filled.

In order to allow for background parsing of FIG files, this class also provides a threaded variant of the parse_fig_file() method, which uses the run() method from Runnable().

See Also:
FigObject, FigObjectList

Field Summary
(package private)  java.util.Vector actionListeners
           
(package private)  ColorCache colorCache
           
(package private)  java.lang.StringBuffer comment
           
(package private)  boolean debug
           
(package private)  boolean enableMessages
           
(package private)  boolean enableNonASCII
           
(package private)  boolean fastMessages
           
(package private)  int fig_version
           
(package private)  java.lang.String gl_filename
           
(package private)  java.lang.String gl_filetype
           
(package private)  StatusMessage helper
           
(package private)  int input_resolution
           
(package private)  int line_number
           
(package private)  int n_errors
           
(package private)  ObjectPainter painter
           
(package private)  java.lang.String[] paperSizes
           
(package private)  ConsoleMessage printer
           
(package private)  java.lang.Thread reader
           
 boolean solaris_is_broken
           
(package private)  FigAttribs t_attribs
           
(package private)  int t_errors
           
(package private)  java.io.InputStream t_f
           
(package private)  boolean t_inside_compound
           
(package private)  boolean t_merge
           
(package private)  FigObjectList t_OL
           
(package private)  boolean t_top_level
           
(package private)  FigTrafo2D t_trafo
           
 
Constructor Summary
FigParser()
           
FigParser(java.lang.Object app)
           
FigParser(java.lang.Object app, StatusMessage helper)
           
 
Method Summary
 void addActionListener(java.awt.event.ActionListener AL)
           
(package private)  java.lang.String buildString(java.lang.String src)
          build the actual text String for a FigText object from the FIG 3.1 file string.
(package private)  void check_add_object_comment(FigObject object)
           
(package private) static double clipRotationAngle(double radians)
          clip the given rotation angle (in radians) to the range 0..2*PI
(package private)  void collect_object_comment(java.lang.String line)
          add the specified string 'line' to the current per-object comment.
(package private)  double fig_arrow_scale(double x)
           
(package private)  java.awt.Color fig_color(int index)
          return the Color object corresponding to FIG3.1 color index
(package private)  double fig_scale(double x)
           
(package private)  int fig_scale(int x)
          scale from FIG3.1 units (1200dpi, origin at top left) to jfig units (2400dpi, origin at top left).
(package private)  int fig_thickness(int x)
          scale from FIG3.1 line thickness (in units of 1/80th inch) (=approx with in pixels on 75dpi screen) to jfig units at 2400dpi (with 30/2400 = 1/80).
(package private)  void handle_backward_arrow(FigAttribs attribs, FigArrowParams b_arrow_params)
           
(package private)  void handle_forward_arrow(FigAttribs attribs, FigArrowParams f_arrow_params)
           
(package private)  void handleFillStyle(int fill_color, FigAttribs attribs)
          set attribs.fillStyle and calculate the fillColor as a function of lineColor, fillColor and fig_area_fill
(package private)  void handleLineStyle(FigAttribs attribs, int line_style, double style_val)
          FORMAT3.2 states that style_val is the length of on/off dashes or dot separation, in 1/80 inch units.
 void message(java.lang.String msg)
           
 void notifyOurActionListeners(boolean merge)
           
(package private)  java.awt.Color old_fig_color(int index)
           
(package private)  void old_handleFillStyle(FigAttribs attribs)
           
(package private)  void parse_fig_arc(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
           
(package private)  void parse_fig_arrow(java.io.BufferedReader f, FigArrowParams p)
          parse a FIG3.1 arrow parameter line from the stream f.
(package private)  void parse_fig_ellipse(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
           
 int parse_fig_file_not_threaded(java.io.InputStream f, boolean top_level, boolean inside_compound, boolean merge, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          parse_fig_file_not_threaded(): substitute for the function for parse_fig_file_threaded(), because thread scheduling is broken under Solaris JDK 1.1beta...
 int parse_fig_file_threaded(java.io.InputStream f, boolean top_level, boolean inside_compound, boolean merge, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          parse_fig_file_threaded(): parse a FIG 3.1 file in a separate Thread.
 int parse_fig_file(java.io.InputStream ff, boolean top_level, boolean inside_compound, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          read an FIG3.1 file from stream f, and insert the objects found into the objectList.
(package private)  void parse_fig_header(java.io.BufferedReader f, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          Try to parse a FIG 3.1 / FIG 2.1 file header from stream f.
(package private)  void parse_fig_pointline(java.io.BufferedReader f, int npoints, int[] xpoints, int[] ypoints)
          parse a FIG3.1 file for polyline coordinates
(package private)  void parse_fig_polyline(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          parse a FIG3.1 polyline object from the stream f, where line is the current line on the stream f.
(package private)  void parse_fig_pseudocolor(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigObjectList OL)
           
(package private)  void parse_fig_spline(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
           
(package private)  void parse_fig_text(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
           
(package private)  int parse_fig21_pointline(java.io.BufferedReader f)
          parse a FIG2.1 file for polyline coordinates Because FIG 2.1 does not store the number of points, we cannot pre allocate the point arrays.
(package private)  void parse_fig31_cpointline(java.io.BufferedReader f, int npoints, double[] xpoints, double[] ypoints)
          parse a FIG3.1 file for spline control point coordinates
(package private)  void parse_fig32_cpointline(java.io.BufferedReader f, int npoints, double[] sfactors)
          parse FIG3.2 spline control point values (and ignore them)
(package private)  void parse_fig32_header(java.io.BufferedReader f, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          Try to parse a FIG 3.2 file header from reader f.
 void parse_jfig_trigger(java.io.BufferedReader f, java.lang.String line, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
           
(package private)  void parse_text_plain(java.lang.String firstLine, java.io.BufferedReader f, FigAttribs attribs, FigTrafo2D trafo, FigObjectList OL)
          parse_text_plain: simple hack to read text/plain and related files.
 void reset_debug()
           
 void run()
           
 void set_debug()
           
 void setConsole(ConsoleMessage printer)
           
 void setFilenameAndType(java.lang.String fname, java.lang.String ftype)
           
 void setObjectPainter(ObjectPainter _painter)
           
 void setStatusMessage(StatusMessage helper)
           
(package private)  java.lang.String skip_fig_comments(java.io.BufferedReader f)
           
 void statusMessage(java.lang.String msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

boolean debug

fastMessages

boolean fastMessages

n_errors

int n_errors

line_number

int line_number

colorCache

ColorCache colorCache

input_resolution

int input_resolution

fig_version

int fig_version

helper

StatusMessage helper

printer

ConsoleMessage printer

painter

ObjectPainter painter

actionListeners

java.util.Vector actionListeners

gl_filename

java.lang.String gl_filename

gl_filetype

java.lang.String gl_filetype

comment

java.lang.StringBuffer comment

enableNonASCII

boolean enableNonASCII

enableMessages

boolean enableMessages

paperSizes

java.lang.String[] paperSizes

solaris_is_broken

public boolean solaris_is_broken

t_errors

int t_errors

t_top_level

boolean t_top_level

t_inside_compound

boolean t_inside_compound

t_merge

boolean t_merge

t_attribs

FigAttribs t_attribs

t_trafo

FigTrafo2D t_trafo

t_OL

FigObjectList t_OL

reader

java.lang.Thread reader

t_f

java.io.InputStream t_f
Constructor Detail

FigParser

public FigParser(java.lang.Object app)

FigParser

public FigParser(java.lang.Object app,
                 StatusMessage helper)

FigParser

public FigParser()
Method Detail

addActionListener

public void addActionListener(java.awt.event.ActionListener AL)

setFilenameAndType

public void setFilenameAndType(java.lang.String fname,
                               java.lang.String ftype)

setObjectPainter

public void setObjectPainter(ObjectPainter _painter)

setStatusMessage

public void setStatusMessage(StatusMessage helper)

setConsole

public void setConsole(ConsoleMessage printer)

set_debug

public void set_debug()

reset_debug

public void reset_debug()

parse_jfig_trigger

public void parse_jfig_trigger(java.io.BufferedReader f,
                               java.lang.String line,
                               FigAttribs attribs,
                               FigTrafo2D trafo,
                               FigObjectList OL)

fig_scale

final int fig_scale(int x)
scale from FIG3.1 units (1200dpi, origin at top left) to jfig units (2400dpi, origin at top left).

This function uses the global variable input_resolution for the coordinate transformation. Hack for FIG 2.1 files We increment all coordinates by 1 to shift the figure back onto the grid...


fig_scale

final double fig_scale(double x)

fig_arrow_scale

final double fig_arrow_scale(double x)

clipRotationAngle

static double clipRotationAngle(double radians)
clip the given rotation angle (in radians) to the range 0..2*PI


fig_thickness

final int fig_thickness(int x)
scale from FIG3.1 line thickness (in units of 1/80th inch) (=approx with in pixels on 75dpi screen) to jfig units at 2400dpi (with 30/2400 = 1/80). The default line width is transformed into 1-pixel wide lines.


old_fig_color

final java.awt.Color old_fig_color(int index)

fig_color

final java.awt.Color fig_color(int index)
return the Color object corresponding to FIG3.1 color index


handleLineStyle

final void handleLineStyle(FigAttribs attribs,
                           int line_style,
                           double style_val)
FORMAT3.2 states that style_val is the length of on/off dashes or dot separation, in 1/80 inch units.


handleFillStyle

final void handleFillStyle(int fill_color,
                           FigAttribs attribs)
set attribs.fillStyle and calculate the fillColor as a function of lineColor, fillColor and fig_area_fill


old_handleFillStyle

final void old_handleFillStyle(FigAttribs attribs)

handle_forward_arrow

final void handle_forward_arrow(FigAttribs attribs,
                                FigArrowParams f_arrow_params)

handle_backward_arrow

final void handle_backward_arrow(FigAttribs attribs,
                                 FigArrowParams b_arrow_params)

collect_object_comment

void collect_object_comment(java.lang.String line)
add the specified string 'line' to the current per-object comment. We strip off the leading '#' char and leading spaces, however.


check_add_object_comment

void check_add_object_comment(FigObject object)

parse_fig_pseudocolor

void parse_fig_pseudocolor(java.io.BufferedReader f,
                           java.lang.String line,
                           FigAttribs attribs,
                           FigObjectList OL)

parse_fig_ellipse

void parse_fig_ellipse(java.io.BufferedReader f,
                       java.lang.String line,
                       FigAttribs attribs,
                       FigTrafo2D trafo,
                       FigObjectList OL)

parse_fig_spline

void parse_fig_spline(java.io.BufferedReader f,
                      java.lang.String line,
                      FigAttribs attribs,
                      FigTrafo2D trafo,
                      FigObjectList OL)

buildString

java.lang.String buildString(java.lang.String src)
build the actual text String for a FigText object from the FIG 3.1 file string. Because the FIG 3.1 file uses octal escapes for chars c >= 127 and the standard controls like '\n' and '\t', we have to convert some characters from the source String src.

Note that the jfig parser - unlike xfig - will also recognize Java unicode escapes '' to '?'.


parse_fig_text

void parse_fig_text(java.io.BufferedReader f,
                    java.lang.String line,
                    FigAttribs attribs,
                    FigTrafo2D trafo,
                    FigObjectList OL)

parse_fig_arc

void parse_fig_arc(java.io.BufferedReader f,
                   java.lang.String line,
                   FigAttribs attribs,
                   FigTrafo2D trafo,
                   FigObjectList OL)

parse_fig_pointline

void parse_fig_pointline(java.io.BufferedReader f,
                         int npoints,
                         int[] xpoints,
                         int[] ypoints)
parse a FIG3.1 file for polyline coordinates

Parameters:
f - The stream to parse
npoints - The number of (x,y) coordinate pairs

parse_fig21_pointline

int parse_fig21_pointline(java.io.BufferedReader f)
parse a FIG2.1 file for polyline coordinates Because FIG 2.1 does not store the number of points, we cannot pre allocate the point arrays. Instead, the global arrays gl_xp and gl_yp are used to pass the parsed point coords.

Parameters:
f - The stream to parse

parse_fig32_cpointline

void parse_fig32_cpointline(java.io.BufferedReader f,
                            int npoints,
                            double[] sfactors)
parse FIG3.2 spline control point values (and ignore them)


parse_fig31_cpointline

void parse_fig31_cpointline(java.io.BufferedReader f,
                            int npoints,
                            double[] xpoints,
                            double[] ypoints)
parse a FIG3.1 file for spline control point coordinates

Parameters:
f - The stream to parse
npoints - The number of (x,y) coordinate pairs

parse_fig_arrow

void parse_fig_arrow(java.io.BufferedReader f,
                     FigArrowParams p)
parse a FIG3.1 arrow parameter line from the stream f.


parse_fig_polyline

void parse_fig_polyline(java.io.BufferedReader f,
                        java.lang.String line,
                        FigAttribs attribs,
                        FigTrafo2D trafo,
                        FigObjectList OL)
parse a FIG3.1 polyline object from the stream f, where line is the current line on the stream f. Construct the corresponding object and insert it into the object list.

The string 'line' should contain the following: object_code (2), sub_type( polyline/box/polygon/arc/box/image), line_style, thickness, pen_color, fill_color, depth, pen_style (unused), area_fill. style_val, join_style, cap_style, radius, forward-arrow, backward-arrow, npoints. Then follow the forward-arrow and backward-arrow and point lines.


parse_text_plain

void parse_text_plain(java.lang.String firstLine,
                      java.io.BufferedReader f,
                      FigAttribs attribs,
                      FigTrafo2D trafo,
                      FigObjectList OL)
parse_text_plain: simple hack to read text/plain and related files. All lines are converted to FIG text objects in 12pt Courier font.

Unfortunately, the main parser has already read one line of the input stream and we cannot easily back up. So we expect the contents of the first line of the file as additional parameter.


skip_fig_comments

java.lang.String skip_fig_comments(java.io.BufferedReader f)
                             throws java.io.IOException
Throws:
java.io.IOException

parse_fig32_header

void parse_fig32_header(java.io.BufferedReader f,
                        FigAttribs attribs,
                        FigTrafo2D trafo,
                        FigObjectList OL)
Try to parse a FIG 3.2 file header from reader f. Note that parser support for FIG 3.2 is experimental at this stage!


parse_fig_header

void parse_fig_header(java.io.BufferedReader f,
                      FigAttribs attribs,
                      FigTrafo2D trafo,
                      FigObjectList OL)
Try to parse a FIG 3.1 / FIG 2.1 file header from stream f. This is currently not a very tolerant parser: It allows no comments in the header and it requires all tokens to be on individual lines.


parse_fig_file

public int parse_fig_file(java.io.InputStream ff,
                          boolean top_level,
                          boolean inside_compound,
                          FigAttribs attribs,
                          FigTrafo2D trafo,
                          FigObjectList OL)
read an FIG3.1 file from stream f, and insert the objects found into the objectList. The parser looks at the first character of each line and decides what other function to call or to skip over comment lines.

The flag 'top_level' indicates that we should read the FIG3.1 header. This is set to true on the first call, and set to false on recursive calls when parsing compound objects.

Return the number of parser errors encountered.


parse_fig_file_not_threaded

public int parse_fig_file_not_threaded(java.io.InputStream f,
                                       boolean top_level,
                                       boolean inside_compound,
                                       boolean merge,
                                       FigAttribs attribs,
                                       FigTrafo2D trafo,
                                       FigObjectList OL)
parse_fig_file_not_threaded(): substitute for the function for parse_fig_file_threaded(), because thread scheduling is broken under Solaris JDK 1.1beta...


notifyOurActionListeners

public void notifyOurActionListeners(boolean merge)

parse_fig_file_threaded

public int parse_fig_file_threaded(java.io.InputStream f,
                                   boolean top_level,
                                   boolean inside_compound,
                                   boolean merge,
                                   FigAttribs attribs,
                                   FigTrafo2D trafo,
                                   FigObjectList OL)
parse_fig_file_threaded(): parse a FIG 3.1 file in a separate Thread. We simply set up some global stuff, then create a new Thread(this) that uses these global variables in its run()-method...


run

public void run()
Specified by:
run in interface java.lang.Runnable

message

public void message(java.lang.String msg)

statusMessage

public void statusMessage(java.lang.String msg)