lightgraph.painters.SvgPainter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of light-weight-graphing Show documentation
Show all versions of light-weight-graphing Show documentation
Library for creating graphs in a swing environment. Can produce png or svg.
The newest version!
package lightgraph.painters;
import lightgraph.LGFont;
import javax.swing.*;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.MessageFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* New imagej plugin that ...
* User: mbs207
* Date: 1/6/12
* Time: 10:27 AM
*/
public class SvgPainter implements GraphPainter{
StringBuilder OUTPUT;
Color COLOR;
boolean CLIPPING = false;
double LINE_WIDTH=1;
float[] DASHES;
Rectangle clip;
String FILL="none";
Color BACKGROUND;
FontMetrics metrics;
boolean FINISHED=false;
LGFont font = new LGFont("Arial", "Bold", 12);
static final String DOCTYPE = "\n";
static final String XML = "\n";
static final String SVG_TAG = "");
}
public String getOutput(){
if(!FINISHED) finish();
return OUTPUT.toString();
}
public Color getColor(){
return COLOR;
}
public void setLineWidth(double d){
LINE_WIDTH=d;
}
public void restoreLineWidth(){
LINE_WIDTH=1;
}
/**
*
*
* @param dashes length/offest combo's for formatting line dashes. set to null for none.
*/
public void setDashes(float[] dashes){
DASHES = dashes;
}
public void setFill(boolean fill){
if(fill){
FILL=svgColorString(BACKGROUND);
} else{
FILL="none";
}
}
public void startGroup() {
OUTPUT.append("\n");
}
public void endGroup() {
OUTPUT.append(" \n");
}
@Override
public void setFont(LGFont font) {
this.font = font;
}
@Override
public int getStringWidth(String label) {
String stripped = stripSvgTags(label);
return metrics.stringWidth(stripped);
}
String stripSvgTags(String tagged){
return tagged.replaceAll("<[^>]*>", "");
}
@Override
public void drawVerticalString(String s, double x, double y) {
String tag = MessageFormat.format(
"{2} \n",
x, y, s, font.getName(), font.getSize(), font.getStyle(), svgColorString(COLOR)
);
OUTPUT.append(tag);
}
}