diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ResolutionChooser.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ResolutionChooser.java index 14aedc6ddf3480cf3e9ac5317dbe77546f58533d..74f17340136aa198333b355e3f9b50f19cbf58aa 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ResolutionChooser.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ResolutionChooser.java @@ -16,8 +16,11 @@ package ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers; -import java.util.Collections; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Set; +import java.util.TreeSet; import com.extjs.gxt.ui.client.event.BaseEvent; import com.extjs.gxt.ui.client.event.Events; @@ -40,16 +43,11 @@ public class ResolutionChooser extends LayoutContainer private SimpleModelComboBox<ImageResolution> comboBox; public ResolutionChooser(final IViewContext<IScreeningClientServiceAsync> viewContext, - final List<ImageResolution> resolutions, final ImageResolution defaultResolution) + List<ImageResolution> incomingResolutions, final ImageResolution defaultResolution) { - List<LabeledItem<ImageResolution>> defaultItems = - Collections.singletonList(new LabeledItem<ImageResolution>(null, viewContext - .getMessage(Dict.RESOLUTION_CHOOSER_DEFAULT))); - - this.comboBox = new SimpleModelComboBox<ImageResolution>(viewContext, defaultItems, null); - - Collections.sort(resolutions); + List<ImageResolution> resolutions = prepareResolutions(incomingResolutions); + List<LabeledItem<ImageResolution>> items = new ArrayList<LabeledItem<ImageResolution>>(); if (resolutions != null) { @@ -58,20 +56,65 @@ public class ResolutionChooser extends LayoutContainer String resolutionText = viewContext.getMessage(Dict.RESOLUTION_CHOOSER_RESOLUTION, resolution.getWidth(), resolution.getHeight()); - comboBox.add(new LabeledItem<ImageResolution>(resolution, resolutionText)); + items.add(new LabeledItem<ImageResolution>(resolution, resolutionText)); } } - LabeledItem<ImageResolution> defaultResolutionItem = - comboBox.findModelForVal(defaultResolution); + comboBox = new SimpleModelComboBox<ImageResolution>(viewContext, items, null); + LabeledItem<ImageResolution> defaultResolutionItem = comboBox.findModelForVal(defaultResolution); + if (defaultResolutionItem != null) { comboBox.setSelection(defaultResolutionItem); + } else if (false == items.isEmpty()) + { + comboBox.setSelection(items.get(0)); } add(comboBox); } + private List<ImageResolution> prepareResolutions(List<ImageResolution> resolutions) + { + Set<ImageResolution> allResolutions = new TreeSet<ImageResolution>(resolutions); + maybeAddThumbnailResolution(allResolutions); + return new ArrayList<ImageResolution>(allResolutions); + } + + private void maybeAddThumbnailResolution(Collection<ImageResolution> resolutions) + { + boolean hasThumbnails = false; + + for (ImageResolution resolution : resolutions) + { + if (false == resolution.isOriginal()) + { + hasThumbnails = true; + break; + } + } + + if (false == hasThumbnails) + { + ImageResolution originalResolution = null; + + for (ImageResolution resolution : resolutions) + { + if (resolution.isOriginal()) + { + originalResolution = resolution; + break; + } + } + + if (originalResolution != null) + { + resolutions.add(new ImageResolution(Math.round(originalResolution.getWidth() / 4), Math.round(originalResolution.getHeight() / 4), + false)); + } + } + } + public ImageResolution getResolution() { return comboBox.tryGetChosenItem(); diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/basic/dto/ImageResolution.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/basic/dto/ImageResolution.java index 80b7b769b5a567f7f26d0f13e5e46242027785ab..b026f223aafdc47ee4ca4b0b41f92ca809152136 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/basic/dto/ImageResolution.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/basic/dto/ImageResolution.java @@ -30,16 +30,19 @@ public class ImageResolution implements Serializable, Comparable<ImageResolution private int height; + private boolean isOriginal; + // GWT only @SuppressWarnings("unused") private ImageResolution() { } - public ImageResolution(int width, int height) + public ImageResolution(int width, int height, boolean isOriginal) { this.width = width; this.height = height; + this.isOriginal = isOriginal; } public int getWidth() @@ -52,6 +55,11 @@ public class ImageResolution implements Serializable, Comparable<ImageResolution return height; } + public boolean isOriginal() + { + return isOriginal; + } + @Override public int compareTo(ImageResolution o) { diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/imaging/HCSImageResolutionLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/imaging/HCSImageResolutionLoader.java index ecbece555df538306342d7cf78adcb20c27f1bed..a06df0533e516d6363ec790143eb60e48b373137 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/imaging/HCSImageResolutionLoader.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/imaging/HCSImageResolutionLoader.java @@ -79,7 +79,7 @@ public class HCSImageResolutionLoader implements IImageResolutionLoader for (ImgImageZoomLevelDTO zoomLevel : zoomLevels) { ImageResolution resolution = - new ImageResolution(zoomLevel.getWidth(), zoomLevel.getHeight()); + new ImageResolution(zoomLevel.getWidth(), zoomLevel.getHeight(), zoomLevel.getIsOriginal()); resolutions.add(resolution); }