aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2008-12-08 13:43:03 +0000
committerArtur Signell <artur.signell@itmill.com>2008-12-08 13:43:03 +0000
commit6ca7337c6d09f03e54f090030f25d9ec1ffdf6ba (patch)
tree61161e5c1109cb61827b3ea971450f28f357ea2b
parentd6d3c709063147bf1cd46d7de5bee94ee3ee8472 (diff)
downloadvaadin-framework-6ca7337c6d09f03e54f090030f25d9ec1ffdf6ba.tar.gz
vaadin-framework-6ca7337c6d09f03e54f090030f25d9ec1ffdf6ba.zip
Fix for #2294 - Sanity check for setComponentAlignment
svn changeset:6120/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2294.java61
-rw-r--r--src/com/itmill/toolkit/ui/AbstractOrderedLayout.java11
2 files changed, 69 insertions, 3 deletions
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2294.java b/src/com/itmill/toolkit/tests/tickets/Ticket2294.java
new file mode 100644
index 0000000000..c77ee155b5
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2294.java
@@ -0,0 +1,61 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Layout.AlignmentHandler;
+
+public class Ticket2294 extends Application {
+
+ public void init() {
+ Window w = new Window(getClass().getSimpleName());
+ setMainWindow(w);
+ // setTheme("tests-tickets");
+ createUI((OrderedLayout) w.getLayout());
+ }
+
+ private void createUI(OrderedLayout layout) {
+ Label label1 = new Label();
+ Label label2 = null;
+ Label label3 = new Label();
+ String result1 = "";
+ String result2 = "";
+ String result3 = "";
+
+ layout.addComponent(label1);
+ try {
+ layout.setComponentAlignment(label1,
+ AlignmentHandler.ALIGNMENT_LEFT,
+ AlignmentHandler.ALIGNMENT_BOTTOM);
+ result1 = "OK";
+ } catch (Exception e) {
+ result1 = "FAILED: " + e.getMessage();
+ }
+
+ try {
+ layout.setComponentAlignment(label2,
+ AlignmentHandler.ALIGNMENT_LEFT,
+ AlignmentHandler.ALIGNMENT_BOTTOM);
+ result2 = "FAILED, no exception";
+ } catch (IllegalArgumentException e) {
+ result2 = "OK";
+ } catch (Exception e) {
+ result2 = "FAILED: " + e.getMessage();
+ }
+
+ try {
+ layout.setComponentAlignment(label3,
+ AlignmentHandler.ALIGNMENT_LEFT,
+ AlignmentHandler.ALIGNMENT_BOTTOM);
+ result3 = "FAILED, no exception";
+ } catch (IllegalArgumentException e) {
+ result3 = "OK";
+ } catch (Exception e) {
+ result3 = "FAILED: " + e.getMessage();
+ }
+
+ label1.setValue("Result 1: " + result1 + ", result 2: " + result2
+ + ", result 3: " + result3);
+ }
+}
diff --git a/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java b/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
index cb3d277222..fe9d897d71 100644
--- a/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
+++ b/src/com/itmill/toolkit/ui/AbstractOrderedLayout.java
@@ -235,9 +235,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
*/
public void setComponentAlignment(Component childComponent,
int horizontalAlignment, int verticalAlignment) {
- componentToAlignment.put(childComponent, new Integer(
- horizontalAlignment + verticalAlignment));
- requestRepaint();
+ if (components.contains(childComponent)) {
+ componentToAlignment.put(childComponent, new Integer(
+ horizontalAlignment + verticalAlignment));
+ requestRepaint();
+ } else {
+ throw new IllegalArgumentException(
+ "Component must be added to layout before using setComponentAlignment()");
+ }
}
/*