[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [albireo-dev] size/layout platform testing
|
| > So, if there's a problem with infinite propagation, we are currently not
| > preventing it today (i.e. the inhibit flag is not preventing it). It's
| > not clear if we can or if we need to.
|
| Good point. We should produce an example where this infinite loop actually
| occurs, and then fix it by moving the 'inhibit' logic into the opposite
| notification (AWT -> SWT).
I'm committing this new view.
Index: plugin.xml
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.examples.plugin/plugin.xml,v
retrieving revision 1.15
diff -c -3 -r1.15 plugin.xml
*** plugin.xml 27 Feb 2008 06:23:33 -0000 1.15
--- plugin.xml 27 Feb 2008 17:05:06 -0000
***************
*** 56,61 ****
--- 56,67 ----
name="Resize Flickering">
</view>
<view
+ class="org.eclipse.albireo.examples.plugin.views.StubbornResizeView"
+ id="org.eclipse.albireo.examples.plugin.stubbornResize"
+ category="org.eclipse.albireo"
+ name="Resize fixed-size">
+ </view>
+ <view
class="org.eclipse.albireo.examples.plugin.views.FocusExampleView1"
id="org.eclipse.albireo.examples.plugin.focus1"
category="org.eclipse.albireo"
=========================== StubbornResizeView.java ===========================
package org.eclipse.albireo.examples.plugin.views;
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JLabel;
import org.eclipse.albireo.core.SwingControl;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
/**
* This view tests what happens when a JComponent is not cooperative
* with SWT regarding its size. If SWT says "your size is 100x100"
* and the Swing component says "my size is 50x50", what happens?
*/
public class StubbornResizeView extends ViewPart {
public static String ID = "org.eclipse.albireo.examples.plugin.stubbornResize"; //$NON-NLS-1$
private SwingControl[][] swingControl;
public void createPartControl(final Composite parent) {
parent.setLayout(new GridLayout(2, true));
swingControl = new SwingControl[2][];
for (int i = 0; i < 2; i++) {
swingControl[i] = new SwingControl[2];
for (int j = 0; j < 2; j++) {
swingControl[i][j] =
new SwingControl(parent, SWT.NONE) {
protected JComponent createSwingComponent() {
class MyLabel extends JLabel {
MyLabel(String text) {
super(text);
}
private Dimension fixedSize;
public Dimension getMinimumSize() {
if (fixedSize != null)
return new Dimension(fixedSize);
else
return super.getMinimumSize();
}
public Dimension getPreferredSize() {
if (fixedSize != null)
return new Dimension(fixedSize);
else
return super.getPreferredSize();
}
public Dimension getMaximumSize() {
if (fixedSize != null)
return new Dimension(fixedSize);
else
return super.getMaximumSize();
}
public void setFixedSize(Dimension size) {
fixedSize = size;
}
}
MyLabel label = new MyLabel("fixed-size");
label.setFixedSize(label.getPreferredSize());
return label;
}
// Overridden to make the width and the height quite arbitrary.
// You can comment this out.
public Point computeSize(int widthHint, int heightHint, boolean changed) {
Point size = super.computeSize(widthHint, heightHint, changed);
if (false) {
// Make it bigger than necessary.
size.x += ((size.x % 20) != 0 ? 20 - (size.x % 20) : 0);
size.y += ((size.y % 20) != 0 ? 20 - (size.y % 20) : 0);
return size;
} else {
// Make it smaller then necessary.
return new Point(40, 8);
}
}
public Composite getLayoutableAncestor() {
return parent;
}
};
}
}
Button layoutSWTButton = new Button(parent, SWT.PUSH);
layoutSWTButton.setText("SWT-Layout");
GridData data = new GridData();
data.horizontalAlignment = SWT.LEAD;
data.verticalAlignment = SWT.CENTER;
layoutSWTButton.setLayoutData(data);
}
public void setFocus() {
swingControl[1][1].setFocus();
}
}