/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. ***********************************************************************/
  18. package org.mt4j.util.xml.svg;
  19. import java.io.File;
  20. //TODO IMPLEMENT!
  21. import org.mt4j.components.MTComponent;
  22. import processing.core.PApplet;
  23. import com.whirlycott.cache.Cache;
  24. import com.whirlycott.cache.CacheException;
  25. import com.whirlycott.cache.CacheManager;
  26. /**
  27. * The Class SVGCache.
  28. */
  29. public class SVGCache {
  30. /** The svg cache. */
  31. private static SVGCache svgCache;
  32. /** The cache. */
  33. private Cache cache;
  34. /**
  35. * Gets the single instance of SVGCache.
  36. *
  37. * @return single instance of SVGCache
  38. */
  39. public static SVGCache getInstance(){
  40. if (svgCache == null){
  41. svgCache = new SVGCache();
  42. return svgCache;
  43. }else{
  44. return svgCache;
  45. }
  46. }
  47. /**
  48. * Instantiates a new sVG cache.
  49. */
  50. private SVGCache(){
  51. try {
  52. cache = CacheManager.getInstance().getCache();
  53. } catch (CacheException e) {
  54. e.printStackTrace();
  55. }
  56. // Shut down the cache manager
  57. // CacheManager.getInstance().shutdown();
  58. }
  59. //TODO wenn in cache, ganze svg gruppenhierarchie clonen
  60. // und clon zurückgeben
  61. /**
  62. * Load svg file.
  63. *
  64. * @param fileName the file name
  65. * @param pa the pa
  66. *
  67. * @return the mT base component
  68. */
  69. public MTComponent loadSVGFile(String fileName, PApplet pa){
  70. MTComponent returnComponent = null;
  71. //Get the object back out of the cache
  72. returnComponent = (MTComponent) cache.retrieve(fileName);
  73. if (returnComponent == null){
  74. System.out.println("Found no cached obj for filepath: " + fileName);
  75. if (new File(fileName).exists()){
  76. // BatikSvgParser batikSvgParser = new BatikSvgParser(pa);
  77. // SVGDocument svgDoc = batikSvgParser.parseSvg(fileName);
  78. // MTBaseComponent[] comps = batikSvgParser.getCreatedSvgComponents(svgDoc);
  79. // MTBaseComponent group = new MTBaseComponent(pa);
  80. // //Wrap the svg in a group
  81. // group.setName("svg: " + fileName);
  82. // group.addChildren(comps);
  83. SVGLoader batikSvgParser = new SVGLoader(pa);
  84. MTComponent svg = batikSvgParser.loadSvg(fileName);
  85. returnComponent = svg;
  86. //TODO store copy? because sonst wird matrix etc verändert wenn damit gearbeitet wurde
  87. cache.store(fileName, svg);
  88. }else{
  89. System.out.println("File doesent exist! aborting..." + fileName);
  90. }
  91. }else{
  92. System.out.println("Found cached svg.");
  93. }
  94. return returnComponent;
  95. }
  96. //TODO für alle componenten clone implementieren?
  97. /**
  98. * Copy svg.
  99. *
  100. * @param original the original
  101. *
  102. * @return the mT base component
  103. */
  104. private MTComponent copySvg(MTComponent original){
  105. return null;
  106. }
  107. /**
  108. * Copy svg recursive.
  109. *
  110. * @param current the current
  111. */
  112. private void copySvgRecursive(MTComponent current){
  113. }
  114. }