Hello!

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

Note that updates take place every 10 minutes, commits may not be seen immediately.
Trac #157: closed
authorpreecej <preecej@localhost>
Fri, 6 Jul 2012 00:22:37 +0000 (00:22 +0000)
committerpreecej <preecej@localhost>
Fri, 6 Jul 2012 00:22:37 +0000 (00:22 +0000)
#149: still working on recalculating window size and placement for a new image, maybe also need to dispose annotations and segments from previous image.

svn path=/; revision=353

Annotation/src/ie/dcu/apps/ist/AppWindow.java
Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java
Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java
Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java
Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java
Annotation/src/ie/dcu/segment/SegmentationContext.java

index cd242d4726c8970c1ff488ae57ce99d2e6b3b6ee..0b5b49f23122a7df45560e428826417570f1154b 100644 (file)
@@ -97,7 +97,7 @@ public class AppWindow extends ApplicationWindow implements FileDropListener {
        }
 
 
-       private SegmentationView createView(Composite parent) {
+       public SegmentationView createView(Composite parent) {
 
                // Load props
                Properties props;
@@ -122,8 +122,13 @@ public class AppWindow extends ApplicationWindow implements FileDropListener {
                // Return new view
                return view;
        }
-
-
+/*
+       public static SegmentationView resetView(SegmentationView view) {
+               view.dispose();
+               return createView(content);
+               
+       }
+       */
        private static ImageDescriptor createImageDescriptor(String url) {
                try {
                        return ImageDescriptor.createFromURL(new URL(url));
index 2b98513f197471e79d1082c6ac9da42444b5ef2b..40a1f12af37e9cfba1b0978ead66b39a35a5746d 100644 (file)
@@ -4,6 +4,7 @@ import ie.dcu.apps.ist.*;
 import ie.dcu.apps.ist.views.SegmentationView;
 import ie.dcu.apps.ist.views.SegmentationView.Tool;
 import ie.dcu.segment.SegmentationContext;
+import ie.dcu.swt.layout.LayoutFactory;
 
 import java.io.*;
 
@@ -43,9 +44,8 @@ public class OpenAction extends AppAction {
                try {
                        // clear the decks
                        window.getView().resetView();
-                       
+
                        if (SegmentationContext.isContextFile(file)) {
-                       
                                // Load context
                                window.setContext(SegmentationContext.load(file));
                                status("Opened segmentation context %s successfully", name);
index 7d0d27d099f13ba03999a82de5b101fa176c6f62..a716699b0bfdfc3ef3dd4905465786da441a7a81 100644 (file)
@@ -56,15 +56,11 @@ public class SaveAction extends AppAction {
                                exporter.setZipFile(zipFile+IMGMAP_EXTENSION);
 
                                exporter.setImageFile(result.image);
-
-                               // save add'l html image map and uncompressed img files, if desired
-                               if (result.open) {
-                                       exporter.setEffect(result.effect);
-                                       exporter.setHtmlFile(zipFile+".html");
-                                       //exporter.setObjectLink(result.link);
-                                       exporter.setExportShape(result.shape);
-                                       //exporter.setObjectDescription(result.description);
-                               }
+                               exporter.setEffect(result.effect);
+                               exporter.setHtmlFile(zipFile+".html");
+                               exporter.setExportShape(result.shape);
+                               //exporter.setObjectLink(result.link);
+                               //exporter.setObjectDescription(result.description);
                                
                                // Export
                                try {
@@ -79,7 +75,7 @@ public class SaveAction extends AppAction {
                                        
                                // for opening the image after saving as ImageMap
                                if (result.open) {
-                                       File file = new File(result.folder, result.html); // TODO: will need to change this to .exportFolder
+                                       File file = new File(result.exportFolder, result.html);
                                        Program program = Program.findProgram(".html");
                                        if (program != null) {
                                                program.execute(file.getAbsolutePath());
index f4904ed9b69389ae9ae149a7060c4193eb70c4dd..2aa76d6499ece9bdcb6f460b13b901966314698a 100644 (file)
@@ -42,12 +42,12 @@ public class ExportDialog extends Dialog {
                        //html = htmlText.getText().trim();
                        zipFile = zipFileName.getText().trim();
                        html = zipFile+".html";
-                       exportFolder = new File(folderText.getText().trim() + "/" + zipFile + "_HTML_export");
-                       image = "image";
+                       image = "image.png";
                        // JP - URL specification disabled until it can be applied to individual segments  
                        //link = linkText.getText().trim();
                        //description = descriptionText.getText();
                        //shape = getShape();
+                       exportFolder = new File(exportFolderText.getText().trim());
                        shape = AreaShape.valueOf("Polygon"); // JP - only one option for now
                        effect = getEffect();
                        open = openButton.getSelection();
@@ -65,12 +65,14 @@ public class ExportDialog extends Dialog {
        
        // Widgets
        private Text folderText;
+       private Text exportFolderText;
        private Button browseButton;
+       private Button exportBrowseButton;
        private Text htmlText;
        private Text zipFileName;
        private Text imageText;
        private Text linkText;
-       private Button effectCheck;
+       //private Button effectCheck;
        private Combo effectCombo;
        private Button[] shapeRadios;
        private Text descriptionText;
@@ -164,11 +166,23 @@ public class ExportDialog extends Dialog {
                */
                // HTML image map options
                openButton = checkbox(widgets, 
-                               "Create HTML image map and open in browser", true, 3); // TODO: change back to false once exportFolder works
-               // TODO: cascade the next two controls to disabled on the value of openButton
-               effectCheck = checkbox(widgets, "Rollover effect:", true, 1);
+                               "Create HTML image map and open in browser", false, 3);
+
+               // TODO: cascade the following controls to disabled on the value of openButton
+               label(widgets, "Select export folder:");
+               exportFolderText = text(widgets, "");
+               exportBrowseButton = button(widgets, "Browse...");
+
+               //effectCheck = checkbox(widgets, "Rollover effect:", true, 1);
+               spacer(widgets);
                effectCombo = combo(widgets, ROLLOVER_EFFECTS);
                spacer(widgets);
+
+               // defaults
+               exportFolderText.setEnabled(false);
+               exportBrowseButton.setEnabled(false);
+               effectCombo.setEnabled(false);
+
                //hline(widgets);
                // Button bar
                expander(buttons);
@@ -177,7 +191,7 @@ public class ExportDialog extends Dialog {
                cancelButton.setText("Cancel");
                exportButton = new Button(buttons, SWT.PUSH);
                exportButton.setLayoutData(layout4());
-               exportButton.setText("Export");
+               exportButton.setText("Save");
                
                // Set the default button
                shell.setDefaultButton(exportButton);
@@ -196,7 +210,16 @@ public class ExportDialog extends Dialog {
                                }
                        }
                });
-               
+
+               exportBrowseButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               String dir = getDirectory();
+                               if (dir != null) {
+                                       exportFolderText.setText(dir);
+                               }
+                       }
+               });
+
                cancelButton.addListener(SWT.Selection, new Listener() {
                        public void handleEvent(Event e) {
                                result = null;
@@ -212,19 +235,29 @@ public class ExportDialog extends Dialog {
                                }
                        }
                });
+
+               openButton.addListener(SWT.Selection, new Listener() {
+                       public void handleEvent(Event e) {
+                               exportFolderText.setEnabled(openButton.getSelection());
+                               exportBrowseButton.setEnabled(openButton.getSelection());
+                               effectCombo.setEnabled(openButton.getSelection());
+                       }
+               });
                
+               /*
                effectCheck.addListener(SWT.Selection, new Listener() {
                        public void handleEvent(Event e) {
                                effectCombo.setEnabled(effectCheck.getSelection());
                        }
                });
+               */
        }
        
        private boolean validate() {
                
                File folder = new File(folderText.getText());
                if (!folder.isDirectory()) {
-                       validationError("The export folder must be specified");
+                       validationError("The save folder must be specified");
                        folderText.setFocus();
                        return false;
                }
@@ -263,8 +296,9 @@ public class ExportDialog extends Dialog {
        }
        
        private RolloverEffect getEffect() {
-               RolloverEffect effect = null;
-               if (effectCheck.getSelection()) {
+               //RolloverEffect effect = null;
+               RolloverEffect effect = RolloverEffect.darkenBackground(); // default
+               //if (effectCheck.getSelection()) {
                        String text = effectCombo.getText();
                        if (text.equals("Outline Object")) {
                                effect = RolloverEffect.outlineObject();
@@ -273,7 +307,7 @@ public class ExportDialog extends Dialog {
                        } else if (text.equals("Highlight Object")) {
                                effect = RolloverEffect.brightenForeground();
                        }
-               } 
+               //
                return effect;
        }
        
index 83b8054b4efcd1308da892855195f89c58b9584c..b8d89cdb6eed75091902b815dbbf905fb029a118 100644 (file)
@@ -121,7 +121,7 @@ public class Exporter {
                map.setSpeciesName(SegmentationView.speciesCombo.getText());
                map.setCollectionId(SegmentationView.collectionId.getText());
                map.setComments(SegmentationView.comment.getText());
-               
+
                List<String> preloads = new ArrayList<String>();
                map.addPreload(imageFile);
                
@@ -152,8 +152,11 @@ public class Exporter {
                                }
                                preloads.clear();
                                preloads.add(getPreloads(trace, mask.layerNumber).get(0));
+
                                // Write image
-                               ImageIO.write(image, "png", new File(folder, imageFile));
+                               if (exportHTML) {
+                                       ImageIO.write(image, "png", new File(exportFolder, imageFile));
+                               }
                                
                                if (effect != null) {
                                        int i = 0;
@@ -161,22 +164,27 @@ public class Exporter {
                                        // 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));
+                                               // '0' for Rollover effect
+
+                                               File exportOut = null;
+                                               if (exportHTML) {
+                                                       exportOut = new File(exportFolder, 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);
+                                               if (exportHTML) {
+                                                       ImageIO.write(im, "png", exportOut);
+                                               }
                                                
                                                // Saving the marked up annotations 
                                                ZipEntry markupData = new ZipEntry("markup-"+mask.layerNumber+".dat");
@@ -213,8 +221,6 @@ public class Exporter {
                                        //area.setHref(objectLink);
                                        
                                        if (effect != null) {
-                                               
-                                               
                                                area.addAttr("onmouseover", 
                                                        String.format("rollover(document.%s, image%s)", 
                                                                        imageName, mask.layerNumber));
@@ -226,26 +232,10 @@ public class Exporter {
                                        
                                        map.addArea(area);
                                }
-                               
-                               // Generating coordinates files
-                               
-                               
                        }
-                       
-                       // Create an entry for the imageMap (code for saving image map file into the zip file)
-                       /*ZipEntry entryImageMap = new ZipEntry(htmlFile);
-                       
-                       // Start the entry
-                       out.putNextEntry(entryImageMap);
-                       
-                       // Exporting to zip file
-                       map.exportToFile(out);*/
-                       
                        // Exporting to Folder
                        if (exportHTML) {
-                               // TODO: need to detect presence of exportFolder here and create it if it doesn't exist
-                               //map.exportToFile(new File(exportFolder, htmlFile));
-                               map.exportToFile(new File(folder, htmlFile)); // TEST: temporary (replace with exportFolder once created)
+                               map.exportToFile(new File(exportFolder, htmlFile));
                        }
                }
                finally 
@@ -286,7 +276,11 @@ public class Exporter {
                  
                  Element speciesElement = document.createElement("species");
                  speciesElement.setAttribute("name", SegmentationView.speciesCombo.getText());
-                 speciesElement.setAttribute("ubio_id", (SegmentationView.speciesCombo.getData(SegmentationView.speciesCombo.getText())).toString());
+                 if (SegmentationView.speciesCombo.getData(SegmentationView.speciesCombo.getText()) != null) {
+                         speciesElement.setAttribute("ubio_id", (SegmentationView.speciesCombo.getData(SegmentationView.speciesCombo.getText())).toString());
+                 } else {
+                         speciesElement.setAttribute("ubio_id","");
+                 }
                  rootElement.appendChild(speciesElement);
                  
                  Element curatorElement = document.createElement("curator_name");
@@ -368,7 +362,7 @@ public class Exporter {
        private List<String> getPreloads(List<Polygon> trace, int layerNumber) {
                List<String> preloads = new ArrayList<String>();
                
-               if (effect != null) {
+               //if (effect != null) {
                        
                        //String basename = FileUtils.removeExtension(imageFile);
                        String basename = "segment";
@@ -376,7 +370,7 @@ public class Exporter {
                                String filename = String.format("%s-%d.png", basename, layerNumber);
                                preloads.add(filename);
                        }
-               }
+               //}
                return preloads;
        }
 }
index f75458fa14a296ceda43a656e63f3e64e0526cd0..682a02139d607ad2ed83eb0ce419ec8f993ad09a 100644 (file)
@@ -479,7 +479,7 @@ public class SegmentationContext {
                        while ((entry = in.getNextEntry()) != null) {
                                String name = entry.getName();
                                
-                               if (name.equals("image")) {
+                               if (name.equals("image.png")) {
                                        imageData = SwtUtils.loadImageData(in);
                                        ctx = new SegmentationContext(imageData, file);
                                        width = imageData.width;