Printing a composite [message #441761] |
Tue, 24 August 2004 11:49 |
Eclipse User |
|
|
|
Originally posted by: jorgen.ekstrom.bredband.net
Hi All,
Can someone help me how to print a composite and hence utilize the layout
capabilities in swt?
In the printing examples I've looked at, either a GC is created and all
"layout" is handled manually or an Image snapshot is
captured and printed as Image. I have a number of charts which are layout
using GridLayout which I would like to print.
I tried creating a new display and shell just as when creating the on screen
composite, but got a thread access error
since I'm not allowed to create several displays from the same thread.
I would appreciate any help or hints! Thanks!
Jorgen
ChartWindow chartWindow = (ChartWindow)window;
int nbrPages = chartWindow.getNbrTabs();
PrintDialog dialog = new PrintDialog(window.getShell(),
SWT.NONE);
dialog.setText("PrintDialogDemo");
dialog.setScope(PrinterData.PAGE_RANGE);
dialog.setStartPage(1);
dialog.setEndPage(nbrPages);
dialog.setPrintToFile(true);
PrinterData printerData = dialog.open();
if (printerData != null) {
Printer printer = new Printer(printerData);
//GC gc = new GC(printer);
DeviceData deviceData = printer.getDeviceData();
Display display = new Display(deviceData);
printer.startJob("Chart");
printer.startPage();
Shell shell = new Shell(display);
ChartResources chartResources = new ChartResources(shell);
int itemId[] = chartWindow.getItemId();
GridLayout layout = new GridLayout();
layout.numColumns = 3;
layout.makeColumnsEqualWidth = true;
shell.setLayout(layout);
for (int i = 0; i < ItemId.length; i++) {
Chart chart = ChartKit.getChart(itemId[i], false,
env);
ChartCanvas canvas = new ChartCanvas(chart,
chartResources, shell, SWT.BORDER);
canvas.setLayoutData(new
GridData(GridData.FILL_BOTH));
}
printer.endPage();
printer.endJob();
printer.dispose();
}
}
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2691)
at org.eclipse.swt.SWT.error(SWT.java:2616)
at org.eclipse.swt.SWT.error(SWT.java:2587)
at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:56 8)
at org.eclipse.swt.widgets.Display.create(Display.java:629)
at org.eclipse.swt.graphics.Device.<init>(Device.java:99)
at org.eclipse.swt.widgets.Display.<init>(Display.java:355)
at com.finsys.tradeagent.chart.PrintAction.run(PrintAction.java :63)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:881 )
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(Action
ContributionItem.java:915)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionI
tem.java:866)
at
org.eclipse.jface.action.ActionContributionItem$7.handleEven t(ActionContribu
tionItem.java:785)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2431)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:668 )
at org.eclipse.jface.window.Window.open(Window.java:648)
at
com.finsys.tradeagent.TradeAgentWindow.main(TradeAgentWindow .java:132)
|
|
|
|
Re: Printing a composite [message #441775 is a reply to message #441768] |
Tue, 24 August 2004 19:06 |
Eclipse User |
|
|
|
Originally posted by: jorgen.ekstrom.bredband.net
Hi and thanks for the answer,
I still have a problem accepting that the layout capabilities of the widgets
could not be used for printing device - in the
end it's how to distribute a rectangular area, just as in the on screen
case?
Most widgets like lists, tabs and menus are not printed like they appear on
screen, but any custom controls, e.g. a chart canvas is very likely to use
both for screen and printing.
Sincerely,
J
|
|
|
|
Powered by
FUDForum. Page generated in 0.03210 seconds