From 4f43f5b1c8baf323e5d66bec96668d31fc79b0c3 Mon Sep 17 00:00:00 2001 From: Spayralbe Date: Wed, 22 Nov 2023 11:33:11 +0100 Subject: [PATCH 1/2] Fix image crop when using stem table --- .../java/org/ohdsi/rabbitInAHat/MappingPanel.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java index 0cfd1e0b..5b4a0160 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -62,6 +62,8 @@ public class MappingPanel extends JPanel implements MouseListener, MouseMotionLi public static final int MIN_SPACE_BETWEEN_COLUMNS = 200; public static final int ARROW_START_WIDTH = 50; public static final int BORDER_HEIGHT = 25; + // Extra margin between header and first item when using stem table + public static final int STEM_HEIGHT_MARGIN = ITEM_HEIGHT / 2; private int sourceX; private int cdmX; @@ -240,7 +242,7 @@ private void setLabeledRectanglesLocation(List components, int int y = HEADER_HEIGHT + HEADER_TOP_MARGIN; if (ObjectExchange.etl.hasStemTable()) { // Move all non-stem items - y = HEADER_TOP_MARGIN + ITEM_HEIGHT; + y += STEM_HEIGHT_MARGIN; } for (LabeledRectangle component : components) { // Exception for laying out the stem table @@ -264,8 +266,11 @@ private void setLabeledRectanglesLocation(List components, int public Dimension getMinimumSize() { Dimension dimension = new Dimension(); dimension.width = 2 * (ITEM_WIDTH + MARGIN) + MIN_SPACE_BETWEEN_COLUMNS; - dimension.height = Math.min(HEADER_HEIGHT + HEADER_TOP_MARGIN + Math.max(sourceComponents.size(), cdmComponents.size()) * (ITEM_HEIGHT + MARGIN), - maxHeight); + int componentsHeight = Math.max(sourceComponents.size(), cdmComponents.size()) * (ITEM_HEIGHT + MARGIN); + dimension.height = Math.min(HEADER_HEIGHT + HEADER_TOP_MARGIN + componentsHeight, maxHeight); + if (ObjectExchange.etl.hasStemTable()) { + dimension.height += STEM_HEIGHT_MARGIN; + } return dimension; } From 5c346651b6f6abeafb3567900bc8abc421f1592c Mon Sep 17 00:00:00 2001 From: Spayralbe Date: Mon, 4 Dec 2023 17:40:42 +0100 Subject: [PATCH 2/2] Decrease size of table panel when using stem table. Without this change, the table panel height is always higher than needed (when using stem table), because the stem table is counted as one of the items in the components list. It is however shown separately at the top, which is already accounted for by the stem table margin. --- .../main/java/org/ohdsi/rabbitInAHat/MappingPanel.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java index 5b4a0160..2a935797 100644 --- a/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java +++ b/rabbitinahat/src/main/java/org/ohdsi/rabbitInAHat/MappingPanel.java @@ -266,10 +266,17 @@ private void setLabeledRectanglesLocation(List components, int public Dimension getMinimumSize() { Dimension dimension = new Dimension(); dimension.width = 2 * (ITEM_WIDTH + MARGIN) + MIN_SPACE_BETWEEN_COLUMNS; - int componentsHeight = Math.max(sourceComponents.size(), cdmComponents.size()) * (ITEM_HEIGHT + MARGIN); + int maxComponentsSize = Math.max(sourceComponents.size(), cdmComponents.size()); + int componentsHeight = maxComponentsSize * (ITEM_HEIGHT + MARGIN); dimension.height = Math.min(HEADER_HEIGHT + HEADER_TOP_MARGIN + componentsHeight, maxHeight); + if (ObjectExchange.etl.hasStemTable()) { dimension.height += STEM_HEIGHT_MARGIN; + // For the table mapping panel, deduct the stem table from the items (as it's not shown as a normal item in the list) + boolean isTablesPanel = cdmComponents.stream().allMatch(n -> (n.getItem() instanceof Table)); + if (!cdmComponents.isEmpty() && isTablesPanel) { + dimension.height -= (ITEM_HEIGHT + MARGIN); + } } return dimension;