PageRenderTime 58ms CodeModel.GetById 50ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/src/org/mt4j/util/xml/svg/SVGCache.java

http://mt4j.googlecode.com/
Java | 145 lines | 49 code | 31 blank | 65 comment | 5 complexity | e9b56a3e86ce658ebeed31c2b9b212f8 MD5 | raw file
  1/***********************************************************************
  2 * mt4j Copyright (c) 2008 - 2009 C.Ruff, Fraunhofer-Gesellschaft All rights reserved.
  3 *  
  4 *   This program is free software: you can redistribute it and/or modify
  5 *   it under the terms of the GNU General Public License as published by
  6 *   the Free Software Foundation, either version 3 of the License, or
  7 *   (at your option) any later version.
  8 *
  9 *   This program is distributed in the hope that it will be useful,
 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *   GNU General Public License for more details.
 13 *
 14 *   You should have received a copy of the GNU General Public License
 15 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 16 *
 17 ***********************************************************************/
 18package org.mt4j.util.xml.svg;
 19
 20import java.io.File;
 21
 22//TODO IMPLEMENT!
 23
 24import org.mt4j.components.MTComponent;
 25
 26import processing.core.PApplet;
 27
 28import com.whirlycott.cache.Cache;
 29import com.whirlycott.cache.CacheException;
 30import com.whirlycott.cache.CacheManager;
 31
 32/**
 33 * The Class SVGCache.
 34 */
 35public class SVGCache {
 36	
 37	/** The svg cache. */
 38	private static SVGCache svgCache;
 39	
 40	/** The cache. */
 41	private Cache cache;
 42
 43	/**
 44	 * Gets the single instance of SVGCache.
 45	 * 
 46	 * @return single instance of SVGCache
 47	 */
 48	public static SVGCache getInstance(){
 49		if (svgCache == null){
 50			svgCache = new SVGCache();
 51			return svgCache;
 52		}else{
 53			return svgCache;
 54		}
 55	}
 56	
 57	/**
 58	 * Instantiates a new sVG cache.
 59	 */
 60	private SVGCache(){
 61		try {
 62			cache = CacheManager.getInstance().getCache();
 63		} catch (CacheException e) {
 64			e.printStackTrace();
 65		}
 66		
 67//			Shut down the cache manager
 68//			CacheManager.getInstance().shutdown();
 69	}
 70	
 71	
 72	//TODO wenn in cache, ganze svg gruppenhierarchie clonen 
 73	// und clon zurückgeben
 74	/**
 75	 * Load svg file.
 76	 * 
 77	 * @param fileName the file name
 78	 * @param pa the pa
 79	 * 
 80	 * @return the mT base component
 81	 */
 82	public MTComponent loadSVGFile(String fileName, PApplet pa){
 83		MTComponent returnComponent = null;
 84		
 85		//Get the object back out of the cache
 86		returnComponent = (MTComponent) cache.retrieve(fileName);
 87		
 88		if (returnComponent == null){
 89			System.out.println("Found no cached obj for filepath: " + fileName);
 90			if (new File(fileName).exists()){
 91//				BatikSvgParser batikSvgParser = new BatikSvgParser(pa);
 92//				SVGDocument svgDoc = batikSvgParser.parseSvg(fileName);
 93//				MTBaseComponent[] comps = batikSvgParser.getCreatedSvgComponents(svgDoc);
 94//				MTBaseComponent group = new MTBaseComponent(pa);
 95//				//Wrap the svg in a group
 96//				group.setName("svg: " + fileName);
 97//				group.addChildren(comps);
 98				
 99				SVGLoader batikSvgParser = new SVGLoader(pa);
100				MTComponent svg = batikSvgParser.loadSvg(fileName);
101				
102				returnComponent = svg;
103				
104				//TODO store copy? because sonst wird matrix etc verändert wenn damit gearbeitet wurde
105				cache.store(fileName, svg);
106			}else{
107				System.out.println("File doesent exist! aborting..." + fileName);
108			}
109		}else{
110			System.out.println("Found cached svg.");
111		}
112		
113		return returnComponent;
114	}
115	
116
117	//TODO für alle componenten clone implementieren?
118	/**
119	 * Copy svg.
120	 * 
121	 * @param original the original
122	 * 
123	 * @return the mT base component
124	 */
125	private MTComponent copySvg(MTComponent original){
126		
127		return null;
128	}
129	
130	
131	/**
132	 * Copy svg recursive.
133	 * 
134	 * @param current the current
135	 */
136	private void copySvgRecursive(MTComponent current){
137		
138		
139		
140	}
141	
142	
143	
144
145}