Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
index f66f280bc8..250ccc24e9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Christoph Läubrich - Bug 513185
*******************************************************************************/
package org.eclipse.swt.layout;
@@ -145,7 +146,7 @@ protected Point computeSize (Composite composite, int wHint, int hHint, boolean
}
Point computeChildSize (Control control, int wHint, int hHint, boolean flushCache) {
- FillData data = (FillData)control.getLayoutData ();
+ FillData data = validateLayoutData(control, -1);
if (data == null) {
data = new FillData ();
control.setLayoutData (data);
@@ -172,8 +173,10 @@ Point computeChildSize (Control control, int wHint, int hHint, boolean flushCach
@Override
protected boolean flushCache (Control control) {
- Object data = control.getLayoutData();
- if (data != null) ((FillData)data).flushCache();
+ FillData data = validateLayoutData(control, -1);
+ if (data != null) {
+ data.flushCache();
+ }
return true;
}
@@ -198,6 +201,7 @@ protected void layout (Composite composite, boolean flushCache) {
int y = rect.y + marginHeight, cellWidth = width / count;
for (int i=0; i<count; i++) {
Control child = children [i];
+ validateLayoutData(child, i);
int childWidth = cellWidth;
if (i == 0) {
childWidth += extra / 2;
@@ -213,6 +217,7 @@ protected void layout (Composite composite, boolean flushCache) {
int y = rect.y + marginHeight, extra = height % count;
for (int i=0; i<count; i++) {
Control child = children [i];
+ validateLayoutData(child, i);
int childHeight = cellHeight;
if (i == 0) {
childHeight += extra / 2;
@@ -225,6 +230,21 @@ protected void layout (Composite composite, boolean flushCache) {
}
}
+private FillData validateLayoutData(Control control, int index) {
+ if (control == null) {
+ throw new SWTException(SWT.ERROR_NULL_ARGUMENT, "control can't be null");
+ }
+ Object layoutData = control.getLayoutData();
+ if (layoutData == null) {
+ return null;
+ }
+ if (layoutData instanceof FillData) {
+ return (FillData) layoutData;
+ }
+ throw new SWTException(SWT.ERROR_INVALID_ARGUMENT, "Child#" + index + " of type " + control.getClass().getName()
+ + " has illegal layout data type " + layoutData.getClass().getName());
+}
+
/**
* Returns a string containing a concise, human-readable
* description of the receiver.

Back to the top