Sponsored link
StackLayoutのリサイズ
StackLayoutでは、子Figureのうち一番サイズが大きいものに他のFigureを合わせていきます。
そのため、画面を一時的にリサイズしてサイズが大きくなった場合、元のサイズには戻りません。

CustomStackLayout
このコードはあまりテストしておらず、他にどういう問題が起きるか把握してません。
Windows以外では動かないかもしれません。
これは、StackLayoutのコードから子Figureのサイズを元に拡大する部分をコメントアウトいます。
これを、StackLayoutの表示の所の、コード
StackLayout layout=new StackLayout(); を StackLayout layout=new CustomStackLayout();
とします。
コードはCVSからダウンロードできます。
package example.draw2d;
import org.eclipse.draw2d.AbstractHintLayout;
import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
public class CustomStackLayout extends StackLayout{
/**
* Returns the minimum size required by the input container. This is the size of the
* largest child of the container, as all other children fit into this size.
*
* @see AbstractHintLayout#calculateMinimumSize(IFigure, int, int)
*/
protected Dimension calculateMinimumSize(IFigure figure, int wHint, int hHint) {
if (wHint > -1)
wHint = Math.max(0, wHint - figure.getInsets().getWidth());
if (hHint > -1)
hHint = Math.max(0, hHint - figure.getInsets().getHeight());
Dimension d = new Dimension();
/*
List children = figure.getChildren();
IFigure child;
for (int i = 0; i < children.size(); i++) {
child = (IFigure)children.get(i);
if (!isObservingVisibility() || child.isVisible())
d.union(child.getMinimumSize(wHint, hHint));
}
d.expand(figure.getInsets().getWidth(),
figure.getInsets().getHeight());
d.union(getBorderPreferredSize(figure));
*/
return d;
}
/**
* Calculates and returns the preferred size of the given figure. This is the union of
* the preferred sizes of the widest and the tallest of all its children.
*
* @see AbstractLayout#calculatePreferredSize(IFigure, int, int)
*/
protected Dimension calculatePreferredSize(IFigure figure, int wHint, int hHint) {
if (wHint > -1)
wHint = Math.max(0, wHint - figure.getInsets().getWidth());
if (hHint > -1)
hHint = Math.max(0, hHint - figure.getInsets().getHeight());
Dimension d = new Dimension();
/*
List children = figure.getChildren();
IFigure child;
for (int i = 0; i < children.size(); i++) {
child = (IFigure)children.get(i);
if (!isObservingVisibility() || child.isVisible())
d.union(child.getPreferredSize(wHint, hHint));
}
d.expand(figure.getInsets().getWidth(),
figure.getInsets().getHeight());
d.union(getBorderPreferredSize(figure));
*/
return d;
}
}
