Sponsored link
擬似ImageBorder(Draw2D/GEF - Java Eclipse)

厳密に言うと、ここで紹介する方法はBorderではありません。
イメージFigureの上に、ダミーFigureをセットして、そこに、MarginBorderを置くことで、
イメージFigureの縁を表示されるようにしているだけです。
うまく使えば、かわいい枠で表示できるかもしれないす。
次は、Borderをimplementsしたバージョンを作ってみようかな。
解説
Stackでサイズを最大取得しています。
imageFigure.setLayoutManager(new StackLayout()); Figure center=new Figure(); imageFigure.add(center); center.setBorder(new MarginBorder(25,40,25,40)); center.setLayoutManager(new StackLayout()); center.add(new RectangleFigure());
コード全文
GEFに含まれるdraw2d.jarが必要です。
コードはCVSからダウンロードできます。
/*
* Created on 2005/08/02
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package example.draw2d;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
*
*
*/
public class ImageAndMarginBorderTest {
public ImageAndMarginBorderTest(Shell shell) {
shell.setBounds(0,0,250,200);
shell.setLayout(new FillLayout(SWT.VERTICAL));
FigureCanvas canvas = new FigureCanvas(shell);
Panel panel=new Panel();
canvas.setContents(panel);
XYLayout layout=new XYLayout();
panel.setLayoutManager(layout);
Image img=new Image(null,this.getClass().getResourceAsStream("/example/draw2d/waku.gif"));
ImageFigure imageFigure=new ImageFigure(img);
panel.add(imageFigure,new Rectangle(10,10,-1,-1));
imageFigure.setLayoutManager(new StackLayout());
Figure center=new Figure();
imageFigure.add(center);
center.setBorder(new MarginBorder(25,40,25,40));
center.setLayoutManager(new StackLayout());
center.add(new RectangleFigure());
}
public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display);
ImageAndMarginBorderTest app=new ImageAndMarginBorderTest(shell);
shell.open();
while(!shell.isDisposed()){
if (!display.readAndDispatch ()){
display.sleep ();
}
}
display.dispose();
}
}
