package ie.dcu.apps.ist.actions; import ie.dcu.apps.ist.dialogs.ExportDialog; import ie.dcu.apps.ist.export.imagemap.*; import ie.dcu.segment.*; import ie.dcu.swt.ImageConverter; import java.awt.image.BufferedImage; import java.io.*; import java.util.List; import java.util.logging.Level; import org.eclipse.swt.program.Program; /** * Export segmentation results as HTML image maps * * @author Kevin McGuinness */ public class ExportImageMapAction extends AppAction{ /** * The file extension given to a this object when it is saved on a disk */ public static final String IMGMAP_EXTENSION = ".imgmap"; public ExportImageMapAction(ActionManager m) { super(m); } @Override public void run() { SegmentationContext ctx = window.getContext(); List masks = ctx.getSegmentationMasks(); if (ctx.hasSegmentationMasks()) { // Get options from user ExportDialog dialog = new ExportDialog(window.getShell()); ExportDialog.Result result = dialog.open(); if (result != null) { // Grab image and mask BufferedImage image = ImageConverter.convert(ctx.getImageData()); // Setup exporter Exporter exporter = new Exporter(image, ctx); exporter.setEffect(result.effect); exporter.setHtmlFile(result.html); // Taking html file name and making the same as filename of imagemap int dotIndex = result.zipFile.indexOf('.'); String zipFile = result.zipFile.substring(0, dotIndex); System.out.println("Zip file name is : "+zipFile); exporter.setZipFile(zipFile+IMGMAP_EXTENSION); exporter.setImageFile(result.image); //exporter.setObjectLink(result.link); exporter.setExportShape(result.shape); //exporter.setObjectDescription(result.description); // Export try { exporter.export(result.folder,result.open,result.exportFolder,masks); } catch (IOException e) { handleError(e); return; } catch (ExportException e) { handleError(e); return; } // for opening the image after saving as ImageMap if (result.open) { File file = new File(result.folder, result.html); Program program = Program.findProgram(".html"); if (program != null) { program.execute(file.getAbsolutePath()); } } } } } private void handleError(Exception e) { log(Level.WARNING, "Error exporting view as HTML image map", e); // Show error dialog error("Error exporting view as HTML image map: %s", e.getLocalizedMessage()); // Set status message status(Error, "Error exporting view as HTML image map"); } }