#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
}
- private SegmentationView createView(Composite parent) {
+ public SegmentationView createView(Composite parent) {
// Load props
Properties props;
// 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));
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.*;
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);
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 {
// 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());
//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();
// 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;
*/
// 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);
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);
}
}
});
-
+
+ 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;
}
}
});
+
+ 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;
}
}
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();
} else if (text.equals("Highlight Object")) {
effect = RolloverEffect.brightenForeground();
}
- }
+ //}
return effect;
}
map.setSpeciesName(SegmentationView.speciesCombo.getText());
map.setCollectionId(SegmentationView.collectionId.getText());
map.setComments(SegmentationView.comment.getText());
-
+
List<String> preloads = new ArrayList<String>();
map.addPreload(imageFile);
}
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;
// 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");
//area.setHref(objectLink);
if (effect != null) {
-
-
area.addAttr("onmouseover",
String.format("rollover(document.%s, image%s)",
imageName, mask.layerNumber));
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
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");
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";
String filename = String.format("%s-%d.png", basename, layerNumber);
preloads.add(filename);
}
- }
+ //}
return preloads;
}
}
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;