From 55a9685dc286871d193b62c8f17d5b328ef894eb Mon Sep 17 00:00:00 2001 From: preecej Date: Fri, 6 Jul 2012 00:22:37 +0000 Subject: [PATCH] Trac #157: closed #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 | 11 +++- .../ie/dcu/apps/ist/actions/OpenAction.java | 4 +- .../ie/dcu/apps/ist/actions/SaveAction.java | 16 ++--- .../ie/dcu/apps/ist/dialogs/ExportDialog.java | 58 +++++++++++++++---- .../apps/ist/export/imagemap/Exporter.java | 52 ++++++++--------- .../ie/dcu/segment/SegmentationContext.java | 2 +- 6 files changed, 86 insertions(+), 57 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/AppWindow.java b/Annotation/src/ie/dcu/apps/ist/AppWindow.java index cd242d4..0b5b49f 100644 --- a/Annotation/src/ie/dcu/apps/ist/AppWindow.java +++ b/Annotation/src/ie/dcu/apps/ist/AppWindow.java @@ -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)); diff --git a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java index 2b98513..40a1f12 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java @@ -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); diff --git a/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java b/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java index 7d0d27d..a716699 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java @@ -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()); diff --git a/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java b/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java index f4904ed..2aa76d6 100644 --- a/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java +++ b/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java @@ -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; } diff --git a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java index 83b8054..b8d89cd 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java @@ -121,7 +121,7 @@ public class Exporter { map.setSpeciesName(SegmentationView.speciesCombo.getText()); map.setCollectionId(SegmentationView.collectionId.getText()); map.setComments(SegmentationView.comment.getText()); - + List preloads = new ArrayList(); 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 getPreloads(List trace, int layerNumber) { List preloads = new ArrayList(); - 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; } } diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index f75458f..682a021 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -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; -- 2.34.1