summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeronika Irvine <veronika>2004-12-01 19:23:02 +0000
committerVeronika Irvine <veronika>2004-12-01 19:23:02 +0000
commitee9860c5e24a0e20cec5cc9efeac2ee1c611ff95 (patch)
treebd860f02bdd89b809db6683fbba038ab8654dc39
parentd6e73574e552f265f3541ca90078668e479b7cf1 (diff)
downloadeclipse.platform.swt-ee9860c5e24a0e20cec5cc9efeac2ee1c611ff95.tar.gz
eclipse.platform.swt-ee9860c5e24a0e20cec5cc9efeac2ee1c611ff95.tar.xz
eclipse.platform.swt-ee9860c5e24a0e20cec5cc9efeac2ee1c611ff95.zip
Use SashFormData instead of storing ratios as a Long in control data
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormData.java27
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java22
3 files changed, 74 insertions, 17 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
index 29965749b3..be519bc7b7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
@@ -42,7 +42,6 @@ public class SashForm extends Composite {
Control maxControl = null;
Listener sashListener;
static final int DRAG_MINIMUM = 20;
- static final String LAYOUT_RATIO = "layout ratio"; //$NON-NLS-1$
/**
* Constructs a new instance of this class given its parent
@@ -133,9 +132,9 @@ public int[] getWeights() {
Control[] cArray = getControls(false);
int[] ratios = new int[cArray.length];
for (int i = 0; i < cArray.length; i++) {
- Long ratio = (Long)cArray[i].getData(LAYOUT_RATIO);
- if (ratio != null) {
- ratios[i] = (int)(ratio.longValue() * 1000 >> 16);
+ Object data = cArray[i].getLayoutData();
+ if (data != null && data instanceof SashFormData) {
+ ratios[i] = (int)(((SashFormData)data).weight * 1000 >> 16);
} else {
ratios[i] = 200;
}
@@ -184,8 +183,18 @@ void onDragSash(Event event) {
event.doit = false;
return;
}
- c1.setData(LAYOUT_RATIO, new Long((((long)b1.width << 16) + area.width - 1) / area.width));
- c2.setData(LAYOUT_RATIO, new Long((((long)b2.width << 16) + area.width - 1) / area.width));
+ Object data1 = c1.getLayoutData();
+ if (data1 == null || !(data1 instanceof SashFormData)) {
+ data1 = new SashFormData();
+ c1.setLayoutData(data1);
+ }
+ Object data2 = c2.getLayoutData();
+ if (data2 == null || !(data2 instanceof SashFormData)) {
+ data2 = new SashFormData();
+ c2.setLayoutData(data2);
+ }
+ ((SashFormData)data1).weight = (((long)b1.width << 16) + area.width - 1) / area.width;
+ ((SashFormData)data2).weight = (((long)b2.width << 16) + area.width - 1) / area.width;
} else {
int shift = event.y - sashBounds.y;
b1.height += shift;
@@ -196,8 +205,18 @@ void onDragSash(Event event) {
event.doit = false;
return;
}
- c1.setData(LAYOUT_RATIO, new Long((((long)b1.height << 16) + area.height - 1) / area.height));
- c2.setData(LAYOUT_RATIO, new Long((((long)b2.height << 16) + area.height - 1) / area.height));
+ Object data1 = c1.getLayoutData();
+ if (data1 == null || !(data1 instanceof SashFormData)) {
+ data1 = new SashFormData();
+ c1.setLayoutData(data1);
+ }
+ Object data2 = c2.getLayoutData();
+ if (data2 == null || !(data2 instanceof SashFormData)) {
+ data2 = new SashFormData();
+ c2.setLayoutData(data2);
+ }
+ ((SashFormData)data1).weight = (((long)b1.height << 16) + area.height - 1) / area.height;
+ ((SashFormData)data2).weight = (((long)b2.height << 16) + area.height - 1) / area.height;
}
if (event.detail != SWT.DRAG) {
c1.setBounds(b1);
@@ -335,7 +354,12 @@ public void setWeights(int[] weights) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
for (int i = 0; i < cArray.length; i++) {
- cArray[i].setData(LAYOUT_RATIO, new Long((((long)weights[i] << 16) + total - 1) / total));
+ Object data = cArray[i].getLayoutData();
+ if (data == null || !(data instanceof SashFormData)) {
+ data = new SashFormData();
+ cArray[i].setLayoutData(data);
+ }
+ ((SashFormData)data).weight = (((long)weights[i] << 16) + total - 1) / total;
}
layout(false);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormData.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormData.java
new file mode 100644
index 0000000000..cfd88c61f5
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormData.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.custom;
+
+class SashFormData {
+
+ long weight;
+
+String getName () {
+ String string = getClass ().getName ();
+ int index = string.lastIndexOf ('.');
+ if (index == -1) return string;
+ return string.substring (index + 1, string.length ());
+}
+
+public String toString () {
+ return getName()+" {weight="+weight+"}"; //$NON-NLS-2$
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
index 4149d2e16e..2ebaca8d2e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
@@ -55,11 +55,14 @@ protected Point computeSize(Composite composite, int wHint, int hHint, boolean f
long[] ratios = new long[cArray.length];
long total = 0;
for (int i = 0; i < cArray.length; i++) {
- Long ratio = (Long)cArray[i].getData(SashForm.LAYOUT_RATIO);
- if (ratio != null) {
- ratios[i] = ratio.longValue();
+ Object data = cArray[i].getLayoutData();
+ if (data != null && data instanceof SashFormData) {
+ ratios[i] = ((SashFormData)data).weight;
} else {
- ratios[i] = ((200 << 16) + 999) / 1000;
+ data = new SashFormData();
+ cArray[i].setLayoutData(data);
+ ((SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
+
}
total += ratios[i];
}
@@ -135,11 +138,14 @@ protected void layout(Composite composite, boolean flushCache) {
long[] ratios = new long[controls.length];
long total = 0;
for (int i = 0; i < controls.length; i++) {
- Long ratio = (Long)controls[i].getData(SashForm.LAYOUT_RATIO);
- if (ratio != null) {
- ratios[i] = ratio.longValue();
+ Object data = controls[i].getLayoutData();
+ if (data != null && data instanceof SashFormData) {
+ ratios[i] = ((SashFormData)data).weight;
} else {
- ratios[i] = ((200 << 16) + 999) / 1000;
+ data = new SashFormData();
+ controls[i].setLayoutData(data);
+ ((SashFormData)data).weight = ratios[i] = ((200 << 16) + 999) / 1000;
+
}
total += ratios[i];
}