From 9f90d60bce81e5ac2a04443ba3acaacaff48652d Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Thu, 8 Oct 2015 10:05:38 +0000 Subject: [PATCH] Fix DesktopTextArea rows behaviour with specified height #PL-6129 --- .../components/DesktopResizableTextArea.java | 19 ++++++++------ .../gui/components/DesktopTextArea.java | 25 ++++++++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopResizableTextArea.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopResizableTextArea.java index 1d461c4c8f..c135dd690a 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopResizableTextArea.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopResizableTextArea.java @@ -14,9 +14,18 @@ import org.dom4j.Element; */ public class DesktopResizableTextArea extends DesktopTextArea implements ResizableTextArea { + protected boolean resizable = false; + protected boolean settingsEnabled = true; + @Override public boolean isResizable() { - return false; + return resizable; + } + + @Override + public void setResizable(boolean resizable) { + this.resizable = resizable; + //Do nothing, because desktop text area is not resizable } @Override @@ -29,11 +38,6 @@ public class DesktopResizableTextArea extends DesktopTextArea implements Resizab //Do nothing, because desktop text area is not resizable } - @Override - public void setResizable(boolean resizable) { - //Do nothing, because desktop text area is not resizable - } - @Override public void addResizeListener(ResizeListener resizeListener) { //Do nothing, because desktop text area is not resizable @@ -56,11 +60,12 @@ public class DesktopResizableTextArea extends DesktopTextArea implements Resizab @Override public boolean isSettingsEnabled() { - return false; + return settingsEnabled; } @Override public void setSettingsEnabled(boolean settingsEnabled) { + this.settingsEnabled = settingsEnabled; //Do nothing, because desktop text area is not resizable } } \ No newline at end of file diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java index a3a38bf5b0..299eb2cb0c 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopTextArea.java @@ -25,6 +25,7 @@ import static javax.swing.KeyStroke.getKeyStroke; public class DesktopTextArea extends DesktopAbstractTextField implements TextArea { protected JComponent composition; + protected int rows; public DesktopTextArea() { setRows(5); @@ -94,11 +95,13 @@ public class DesktopTextArea extends DesktopAbstractTextField impleme @Override public int getRows() { - return impl.getRows(); + return this.rows; } @Override public void setRows(int rows) { + this.rows = 5; + impl.setRows(rows); int minHeight = impl.getPreferredSize().height; @@ -111,6 +114,26 @@ public class DesktopTextArea extends DesktopAbstractTextField impleme composition.setMinimumSize(new Dimension(minWidth, minHeight)); } + @Override + public void setHeight(String height) { + super.setHeight(height); + + if (getHeight() >= 0) { + impl.setRows(1); + } else { + impl.setRows(this.rows); + } + + int minHeight = impl.getPreferredSize().height; + int minWidth = impl.getPreferredSize().width; + + Insets insets = impl.getInsets(); + minWidth += insets.left + insets.right; + minHeight += insets.bottom + insets.top; + + composition.setMinimumSize(new Dimension(minWidth, minHeight)); + } + @Override public int getColumns() { return impl.getColumns();