net.xoetrope.optional.laf.synth
Class SvgPreprocessor

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

public class SvgPreprocessor
extends java.lang.Object
implements FilePreprocessor

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

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


Constructor Summary
protected SvgPreprocessor()
          Creates a new instance of SvgPreprocessor
 
Method Summary
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 args, int attrib, boolean isRgb, boolean isHSB)
          Replace the tagged field.
 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

SvgPreprocessor

protected SvgPreprocessor()
Creates a new instance of SvgPreprocessor

Method Detail

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 contents
Throws:
java.io.IOException - problems processing 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

getColorStyleAttribute

protected java.lang.String getColorStyleAttribute(java.lang.String args,
                                                  int attrib,
                                                  boolean isRgb,
                                                  boolean isHSB)
Replace the tagged field. Replace ${tag(args)} with #F0E000 or whatever the hex color value is. Alternatively ${getColorForegroundHex(name,percentRed,percentGreen,PercentBlue)} where the percent fields indicate the variation of each color channel. A value of 100 results in no change a value less than 100 (%) results in a linear scaling of the color value to 00. A value between 100 and 200 scales the value to FF or 255 for an RGB color.
The getColorForegroundHex tag may be replaced by getColorForegroundRgb for RGB output in the form rgb(r,g,b). Finally ${getHsbColorForegroundHex(name,hRed,stGreen,bBlue)} works in a similar fashion with the HSB values being scaled in the same manner. Variations for forground/background and Hex/RGB output are also supported.

Parameters:
isHSB - is a HSB color space used instead of RGB
args - the text to locate e.g. ${getColorForegroundHex(name)}
attrib - the attribute to lookup in the style
isRgb - true to output an RGB color, or false for Hex
Returns:
the attribute as a string