From 23caef4e6e8a52cf3efaf6de73ab35cb6ebbd8b4 Mon Sep 17 00:00:00 2001
From: kaloyane <kaloyane>
Date: Mon, 5 Dec 2011 14:03:19 +0000
Subject: [PATCH] [LMS-2516] fixed: set plate/heatmap legend to auto-height

SVN: 23874
---
 .../detailviewers/PlateStyleSetter.java       |  2 ++
 .../heatmaps/HeatmapScaleFactory.java         |  7 +++++--
 .../detailviewers/heatmaps/PlateLayouter.java | 21 ++++++++++++-------
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/PlateStyleSetter.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/PlateStyleSetter.java
index 5cda62a0904..bbaed2b8590 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/PlateStyleSetter.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/PlateStyleSetter.java
@@ -27,6 +27,8 @@ public class PlateStyleSetter
 {
     public static final int WELL_BOX_SIZE_PX = 20;
 
+    public static final int WELL_SPACING_PX = 2;
+
     public static Component setWellStyle(Component component)
     {
         setPointerCursor(component);
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapScaleFactory.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapScaleFactory.java
index 50b75b9505b..f4a26bb547d 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapScaleFactory.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapScaleFactory.java
@@ -12,6 +12,7 @@ import com.extjs.gxt.ui.client.widget.layout.TableData;
 import com.extjs.gxt.ui.client.widget.layout.TableLayout;
 import com.google.gwt.user.client.ui.Widget;
 
+import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers.PlateStyleSetter;
 import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers.heatmaps.dto.Color;
 import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers.heatmaps.dto.HeatmapScaleElement;
 
@@ -34,6 +35,7 @@ class HeatmapScaleFactory
         container.setLayout(new TableLayout(2));
         container.setBorders(false);
         container.setScrollMode(Scroll.NONE);
+        container.setAutoHeight(true);
         boolean isFirstLabel = firstLabelOrNull != null;
         if (isFirstLabel)
         {
@@ -78,8 +80,9 @@ class HeatmapScaleFactory
         {
             box.setStyleAttribute("background-color", color.getHexColor());
         }
-        box.setWidth("2em");
-        box.setHeight("2em");
+        int size = PlateStyleSetter.WELL_BOX_SIZE_PX + PlateStyleSetter.WELL_SPACING_PX;
+        box.setWidth("" + size);
+        box.setHeight("" + size);
         return box;
     }
 
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
index e23f7d1e82e..153c0986e15 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
@@ -16,6 +16,8 @@
 
 package ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers.heatmaps;
 
+import static ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers.PlateStyleSetter.WELL_SPACING_PX;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -95,8 +97,6 @@ public class PlateLayouter
 
     private static final int HEATMAP_KIND_COMBOBOX_CHOOSER_WIDTH_PX = 200;
 
-    private static final int WELL_SPACING_PX = 2;
-
     // ------- internal fixed state
 
     private final PlateLayouterModel model;
@@ -191,6 +191,7 @@ public class PlateLayouter
                 {
                     legendContainer.removeAll();
                     legendContainer.add(legend);
+                    legendContainer.setAutoHeight(true);
                     legendContainer.layout();
                 }
 
@@ -259,11 +260,10 @@ public class PlateLayouter
         plateContainer.setLayout(new ColumnLayout());
 
         int legendWidth = 200;
-        int topChoosersHeight = 70; // height of things above plate layout in this container
         int plateWidth = getPlateMatrixPixelWidth(renderedWells);
-        int plateHeight = getPlateMatrixPixelHeight(renderedWells);
         int totalWidth = plateWidth + legendWidth;
-        plateContainer.setSize(totalWidth, plateHeight);
+        plateContainer.setAutoHeight(true);
+        plateContainer.setWidth(totalWidth);
 
         plateContainer.add(renderPlateLayout(renderedWells));
 
@@ -275,14 +275,19 @@ public class PlateLayouter
         plateContainer.add(legendContainer);
 
         container.add(plateContainer);
-        container.setSize(totalWidth, plateHeight + topChoosersHeight);
+        container.setAutoHeight(true);
+        container.setWidth(totalWidth);
         return container;
     }
 
     private static int getPlateMatrixPixelHeight(Component[][] renderedWells)
     {
-        int boxes = renderedWells.length + 1;
-        return WELL_SPACING_PX * (boxes + 1) + PlateStyleSetter.WELL_BOX_SIZE_PX * boxes;
+        return getPlateMatrixPixelHeight(renderedWells.length + 1);
+    }
+
+    private static int getPlateMatrixPixelHeight(int numRows)
+    {
+        return WELL_SPACING_PX * (numRows + 1) + PlateStyleSetter.WELL_BOX_SIZE_PX * numRows;
     }
 
     private static int getPlateMatrixPixelWidth(Component[][] renderedWells)
-- 
GitLab