Truncate item manager caption if not enough room for it

This commit is contained in:
drdev
2014-01-18 02:53:32 +00:00
parent f9178dcff2
commit 86cea92ca1
2 changed files with 33 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ public final class LayoutHelper {
parentWidth = parent.getWidth(); parentWidth = parent.getWidth();
parentHeight = parent.getHeight(); parentHeight = parent.getHeight();
} }
/** /**
* Layout component to fill remaining vertical space of parent * Layout component to fill remaining vertical space of parent
* @param comp * @param comp
@@ -23,7 +23,7 @@ public final class LayoutHelper {
newLine(); //start new line if needed newLine(); //start new line if needed
include(comp, parentWidth, parentHeight - y); include(comp, parentWidth, parentHeight - y);
} }
/** /**
* Layout component to fill remaining horizontal space of current line * Layout component to fill remaining horizontal space of current line
* @param comp * @param comp
@@ -55,7 +55,7 @@ public final class LayoutHelper {
public void include(final JComponent comp, float widthPercent, int height) { public void include(final JComponent comp, float widthPercent, int height) {
include(comp, Math.round(parentWidth * widthPercent), height); include(comp, Math.round(parentWidth * widthPercent), height);
} }
/** /**
* Include component in layout with a fixed width and percentage height * Include component in layout with a fixed width and percentage height
* @param comp * @param comp
@@ -65,7 +65,7 @@ public final class LayoutHelper {
public void include(final JComponent comp, int width, float heightPercent) { public void include(final JComponent comp, int width, float heightPercent) {
include(comp, width, Math.round(parentHeight * heightPercent)); include(comp, width, Math.round(parentHeight * heightPercent));
} }
/** /**
* Include component in layout with a percentage width and height * Include component in layout with a percentage width and height
* @param comp * @param comp
@@ -75,7 +75,7 @@ public final class LayoutHelper {
public void include(final JComponent comp, float widthPercent, float heightPercent) { public void include(final JComponent comp, float widthPercent, float heightPercent) {
include(comp, Math.round(parentWidth * widthPercent), Math.round(parentHeight * heightPercent)); include(comp, Math.round(parentWidth * widthPercent), Math.round(parentHeight * heightPercent));
} }
/** /**
* Include component in layout with a fixed width and height * Include component in layout with a fixed width and height
* @param comp * @param comp
@@ -84,7 +84,7 @@ public final class LayoutHelper {
*/ */
public void include(final JComponent comp, int width, int height) { public void include(final JComponent comp, int width, int height) {
if (width <= 0 || height <= 0) { return; } if (width <= 0 || height <= 0) { return; }
if (x + width > parentWidth) { if (x + width > parentWidth) {
newLine(); newLine();
if (width > parentWidth) { if (width > parentWidth) {
@@ -101,7 +101,7 @@ public final class LayoutHelper {
lineBottom = y + height; lineBottom = y + height;
} }
} }
/** /**
* Offset current layout helper position * Offset current layout helper position
* @param dx * @param dx
@@ -114,7 +114,7 @@ public final class LayoutHelper {
/** /**
* Start new line of layout * Start new line of layout
*/ */
public void newLine() { public void newLine() {
if (lineBottom == y) { return; } if (lineBottom == y) { return; }
x = 0; x = 0;
@@ -124,13 +124,13 @@ public final class LayoutHelper {
/** /**
* Start new line of layout * Start new line of layout
*/ */
public void newLine(int dy) { public void newLine(int dy) {
x = 0; x = 0;
y = lineBottom + 3 + dy; y = lineBottom + 3 + dy;
lineBottom = y; lineBottom = y;
} }
/** /**
* @return width of parent * @return width of parent
*/ */
@@ -144,4 +144,18 @@ public final class LayoutHelper {
public int getParentHeight() { public int getParentHeight() {
return parentHeight; return parentHeight;
} }
/**
* @return current X
*/
public int getX() {
return x;
}
/**
* @return current Y
*/
public int getY() {
return y;
}
} }

View File

@@ -319,8 +319,15 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
helper.fillLine(this.pnlButtons, showButtonPanel ? buttonPanelHeight : 1); //just show border if no buttons helper.fillLine(this.pnlButtons, showButtonPanel ? buttonPanelHeight : 1); //just show border if no buttons
} }
helper.include(this.btnFilters, 61, FTextField.HEIGHT); helper.include(this.btnFilters, 61, FTextField.HEIGHT);
helper.include(this.lblCaption, this.lblCaption.getAutoSizeWidth(), FTextField.HEIGHT); int captionWidth = this.lblCaption.getAutoSizeWidth();
helper.fillLine(this.lblRatio, FTextField.HEIGHT, this.cbViews.getAutoSizeWidth()); //leave room for cbViews 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.fillLine(this.cbViews.getComponent(), FTextField.HEIGHT);
helper.fill(this.viewScroller); helper.fill(this.viewScroller);
} }