[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] Size of IFigure in LightweightSystem
|
I have a group where I've set the bounds and I've created a Canvas in its client area. When I query the canvas, I get reasonable sizes:
However, when the paintFigure method is called, the dimension of the client area is only 64x64 rather than the expected 494x59. I've tried setting the constructor of the Figure to a Dimension of 494x59.
Here is some example code that shows the problem. I'd expected the blue rectangle to fill the client area of the group.
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
public class testFigure {
static class ChartFigure extends Figure {
public ChartFigure(Dimension dim) {
setMinimumSize(dim);
System.out.println("Dim:" + dim);
setBounds(new Rectangle(0, 0, dim.width, dim.height));
}
protected void paintFigure(Graphics g) {
Rectangle clientArea = getClientArea();
Rectangle graphArea = clientArea.getCopy();
Dimension dim = graphArea.getSize();
System.out.println(dim);
}
}
public static void main(String[] args) {
final Display display = new Display();
Color m_Red = display.getSystemColor(SWT.COLOR_RED);
Color m_Blue = display.getSystemColor(SWT.COLOR_BLUE);
Color m_White = display.getSystemColor(SWT.COLOR_WHITE);
Color m_Gray = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
Color m_Green = display.getSystemColor(SWT.COLOR_GREEN);
Color m_Black = display.getSystemColor(SWT.COLOR_BLACK);
final Shell shell = new Shell();
shell.setBounds(0, 0, 540, 540);
final GridLayout gridLayout = new GridLayout();
gridLayout.makeColumnsEqualWidth = true;
shell.setLayout(gridLayout);
final Group graphGroup = new Group(shell, SWT.NONE);
graphGroup.setBounds(0, 0, 500, 75);
graphGroup.setText("Graph:");
graphGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
final GridLayout graphLayout = new GridLayout();
graphLayout.numColumns = 1;
graphLayout.makeColumnsEqualWidth = true;
graphGroup.setLayout(graphLayout);
org.eclipse.swt.graphics.Rectangle rect = graphGroup.getClientArea();
System.out.println("Rect:" + rect);
final Canvas graphCanvas = new Canvas(graphGroup, SWT.NONE);
graphCanvas.setBounds(graphGroup.getClientArea());
graphCanvas.setBackground(m_Blue);
org.eclipse.swt.graphics.Point pt = graphCanvas.getSize();
System.out.println("Client:" + pt);
ChartFigure m_ChartFigure = new ChartFigure(new Dimension(pt));
LightweightSystem lws = new LightweightSystem(graphCanvas);
lws.setContents(m_ChartFigure);
// DESIGNER: Add controls before this line.
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
Thanks in advance for your help (I can send the source if it got too mangled)... Nat