From 86cea92ca1e9bb9a581983a38f82240ca5719e03 Mon Sep 17 00:00:00 2001 From: drdev Date: Sat, 18 Jan 2014 02:53:32 +0000 Subject: [PATCH] Truncate item manager caption if not enough room for it --- .../java/forge/gui/toolbox/LayoutHelper.java | 34 +++++++++++++------ .../gui/toolbox/itemmanager/ItemManager.java | 11 ++++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/forge-gui/src/main/java/forge/gui/toolbox/LayoutHelper.java b/forge-gui/src/main/java/forge/gui/toolbox/LayoutHelper.java index 7a56e4b2477..df9e74a5099 100644 --- a/forge-gui/src/main/java/forge/gui/toolbox/LayoutHelper.java +++ b/forge-gui/src/main/java/forge/gui/toolbox/LayoutHelper.java @@ -14,7 +14,7 @@ public final class LayoutHelper { parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); } - + /** * Layout component to fill remaining vertical space of parent * @param comp @@ -23,7 +23,7 @@ public final class LayoutHelper { newLine(); //start new line if needed include(comp, parentWidth, parentHeight - y); } - + /** * Layout component to fill remaining horizontal space of current line * @param comp @@ -55,7 +55,7 @@ public final class LayoutHelper { public void include(final JComponent comp, float widthPercent, int height) { include(comp, Math.round(parentWidth * widthPercent), height); } - + /** * Include component in layout with a fixed width and percentage height * @param comp @@ -65,7 +65,7 @@ public final class LayoutHelper { public void include(final JComponent comp, int width, float heightPercent) { include(comp, width, Math.round(parentHeight * heightPercent)); } - + /** * Include component in layout with a percentage width and height * @param comp @@ -75,7 +75,7 @@ public final class LayoutHelper { public void include(final JComponent comp, float widthPercent, float heightPercent) { include(comp, Math.round(parentWidth * widthPercent), Math.round(parentHeight * heightPercent)); } - + /** * Include component in layout with a fixed width and height * @param comp @@ -84,7 +84,7 @@ public final class LayoutHelper { */ public void include(final JComponent comp, int width, int height) { if (width <= 0 || height <= 0) { return; } - + if (x + width > parentWidth) { newLine(); if (width > parentWidth) { @@ -101,7 +101,7 @@ public final class LayoutHelper { lineBottom = y + height; } } - + /** * Offset current layout helper position * @param dx @@ -114,7 +114,7 @@ public final class LayoutHelper { /** * Start new line of layout - */ + */ public void newLine() { if (lineBottom == y) { return; } x = 0; @@ -124,13 +124,13 @@ public final class LayoutHelper { /** * Start new line of layout - */ + */ public void newLine(int dy) { x = 0; y = lineBottom + 3 + dy; lineBottom = y; } - + /** * @return width of parent */ @@ -144,4 +144,18 @@ public final class LayoutHelper { public int getParentHeight() { return parentHeight; } + + /** + * @return current X + */ + public int getX() { + return x; + } + + /** + * @return current Y + */ + public int getY() { + return y; + } } diff --git a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/ItemManager.java b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/ItemManager.java index 722c010167b..f9147fa1673 100644 --- a/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/ItemManager.java +++ b/forge-gui/src/main/java/forge/gui/toolbox/itemmanager/ItemManager.java @@ -319,8 +319,15 @@ public abstract class ItemManager extends JPanel { helper.fillLine(this.pnlButtons, showButtonPanel ? buttonPanelHeight : 1); //just show border if no buttons } helper.include(this.btnFilters, 61, FTextField.HEIGHT); - helper.include(this.lblCaption, this.lblCaption.getAutoSizeWidth(), FTextField.HEIGHT); - helper.fillLine(this.lblRatio, FTextField.HEIGHT, this.cbViews.getAutoSizeWidth()); //leave room for cbViews + int captionWidth = this.lblCaption.getAutoSizeWidth(); + int ratioWidth = this.lblRatio.getAutoSizeWidth(); + int cbViewsWidth = this.cbViews.getAutoSizeWidth(); + int availableCaptionWidth = helper.getParentWidth() - cbViewsWidth - ratioWidth - helper.getX() - 9; + if (captionWidth > availableCaptionWidth) { //truncate caption if not enough room for it + captionWidth = availableCaptionWidth; + } + helper.include(this.lblCaption, captionWidth, FTextField.HEIGHT); + helper.fillLine(this.lblRatio, FTextField.HEIGHT, cbViewsWidth); //leave room for cbViews helper.fillLine(this.cbViews.getComponent(), FTextField.HEIGHT); helper.fill(this.viewScroller); }