summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/kitfox/salamander
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/kitfox/salamander')
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/SVGConstants.java22
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/parser/SVGParser.java96
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java98
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/parser/SVGParserHandler.java80
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java42
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/renderer/SRTreeNode.java83
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/renderer/SurfaceManager.java236
-rwxr-xr-xsrc/main/java/com/kitfox/salamander/writer/SVGWriter.java34
8 files changed, 0 insertions, 691 deletions
diff --git a/src/main/java/com/kitfox/salamander/SVGConstants.java b/src/main/java/com/kitfox/salamander/SVGConstants.java
deleted file mode 100755
index 2e4b120..0000000
--- a/src/main/java/com/kitfox/salamander/SVGConstants.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * SVGConstants.java
- *
- * Created on April 12, 2007, 7:13 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander;
-
-/**
- *
- * @author kitfox
- */
-public interface SVGConstants
-{
- public static final String NAMESPACE_SVG = "http://www.w3.org/2000/svg";
- public static final String PUBLIC_IDENTIFIER_SVG = "PUBLIC \"-//W3C//DTD SVG 1.1//EN\"";
- public static final String SYSTEM_IDENTIFIER_SVG = "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";
- public static final String MIME_TYPE_SVG = "image/svg+xml";
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParser.java b/src/main/java/com/kitfox/salamander/parser/SVGParser.java
deleted file mode 100755
index d588b08..0000000
--- a/src/main/java/com/kitfox/salamander/parser/SVGParser.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SVGParser.java
- *
- * Created on April 11, 2007, 5:07 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-/**
- *
- * @author kitfox
- */
-public class SVGParser
-{
- public static interface SVGParserListener
- {
-
- }
-
- /** Creates a new instance of SVGParser */
- public SVGParser()
- {
- }
-
- /**
- * Parse an SVG document. The document may be either uncompressed XML (.svg)
- * or a zipped document (.svgz). This routine will automatically detect
- * zipped documents and unzip them.
- */
- public static void parse(File source, SVGParserListener listener)
- {
- try
- {
- XMLReader parser;
- parser = XMLReaderFactory.createXMLReader();
- SVGParserHandler handler = new SVGParserHandler(listener);
- parser.setContentHandler(handler);
-
- FileInputStream fis = new FileInputStream(source);
- BufferedInputStream bis = new BufferedInputStream(fis);
- bis.mark(4);
- //Check for gzip magic number
- DataInputStream din = new DataInputStream(bis);
- long magicNumber = din.readLong();
- bis.reset();
-
- InputStream svgStream;
- if ((int)magicNumber == 0x4b50)
- {
- //PK Zip file
- ZipInputStream zin = new ZipInputStream(bis);
- ZipEntry entry = zin.getNextEntry();
- byte[] buf = new byte[(int)entry.getSize()];
- for (int offset = 0; offset < buf.length; offset += zin.read(buf, offset, buf.length - offset));
- zin.closeEntry();
- zin.close();
-
- svgStream = new ByteArrayInputStream(buf);
- }
- else
- {
- //Treat input as uncompressed XML
- svgStream = bis;
- }
-
- InputSource is = new InputSource(svgStream);
- parser.parse(is);
-
- }
- catch (SAXException ex)
- {
- ex.printStackTrace();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java b/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java
deleted file mode 100755
index 4c7a251..0000000
--- a/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * GraphicsCodeGenAntTask.java
- *
- * Created on March 3, 2007, 9:31 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import java.io.File;
-import java.util.ArrayList;
-import javax.imageio.ImageIO;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.FileScanner;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.FileSet;
-
-/**
- * This ant task examines a directory hierarchy containing .xml files and
- * for the XML files rooted in the GraphicsCodeGen.GRAPHICS_NS namespace,
- * causes code generation to be run. Task will only update code that is missing
- * or out of date to minimize processing time.
- *
- * <code>
- * &lt;graphicsCodeGeneration&gt;
- * &lt;fileset dir="${root.dir}"&gt;
- * &lt;include name="com/kitfox/monsters/** / *"/&gt;
- * &lt;/fileset&gt;
- * &lt;fileset dir="${dir2}"&gt;
- * &lt;/fileset&gt;
- * &lt;/graphicsCodeGeneration&gt;
- * </code>
- *
- * @author kitfox
- */
-public class SVGParserAntTask extends Task
-{
-// Path examinePath;
- private ArrayList<FileSet> filesets = new ArrayList<FileSet>();
-
-
- /** Creates a new instance of GraphicsCodeGenAntTask */
- public SVGParserAntTask()
- {
- }
-
- /**
- * Adds a set of files.
- */
- public void addFileset(FileSet set)
- {
- filesets.add(set);
- }
-
- /**
- * The examine path should be a subset of the classpath and include all the
- * classes that should be examined for possible inclusion in the services list.
- */
-// public Path createExaminePath() throws BuildException
-// {
-// if (examinePath == null)
-// {
-// examinePath = new Path(getProject());
-// return examinePath;
-// }
-// throw new BuildException("Only one examine path can be set");
-// }
-
- public void execute() throws BuildException
- {
- /*
- //This is necessary for ImageIO to find all pluggable image readers on the
- // classpath
- ImageIO.scanForPlugins();
-
- for (FileSet fileSet: filesets)
- {
- FileScanner scanner = fileSet.getDirectoryScanner(getProject());
- String[] files = scanner.getIncludedFiles();
-
- File dir = fileSet.getDir();
-
- for (String fileName: files)
- {
-// if (!fileName.getName().endsWith(".xml")) continue;
- File file = new File(dir, fileName);
-//System.err.println("*****File " + file);
-
- //Conditionally generate code
- GraphicsCodeGen.generateCode(file, true);
- }
- }
- */
- }
-
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java b/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java
deleted file mode 100755
index 8119984..0000000
--- a/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * GraphicsDocumentHandler.java
- *
- * Created on March 3, 2007, 7:49 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import com.kitfox.salamander.parser.SVGParser.SVGParserListener;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-
-/**
- *
- * @author kitfox
- */
-public class SVGParserHandler implements ContentHandler
-{
-// LinkedList<CodeGenNode> nodeStack = new LinkedList<CodeGenNode>();
-
- final SVGParserListener listener;
-
- /** Creates a new instance of GraphicsDocumentHandler */
- public SVGParserHandler(SVGParserListener listener)
- {
- this.listener = listener;
- }
-
- public void setDocumentLocator(Locator locator)
- {
- }
-
- public void startDocument() throws SAXException
- {
- }
-
- public void endDocument() throws SAXException
- {
- }
-
- public void startPrefixMapping(String prefix, String uri) throws SAXException
- {
- }
-
- public void endPrefixMapping(String prefix) throws SAXException
- {
- }
-
- public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- {
- }
-
-
- public void endElement(String uri, String localName, String qName) throws SAXException
- {
- }
-
- public void characters(char[] ch, int start, int length) throws SAXException
- {
- }
-
- public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- {
- }
-
- public void processingInstruction(String target, String data) throws SAXException
- {
- }
-
- public void skippedEntity(String name) throws SAXException
- {
- }
-
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java b/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java
deleted file mode 100755
index 0b6aa00..0000000
--- a/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SRTreeNode.java
- *
- * Created on April 12, 2007, 8:07 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import com.kitfox.salamander.renderer.SRTreeNode.RenderingSurface;
-import java.awt.geom.Point2D;
-import java.util.List;
-
-/**
- * Nodes that provide points where markers can be placed.
- *
- * @author kitfox
- */
-abstract public class SRMarkedNode extends SRTreeNode
-{
- /** Creates a new instance of SRTreeNode */
- public SRMarkedNode()
- {
- }
-
- abstract protected List<Point2D.Float> getMarkerPoints();
-
- /**
- * Draw content specific to this element (not including child elements)
- */
- protected void renderLocal(RenderingSurface surface)
- {
- super.renderLocal(surface);
-
- for (Point2D.Float pt: getMarkerPoints())
- {
- getMarkerPoints();
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java b/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java
deleted file mode 100755
index 6f88129..0000000
--- a/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SRTreeNode.java
- *
- * Created on April 12, 2007, 8:07 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import com.kitfox.salamander.renderer.SurfaceManager.SurfaceInfo;
-import java.util.ArrayList;
-
-/**
- *
- * @author kitfox
- */
-abstract public class SRTreeNode
-{
- public static class RenderingSurface
- {
- }
-
- ArrayList<SRTreeNode> children = new ArrayList<SRTreeNode>();
-
- /** Creates a new instance of SRTreeNode */
- public SRTreeNode()
- {
- }
-
- public void addChild(SRTreeNode child)
- {
- children.add(child);
- }
-
- public boolean removeChild(SRTreeNode child)
- {
- return children.remove(child);
- }
-
- protected void render(RenderingSurface surface)
- {
- /*
- if (isFiltered() || isComplexClipArea())
- {
- RenderingSurface oldSurf = surface;
- //New surface initialized to transparent black
- SurfaceInfo backing = SurfaceManager.getDefault().getSurface(width, height, surface.getGraphicsConfiguration());
- surface = new RenderingSurface(backing);
-
- renderLocal(surface);
-
- for (SRTreeNode child: children)
- {
- child.render(surface);
- }
-
- applyFilters(surface);
- applyClipArea();
- oldSurf.overlay(surface);
- }
- else
- {
- applyClipArea();
- renderLocal(surface);
-
- for (SRTreeNode child: children)
- {
- child.render(surface);
- }
- }
- */
- }
-
- /**
- * Draw content specific to this element (not including child elements)
- */
- protected void renderLocal(RenderingSurface surface)
- {
- //No rendering by default
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java b/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java
deleted file mode 100755
index 83cd227..0000000
--- a/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * SurfaceManager.java
- *
- * Created on April 12, 2007, 8:37 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import java.awt.AlphaComposite;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.image.BufferedImage;
-import java.lang.ref.WeakReference;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.TreeSet;
-import java.util.WeakHashMap;
-
-/**
- *
- * @author kitfox
- */
-public class SurfaceManager implements Runnable
-{
- public class SurfaceInfo
- {
- private BufferedImage image;
- private BufImgInfo info;
-
- SurfaceInfo(BufferedImage image, BufImgInfo info)
- {
- this.image = image;
- this.info = info;
- }
-
- public BufferedImage getBuffer()
- {
- return image;
- }
-
- /**
- * Release resources to be recycled. Do not use the image after calling this.
- */
- public void dispose()
- {
- image = null;
- allocatedSurfs.remove(info);
- pooledSurfs.add(info);
- info.touch();
- info = null;
- }
- }
-
- static class BufImgInfo implements Comparable<BufImgInfo>
- {
- final int width;
- final int height;
- final int area;
- WeakReference<SurfaceInfo> surfRef;
- final BufferedImage image;
- long touchTime;
-
- BufImgInfo(BufferedImage image)
- {
- this.width = image.getWidth();
- this.height = image.getHeight();
- this.area = width * height;
-// ref = new SoftReference(img);
- this.image = image;
-// this.surfRef = new WeakReference<SurfaceInfo>(null);
- }
-
- public void attach(SurfaceInfo surf)
- {
- surfRef = new WeakReference(surf);
-// touch();
- }
-
- public int compareTo(SurfaceManager.BufImgInfo obj)
- {
- return area < obj.area ? -1 : (area > obj.area ? 1 : 0);
- }
-
- void touch()
- {
- touchTime = System.currentTimeMillis();
- }
- }
-
- private static final SurfaceManager singleton = new SurfaceManager();
- TreeSet<BufImgInfo> pooledSurfs = new TreeSet<BufImgInfo>();
- HashSet<BufImgInfo> allocatedSurfs = new HashSet<BufImgInfo>();
-// WeakHashMap<SurfaceInfo, BufImgInfo> surfaces = new WeakHashMap<SurfaceInfo, BufImgInfo>();
-
- int SWEEP_DELAY = 10000; //Every 10 seconds
-
- /** Creates a new instance of SurfaceManager */
- private SurfaceManager()
- {
- Thread thread = new Thread(this);
- thread.setDaemon(true);
- thread.start();
- }
-
- public static SurfaceManager getDefault()
- {
- return singleton;
- }
-
- /**
- * @return a new, cleared temporary surface to render upon. Remember to call
- * dispose() on the SurfaceInfo when you're finished with it.
- */
- public SurfaceInfo getSurface(int width, int height, GraphicsConfiguration gc)
- {
- SurfaceInfo surfInfo;
- BufImgInfo bufInfo = null;
- int targetArea = width * height;
-
- //Search for exising surface
- Iterator<BufImgInfo> it = pooledSurfs.iterator();
- for (; it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.area >= targetArea)
- {
- if (info.width >= width && info.height >= height)
- {
- bufInfo = info;
- }
- break;
- }
- }
-
- if (bufInfo == null)
- {
- for (; it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.area / 2 <= targetArea)
- {
- //Do not use exceptionally poorly fit buffers
- break;
- }
- if (info.width >= width && info.height >= height)
- {
- bufInfo = info;
- break;
- }
- }
- }
-
- if (bufInfo != null)
- {
- //Refurbish
-// BufferedImage img = bufInfo.ref.get();
- BufferedImage img = bufInfo.image;
-
- Graphics2D g = img.createGraphics();
-
- g.setComposite(AlphaComposite.Clear);
- g.fillRect(0, 0, width, height);
-
- g.dispose();
-
- surfInfo = new SurfaceInfo(img.getSubimage(0, 0, width, height), bufInfo);
-// surfaces.put(surfInfo, bufInfo);
- allocatedSurfs.add(bufInfo);
- pooledSurfs.remove(bufInfo);
- }
- else
- {
- //Create a new surface
- BufferedImage img;
- if (gc.getColorModel().hasAlpha())
- {
- img = gc.createCompatibleImage(width, height);
- }
- else
- {
- img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
-
- bufInfo = new BufImgInfo(img);
- surfInfo = new SurfaceInfo(img, bufInfo);
-// surfaces.put(surfInfo, bufInfo);
- allocatedSurfs.add(bufInfo);
- }
-
- bufInfo.attach(surfInfo);
- return surfInfo;
- }
-
- public void run()
- {
- while (true)
- {
- /*
- //Clean up memory leaked images
- for (Iterator<BufImgInfo> it = allocatedSurfs.iterator(); it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.surfRef.get() == null)
- {
- it.remove();
- pooledSurfs.add(info);
- info.touch();
- }
- }
- */
-
- //Kill out of date pooled surfaces
- long curTime = System.currentTimeMillis();
- for (Iterator<BufImgInfo> it = pooledSurfs.iterator(); it.hasNext();)
- {
- BufImgInfo info = it.next();
- if ((curTime - info.touchTime) > SWEEP_DELAY)
- {
- it.remove();
- }
- }
-
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException ex)
- {
- ex.printStackTrace();
- }
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/writer/SVGWriter.java b/src/main/java/com/kitfox/salamander/writer/SVGWriter.java
deleted file mode 100755
index 4d51fc5..0000000
--- a/src/main/java/com/kitfox/salamander/writer/SVGWriter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * SVGWriter.java
- *
- * Created on April 12, 2007, 7:17 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.writer;
-
-import com.kitfox.salamander.SVGConstants;
-import java.io.PrintWriter;
-
-/**
- *
- * @author kitfox
- */
-public class SVGWriter implements SVGConstants
-{
- final PrintWriter pw;
-
- /** Creates a new instance of SVGWriter */
- public SVGWriter(PrintWriter pw)
- {
- this.pw = pw;
- }
-
- private void writeHeader()
- {
- pw.printf("<!DOCTYPE svg %s \"%s\"\n", PUBLIC_IDENTIFIER_SVG, SYSTEM_IDENTIFIER_SVG);
- }
-
-}