From 330d53533800f742a4b401f9a92d62780a00047f Mon Sep 17 00:00:00 2001 From: preecej Date: Wed, 4 Jul 2012 22:29:31 +0000 Subject: [PATCH] [Trac tickets] Closed: 204,200,203,202,198 Held: 193,188,186 Working on Trac tickets: 149,157 svn path=/; revision=352 --- Annotation/src/ie/dcu/apps/ist/AppWindow.java | 4 +- .../ist/actions/ExportImageMapAction.java | 6 +-- .../ie/dcu/apps/ist/actions/OpenAction.java | 4 +- .../ie/dcu/apps/ist/actions/SaveAction.java | 54 ++++++++++--------- .../ie/dcu/apps/ist/dialogs/ExportDialog.java | 37 +++++++------ .../apps/ist/export/imagemap/Exporter.java | 21 +++++--- .../src/ie/dcu/apps/ist/labelling/Labels.java | 2 +- .../dcu/apps/ist/views/SegmentationView.java | 26 +++++---- .../ie/dcu/segment/SegmentationContext.java | 5 ++ 9 files changed, 93 insertions(+), 66 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/AppWindow.java b/Annotation/src/ie/dcu/apps/ist/AppWindow.java index e2e98b6..cd242d4 100644 --- a/Annotation/src/ie/dcu/apps/ist/AppWindow.java +++ b/Annotation/src/ie/dcu/apps/ist/AppWindow.java @@ -325,11 +325,11 @@ public class AppWindow extends ApplicationWindow implements FileDropListener { tools.add(new Separator()); tools.add(actions.get(ConfigureSegmenterAction.class)); - */ + MenuManager go = addMenu(bar, "&Go"); go.add(actions.get(NextAction.class)); go.add(actions.get(PreviousAction.class)); - + */ MenuManager help = addMenu(bar, "&Help"); help.add(actions.get(HelpAction.class)); diff --git a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java index ce71c83..be8654c 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java @@ -54,13 +54,13 @@ public class ExportImageMapAction extends AppAction{ exporter.setZipFile(zipFile+IMGMAP_EXTENSION); exporter.setImageFile(result.image); - exporter.setObjectLink(result.link); + //exporter.setObjectLink(result.link); exporter.setExportShape(result.shape); - exporter.setObjectDescription(result.description); + //exporter.setObjectDescription(result.description); // Export try { - exporter.export(result.folder,masks); + exporter.export(result.folder,result.open,result.exportFolder,masks); } catch (IOException e) { handleError(e); return; diff --git a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java index fbfb518..2b98513 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java @@ -43,7 +43,7 @@ public class OpenAction extends AppAction { try { // clear the decks window.getView().resetView(); - + if (SegmentationContext.isContextFile(file)) { // Load context @@ -56,7 +56,7 @@ public class OpenAction extends AppAction { window.setContext(SegmentationContext.loadImageMap(file)); status("Opened segmentation context %s successfully", name); } - else { + else { // JP - majority of cases (opening an img or zip file to annotate) // Create context window.setContext(SegmentationContext.create(file)); status("Opened image file %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 549a62c..7d0d27d 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java @@ -45,37 +45,41 @@ public class SaveAction extends AppAction { 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); + BufferedImage image = ImageConverter.convert(ctx.getImageData()); + + // Setup exporter + Exporter exporter = new Exporter(image); + + // save the annotated zip file + String zipFile = result.zipFile; + 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("imagemap.html"); - - // Taking html file name and making the same as filename of imagemap - String zipFile = result.zipFile; - exporter.setZipFile(zipFile+IMGMAP_EXTENSION); - - exporter.setImageFile(result.image); - exporter.setObjectLink(result.link); + exporter.setHtmlFile(zipFile+".html"); + //exporter.setObjectLink(result.link); exporter.setExportShape(result.shape); - exporter.setObjectDescription(result.description); + //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; + } - // Export - try { - exporter.export(result.folder,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); + File file = new File(result.folder, result.html); // TODO: will need to change this to .exportFolder 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 8bbf394..f4904ed 100644 --- a/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java +++ b/Annotation/src/ie/dcu/apps/ist/dialogs/ExportDialog.java @@ -27,11 +27,12 @@ public class ExportDialog extends Dialog { public class Result { public final File folder; + public final File exportFolder; public final String html; public final String zipFile; public final String image; - public final String link; - public final String description; + //public final String link; + //public final String description; public final AreaShape shape; public final RolloverEffect effect; public final boolean open; @@ -39,12 +40,15 @@ public class ExportDialog extends Dialog { Result() { folder = new File(folderText.getText().trim()); //html = htmlText.getText().trim(); - html = "imagemap.html"; zipFile = zipFileName.getText().trim(); + html = zipFile+".html"; + exportFolder = new File(folderText.getText().trim() + "/" + zipFile + "_HTML_export"); image = "image"; - link = linkText.getText().trim(); - description = descriptionText.getText(); - shape = getShape(); + // JP - URL specification disabled until it can be applied to individual segments + //link = linkText.getText().trim(); + //description = descriptionText.getText(); + //shape = getShape(); + shape = AreaShape.valueOf("Polygon"); // JP - only one option for now effect = getEffect(); open = openButton.getSelection(); } @@ -78,7 +82,7 @@ public class ExportDialog extends Dialog { // Effects private final String[] ROLLOVER_EFFECTS = { - "Outline Object", "Darken Background", "Highlight Object" + "Darken Background", "Outline Object", "Highlight Object" }; // Shapes @@ -87,7 +91,7 @@ public class ExportDialog extends Dialog { }; // Default title - private static final String TITLE = "Export HTML Image Map"; + private static final String TITLE = "Save Annotation"; public ExportDialog(Shell shell) { super(shell); @@ -134,17 +138,18 @@ public class ExportDialog extends Dialog { buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); // Form content - label(widgets, "Export folder:"); + label(widgets, "Select folder:"); folderText = text(widgets, ""); browseButton = button(widgets, "Browse..."); - label(widgets, "Target zip file name:"); - zipFileName = text(widgets, "annotated"); + label(widgets, "Name your .zip file:"); + zipFileName = text(widgets, ""); label(widgets, ".zip"); //spacer(widgets); /*label(widgets, "File name:"); imageText = text(widgets, "image"); spacer(widgets);*/ hline(widgets); + /* TODO: enhance this later to work for multiple segments label(widgets, "Export shape:"); shapeRadios = radios(widgets, SHAPES); // TODO: Enable when available @@ -156,13 +161,15 @@ public class ExportDialog extends Dialog { label(widgets, "Object description:"); descriptionText = text(widgets, ""); spacer(widgets); + */ + // 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); effectCombo = combo(widgets, ROLLOVER_EFFECTS); spacer(widgets); - hline(widgets); - openButton = checkbox(widgets, - "Open image map in browser after export completes", true, 3); - + //hline(widgets); // Button bar expander(buttons); cancelButton = new Button(buttons, SWT.PUSH); 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 1ed82c1..83b8054 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java @@ -107,7 +107,7 @@ public class Exporter { this.exportShape = shape; } - public void export(File folder, List masks) throws IOException, ExportException { + public void export(File folder, boolean exportHTML, File exportFolder, List masks) throws IOException, ExportException { // Create a zip file for saving imageMaps file = new File(folder,zipFile); @@ -209,8 +209,8 @@ public class Exporter { break; } - area.setAlt(objectDescription); - area.setHref(objectLink); + //area.setAlt(objectDescription); + //area.setHref(objectLink); if (effect != null) { @@ -220,7 +220,8 @@ public class Exporter { imageName, mask.layerNumber)); area.addAttr("onmouseout", String.format("rollover(document.%s, image0)", imageName)); - area.addAttr("title",mask.ontologyTerm.getName()); + area.addAttr("title",mask.ontologyTerm.getName() + + " {" + mask.ontologyTerm.getAccessionId() + "}"); } map.addArea(area); @@ -241,7 +242,11 @@ public class Exporter { map.exportToFile(out);*/ // Exporting to Folder - map.exportToFile(new File(folder, htmlFile)); + 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) + } } finally { @@ -273,7 +278,7 @@ public class Exporter { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); - Element rootElement = document.createElement("Image_data"); + Element rootElement = document.createElement("image_data"); document.appendChild(rootElement); Element imageElement = document.createElement("image_filename"); @@ -281,7 +286,7 @@ public class Exporter { Element speciesElement = document.createElement("species"); speciesElement.setAttribute("name", SegmentationView.speciesCombo.getText()); - speciesElement.setAttribute("ubio_id", "Ubio:12345"); + speciesElement.setAttribute("ubio_id", (SegmentationView.speciesCombo.getData(SegmentationView.speciesCombo.getText())).toString()); rootElement.appendChild(speciesElement); Element curatorElement = document.createElement("curator_name"); @@ -304,7 +309,7 @@ public class Exporter { Element segmentElement = document.createElement("segment"); segmentsElement.appendChild(segmentElement); - String url = "url"; + String url = ""; Element urlElem = document.createElement("url"); urlElem.appendChild(document.createTextNode(url)); segmentElement.appendChild(urlElem); diff --git a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java index 862d974..0eafac8 100644 --- a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java +++ b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java @@ -106,7 +106,7 @@ public class Labels for(int i = 0 ; i < nlist.getLength();i++) { //get the employee element Element el = (Element)nlist.item(i); - namBankId = new String(DatatypeConverter.parseBase64Binary(getTagValue("namebankID", el))); + namBankId = getTagValue("namebankID", el); nameBankString = new String(DatatypeConverter.parseBase64Binary(getTagValue("nameString", el))); SpeciesTerm species = new SpeciesTerm(nameBankString,namBankId); speciesTerms.add(species); diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 0fdcf1b..2483b25 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -18,8 +18,6 @@ import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; import java.util.logging.*; @@ -225,7 +223,7 @@ public class SegmentationView extends Composite { m.add(new Separator()); m.add(getAction(Tool.AutoApply)); m.add(getAction(Tool.Apply)); - m.add(getAction(Tool.SegmenterOptions)); + //m.add(getAction(Tool.SegmenterOptions)); m.update(true); } @@ -253,16 +251,24 @@ public class SegmentationView extends Composite { * TODO: then recall this method from the Open (Open Recent), Go Next, Go Previous, and Close...when you add Close */ public void resetView() { - comboLabel.deselectAll(); Tool.OperatingMode.action.setChecked(false); resetViewSelectionToolbar(painters.get("Combined")); + // clear metadata + comboLabel.deselectAll(); + comboLabel.setEnabled(false); clearTermDetailTable(); clearTermSynonymTable(); collectionId.setText(""); comment.setText(""); curatorCombo.deselectAll(); speciesCombo.deselectAll(); - + // clear segment data (term labels, layers, image coords) + if (view.getContext() != null) { + ArrayList segMasks = view.getContext().getSegmentationMasks(); + if (segMasks.size() > 0) + segMasks.clear(); + SegmentationMask.numberOfLayers = 0; // reset the layer counter for the next image + } } private String parseAccessionIdFromComboLabel(Combo comboLabel) { @@ -1158,9 +1164,9 @@ public class SegmentationView extends Composite { case AssignButton: assignLabel(); break; - case SegmenterOptions: - showSegmenterOptions(); - break; + //case SegmenterOptions: + //showSegmenterOptions(); + //break; } updateToolStates(); @@ -1190,7 +1196,7 @@ public class SegmentationView extends Composite { Tool.OperatingMode.action.setChecked(getLabelMode()); Tool.Clear.action.setEnabled(canClear()); Tool.AutoApply.action.setChecked(auto); - Tool.SegmenterOptions.action.setEnabled(canShowOptions()); + //Tool.SegmenterOptions.action.setEnabled(canShowOptions()); Tool.Foreground.action.setEnabled(!getLabelMode() && canZoomIn()); Tool.Background.action.setEnabled(!getLabelMode() && canZoomIn()); Tool.OperatingMode.action.setEnabled(canZoomIn()); @@ -1198,7 +1204,7 @@ public class SegmentationView extends Composite { // Always enabled if view enabled Tool.SetBrushSize.action.setEnabled(true); - Tool.SegmenterOptions.action.setEnabled(true); + //Tool.SegmenterOptions.action.setEnabled(true); Tool.SetPainter.action.setEnabled(true); Tool.Repaint.action.setEnabled(true); Tool.AutoApply.action.setEnabled(true); diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index 89ea600..f75458f 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -9,6 +9,7 @@ import ie.dcu.util.FileUtils; import java.io.*; import java.util.ArrayList; +import java.util.logging.Logger; import java.util.zip.*; import javax.xml.bind.DatatypeConverter; @@ -38,6 +39,8 @@ import org.xml.sax.InputSource; */ public class SegmentationContext { + private static final Logger log = Logger.getLogger(SegmentationContext.class.getName()); // Logger + /** * The file extension given to a this object when it is saved on a disk */ @@ -541,6 +544,8 @@ public class SegmentationContext { } SegmentationView.speciesCombo.setText(speciesTermName); SegmentationView.speciesCombo.setData(speciesTermName,speciesTermId); + /*log.info(SegmentationView.speciesCombo.getText() + ":" + + (SegmentationView.speciesCombo.getData(speciesTermName)).toString());*/ // TEST SegmentationView.curatorCombo.setText(curatorName); SegmentationView.collectionId.setText(collectionId); SegmentationView.comment.setText(comment); -- 2.34.1