Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Size of IFigure in LightweightSystem


When the SWT shell is open()ed, it fires RESIZE event even though you already sized it earlier.  This trigger's a layout, which means that your graph Canvas has it's computeBounds() queried by GridLayout.  The default implementation of compute bounds must be returning 64x64.  All of the numbers you printed out change after calling shell.open().

Try using FigureCanvas (it implements computeBounds() by asking the Figure), and try implementing getPreferredSize() in your custom figure instead of just hard-coding a specific size.  Questions related to GEF should be asked on the gef-dev@xxxxxxxxxxx mailing list.

Thanks,
Randy





"W. Nathaniel Mills, III" <nat@xxxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

09/17/2003 03:39 PM
Please respond to platform-swt-dev

       
        To:        platform-swt-dev@xxxxxxxxxxx
        cc:        
        Subject:        [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

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top