Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Saving imagemap as a zip file functionality. Done by Nikhil.
authorlingutln <lingutln@localhost>
Thu, 1 Mar 2012 00:23:54 +0000 (00:23 +0000)
committerlingutln <lingutln@localhost>
Thu, 1 Mar 2012 00:23:54 +0000 (00:23 +0000)
svn path=/; revision=304

Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java
Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java
Annotation/src/ie/dcu/apps/ist/export/imagemap/ImageMap.java

index ed9fd591d9fd85f03ef03703c93393f3c0aa3615..29bbf79d8e8da29fdb80b2daa88124872624837a 100644 (file)
@@ -10,6 +10,7 @@ import java.io.*;
 import java.util.List;
 import java.util.logging.Level;
 
+
 import org.eclipse.swt.program.Program;
 
 /**
@@ -18,7 +19,7 @@ import org.eclipse.swt.program.Program;
  * @author Kevin McGuinness
  */
 public class ExportImageMapAction extends AppAction{
-
+       
        public ExportImageMapAction(ActionManager m) {
                super(m);
        }
index 32fcac1dca5137a86bcb45b39513db0a1912ba80..a4e00e0fec6a3f68f62228d7b107646faf18cc0b 100644 (file)
@@ -9,6 +9,8 @@ import java.awt.Polygon;
 import java.awt.image.*;
 import java.io.*;
 import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import javax.imageio.ImageIO;
 
@@ -20,6 +22,7 @@ import javax.imageio.ImageIO;
 public class Exporter {
 //     private final List<SegmentationMask> masks;
        private final BufferedImage image;
+       private File file;
        
        private RolloverEffect effect;
        private String htmlFile = "imagemap.html";
@@ -91,6 +94,10 @@ public class Exporter {
 
        public void export(File folder, List<SegmentationMask> masks) throws IOException, ExportException {
                
+               // Create a zip file for saving imageMaps
+               file = new File("/home/lingutln/practice/example.zip");
+               ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
+               
                // Create image map
                ImageMap map = new ImageMap();
                map.setImageHref(imageFile);
@@ -105,73 +112,114 @@ public class Exporter {
                
                List<String> preloads = new ArrayList<String>();
                map.addPreload(imageFile);
-               for(SegmentationMask mask : masks)
-               {
-                       ContourTracer tracer = new ContourTracer(mask, SegmentationMask.FOREGROUND);
-                       List<Polygon> trace = tracer.trace();
+               
+               try {
+                       // Low (fast) compression.. most of data is PNG compressed anyway
+                       out.setLevel(0);
+                       out.flush();
+                       // Create an entry for the image
+                       ZipEntry entryImage = new ZipEntry(imageFile);
                        
-                       if (trace.size() == 0) {
-                               throw new ExportException("No objects found");
-                       }
-                       preloads.clear();
-                       preloads.add(getPreloads(trace, mask.layerNumber).get(0));
-                       // Write image
-                       ImageIO.write(image, "png", new File(folder, imageFile));
+                       // Start the entry
+                       out.putNextEntry(entryImage);
                        
-                       if (effect != null) {
-                               int i = 0;
+                       ImageIO.write(image, "png", out);
+                               
+                       for(SegmentationMask mask : masks)
+                       {
+                               ContourTracer tracer = new ContourTracer(mask, SegmentationMask.FOREGROUND);
+                               List<Polygon> trace = tracer.trace();
                                
-                               // Generate effect images
-                               for (Polygon object : trace) {
-                                       RenderedImage im = effect.createEffect(image, object);
-                                       // '0' for Rollover effect 
-                                       File output = new File(folder, preloads.get(i));
-                                       ImageIO.write(im, "png", output);
+                               if (trace.size() == 0) {
+                                       throw new ExportException("No objects found");
                                }
-                       }
-                       
-                       // Add javascript preloads
-                       for (String str : preloads) {
-                               map.addPreload(str);
-                       }
-                       
-                       // Add areas
-                       for (Polygon polygon : trace) {
-                               MapArea area = new MapArea();
-                               switch (exportShape) {
-                               case Polygon:
-                                       area.setPolygon(polygon);
-                                       break;
-                               case Rectangle:
-                                       area.setRect(polygon.getBounds());
-                                       break;
-                               case Circle:
-                                       // TODO: Implement circle!
+                               preloads.clear();
+                               preloads.add(getPreloads(trace, mask.layerNumber).get(0));
+                               // Write image
+                               ImageIO.write(image, "png", new File(folder, imageFile));
+                               
+                               if (effect != null) {
+                                       int i = 0;
                                        
-                               default:
-                                       area.setPolygon(polygon);
-                                       break;
+                                       // Generate effect images
+                                       for (Polygon object : trace) {
+                                               RenderedImage im = effect.createEffect(image, object);
+                                               // '0' for Rollover effect 
+                                               File output = new File(folder, preloads.get(i));
+                                               
+                                               // Low (fast) compression.. most of data is PNG compressed anyway
+                                               out.setLevel(0);
+
+                                               // Create an entry for the image
+                                               ZipEntry entryMaskImage = new ZipEntry(preloads.get(i).toString());
+                                               
+                                               // Start the entry
+                                               out.putNextEntry(entryMaskImage);
+                                               // Writing to the Zip file
+                                               ImageIO.write(im, "png", out);
+                               
+                                               // writing to the folder
+                                               ImageIO.write(im, "png", output);
+                                       }
                                }
                                
-                               area.setAlt(objectDescription);
-                               area.setHref(objectLink);
+                               // Add javascript preloads
+                               for (String str : preloads) {
+                                       map.addPreload(str);
+                               }
                                
-                               if (effect != null) {
+                               // Add areas
+                               for (Polygon polygon : trace) {
+                                       MapArea area = new MapArea();
+                                       switch (exportShape) {
+                                       case Polygon:
+                                               area.setPolygon(polygon);
+                                               break;
+                                       case Rectangle:
+                                               area.setRect(polygon.getBounds());
+                                               break;
+                                       case Circle:
+                                               // TODO: Implement circle!
+                                               
+                                       default:
+                                               area.setPolygon(polygon);
+                                               break;
+                                       }
+                                       
+                                       area.setAlt(objectDescription);
+                                       area.setHref(objectLink);
                                        
+                                       if (effect != null) {
+                                               
+                                               
+                                               area.addAttr("onmouseover", 
+                                                       String.format("rollover(document.%s, image%s)", 
+                                                                       imageName, mask.layerNumber));
+                                               area.addAttr("onmouseout", 
+                                                               String.format("rollover(document.%s, image0)", imageName));
+                                               area.addAttr("title",mask.segmentName);
+                                       }
                                        
-                                       area.addAttr("onmouseover", 
-                                               String.format("rollover(document.%s, image%s)", 
-                                                               imageName, mask.layerNumber));
-                                       area.addAttr("onmouseout", 
-                                                       String.format("rollover(document.%s, image0)", imageName));
-                                       area.addAttr("title",mask.segmentName);
+                                       map.addArea(area);
                                }
-                               
-                               map.addArea(area);
                        }
+                       // Create an entry for the imageMap
+                       ZipEntry entryImageMap = new ZipEntry(htmlFile);
+                       
+                       // Start the entry
+                       out.putNextEntry(entryImageMap);
+                       
+                       // Exporting to zip file
+                       map.exportToFile(out);
                        
+                       // Exporting to Folder
                        map.exportToFile(new File(folder, htmlFile));
                }
+               finally 
+               {
+                       // Close
+                       out.close();
+               }
        }
        
        private List<String> getPreloads(List<Polygon> trace, int layerNumber) {
index 58ccfbb1af4b26ab4013c760de2068118b4fd9a6..2a3e1c420eaff6d5e753c2c475c57b90691fab77 100644 (file)
@@ -3,7 +3,9 @@
  */
 package ie.dcu.apps.ist.export.imagemap;
 
+import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -12,6 +14,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.zip.ZipOutputStream;
 
 /**
  * Exports HTML image maps
@@ -196,6 +199,15 @@ public class ImageMap {
                }
        }
        
+       public void exportToFile(ZipOutputStream o) throws IOException {
+               DataOutputStream out = new DataOutputStream(
+                               new BufferedOutputStream(o));
+               System.out.println("Exxporting content : "+export());
+               out.writeBytes(export());
+               // Flush
+               out.flush();
+       }
+       
        private String substitute(String template, Map<String, String> subs) {
                // This could be more efficient..
                String result = template;