在PartView中正确调整GridLayout的大小

时间:2013-02-14 21:42:53

标签: java swt eclipse-rcp

我在网格中有一个图像,可以在调整PartView大小时进行缩放。如果BarsView的开始小于64(画布的大小),则图像的底部会被切断到初始大小以下。如果它的开始大于调整大小的大小,那么小型实体就不会收缩。当我调整大小时,我怎样才能看到当我打开那个大小的程序时的布局?

以正常大小打开程序时的屏幕截图:

Normal size to start

以正常尺寸打开后收缩(注意浓度条被推离屏幕底部):

enter image description here

以较小的尺寸开启:

enter image description here

以较小的尺寸打开然后展开:

enter image description here

重新调整大小之间的重新启动具有所需的效果,但需要重新启动部分。

public class BarsView extends ViewPart {
    private PageBook book;
    public void createPartControl(Composite parent) {   
        book = new PageBook(parent, SWT.NONE);
        book.setLayout(new FillLayout());
        Composite page = new BarsPageView(book, view);
        book.showPage(page);
    }
    private class BarsPageView extends Composite {
        public BarsPageView(Composite parent, GameView view) {
        super(parent, SWT.NONE);
        this.setLayout(new GridLayout(3, false));

        // This is a wrapper around a StyledText
        entry = new StormFrontEntry(this, view);
        GridData entryData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
        entryData.heightHint = 22;
        entry.getWidget().setLayoutData(entryData); // getWidget() returns the StyledText

        // This is a Composite containing a Canvas
        status = new StormFrontStatus(this, view);
        status.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));

        // This is defined below                
        GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
        compassData.heightHint = 64;
        compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
        compass.setLayoutData(compassData);

        minivitals = new StormFrontDialogControl(this, SWT.NONE);
        GridData mvData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
        minivitals.setLayoutData(mvData);
    }
}

public class WarlockCompass extends Canvas {
    public WarlockCompass (final Composite parent, int style, CompassTheme theme, GridData layoutData) {
        super(parent, style);
        addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                drawCompass(e.gc);
            }
        });
        parent.addListener(SWT.Resize, new Listener() {
            @Override
            public void handleEvent(Event event) {
                // I cut out the calculations for this
                layoutData.heightHint = height;
                WarlockCompass.this.setSize(width, height);
            }
        });
    }
    private void drawCompass (GC gc) {
        // Cut out the calculations to scale the image to fix the canvas
        gc.drawImage(scaledImage, 0, 0);
    }
}

1 个答案:

答案 0 :(得分:0)

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

应该是:

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

更改该标志会使其正确调整大小。