net.xoetrope.optional.laf.synth
Class SynthPreprocessor

java.lang.Object
  extended by net.xoetrope.optional.laf.synth.SynthPreprocessor
All Implemented Interfaces:
FilePreprocessor

public class SynthPreprocessor
extends java.lang.Object
implements FilePreprocessor

Process a synth file to replace colors etc... with the styles

Copyright (c) Xoetrope Ltd., 2001-2005
License: see license.txt $Revision: 1.13 $


Constructor Summary
SynthPreprocessor()
          Creates a new instance of SynthPreprocessor
 
Method Summary
protected  java.lang.String convertSvg(java.lang.String name, int width, int height, java.lang.String ext, boolean isPng)
          Converts an SVG file to a PNG or a TIFF file
protected  java.lang.String findAndReplace(java.util.Hashtable methodNames, java.lang.String originalText)
          Search and replace a function references embedded in the synth file
protected  java.lang.String getColorStyleAttribute(java.lang.String key, int attrib, boolean asColorResource)
          Replace the tagged field
protected  java.lang.String getIndexedStyleAttribute(java.lang.String key, int attrib, java.lang.String[] values)
          Replace the tagged field
static SynthPreprocessor getInstance()
          Get an instance of this preprocessor
protected  java.lang.String getPngForSvg(java.lang.String key)
          Replace the tagged field and create a PNG file in place of the original SVG.
protected  java.lang.String getStyleAttribute(java.lang.String key, int attrib)
          Replace the tagged field
protected  java.lang.String getTiffForSvg(java.lang.String key)
          Replace the tagged field and create a TIFF file in place of the original SVG.
 java.lang.String process(java.io.BufferedInputStream is)
          Read the file from the input stream, do any substitutions required and return the processed file as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynthPreprocessor

public SynthPreprocessor()
Creates a new instance of SynthPreprocessor

Method Detail

getInstance

public static SynthPreprocessor getInstance()
Get an instance of this preprocessor

Returns:
the preprocessor instance

process

public java.lang.String process(java.io.BufferedInputStream is)
                         throws java.io.IOException
Read the file from the input stream, do any substitutions required and return the processed file as a string.

Specified by:
process in interface FilePreprocessor
Parameters:
is - the input stream
Returns:
the processed file
Throws:
java.io.IOException - problems reading the input stream

findAndReplace

protected java.lang.String findAndReplace(java.util.Hashtable methodNames,
                                          java.lang.String originalText)
Search and replace a function references embedded in the synth file

Parameters:
methodNames - the table of methods to find and replace
originalText - the original config file text
Returns:
the processed text

getStyleAttribute

protected java.lang.String getStyleAttribute(java.lang.String key,
                                             int attrib)
Replace the tagged field

Parameters:
key - the style name
attrib - the attribute to lookup in the style
Returns:
the style value

getColorStyleAttribute

protected java.lang.String getColorStyleAttribute(java.lang.String key,
                                                  int attrib,
                                                  boolean asColorResource)
Replace the tagged field

Parameters:
key - the argument value to replace
attrib - the attribute to lookup in the style
asColorResource - output the colour as a ColorUIResource
Returns:
the color style value

getIndexedStyleAttribute

protected java.lang.String getIndexedStyleAttribute(java.lang.String key,
                                                    int attrib,
                                                    java.lang.String[] values)
Replace the tagged field

Parameters:
key - the style name
attrib - the attribute to lookup in the style
values - the values array into which the attribute indexes
Returns:
the style value

getPngForSvg

protected java.lang.String getPngForSvg(java.lang.String key)
Replace the tagged field and create a PNG file in place of the original SVG. The key can optionally include the width and height.

Parameters:
key - the style name
Returns:
the png file name

getTiffForSvg

protected java.lang.String getTiffForSvg(java.lang.String key)
Replace the tagged field and create a TIFF file in place of the original SVG. The key can optionally include the width and height.

Parameters:
key - the style name
Returns:
the png file name

convertSvg

protected java.lang.String convertSvg(java.lang.String name,
                                      int width,
                                      int height,
                                      java.lang.String ext,
                                      boolean isPng)
Converts an SVG file to a PNG or a TIFF file

Parameters:
name - the file name
width - the target image width
height - the targetimage height
ext - the converted file extension
isPng - true for a png file, false for a tiff file
Returns:
the png file name