[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.gef] Re: Capturing drawing image WITHOUT showing it on screen
|
Here is the complete code...
<pre>
public class Demo2 {
public static void main(String[] args) {
Shell shell = new Shell();
shell.setText("Draw2d");
final LightweightSystem lws = new LightweightSystem(shell);
final IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);
Clickable button = new Button("Click me");
Clickable checkbox = new CheckBox("Check box");
Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);
Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);
panel.add(button);
panel.add(checkbox);
panel.add(ellipse);
panel.add(rectangle);
final Display display = Display.getDefault();
// here printout prints only the last figure
Shell shell2 = new Shell();
PrintDialog dialog = new PrintDialog(shell2, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op = new PrintFigureOperation(new Printer(data), panel);
op.setPrintMode(PrintFigureOperation.TILE);
op.run("demo2");
}
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// here printout is proper, and has all figures
Shell shell = new Shell();
PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op = new PrintFigureOperation(new Printer(data), panel);
op.setPrintMode(PrintFigureOperation.FIT_PAGE);
op.run("demo2");
}
}
});
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}
}
</pre>