[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] Printing a composite widget
|
See
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/faq.html#noprintimage
Your code fails cause it creates two Displays in the same thread.
For user question please use the swt newsgroup:
http://www.eclipse.org/newsgroups/index.html
Thanks
Felipe
Jörgen Ekström <jorgen.ekstrom@xxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx
08/23/2004 02:51 AM
Please respond to
platform-swt-dev
To
<platform-swt-dev@xxxxxxxxxxx>
cc
Subject
[platform-swt-dev] Printing a composite widget
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, a GC is created and all ?layout?
is handled manually. I have a
number of charts which are layout using GridLayout which I would like to
print as they appear on screen.
I tried the following code (see below) but got a Thread Access Error when
creating the Display. The Action is a simple
menu action called within the UI thread.
I would appreciate any help or hints! Thanks!
Jorgen E.
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:568)
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.handleWidgetSelection(ActionContributionItem.java:915)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:866)
at
org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.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.java: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)