Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Printing a composite
Printing a composite [message #441761] Tue, 24 August 2004 11:49 Go to next message
Eclipse UserFriend
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 #441768 is a reply to message #441761] Tue, 24 August 2004 16:25 Go to previous messageGo to next message
Carolyn MacLeod is currently offline Carolyn MacLeodFriend
Messages: 149
Registered: July 2009
Senior Member
Hi, Jorgen.

You are correct - printing is either done "manually" by drawing on a GC, or
by taking a snapshot and printing the image.

One example of a widget that prints itself is
org.eclipse.swt.custom.StyledText - you could look at the code for that to
see an example of an implementation that either draws to the display device
or to a printer device depending on whether the widget is being displayed or
printed. A lot of the more interesting code can be reused - you just need to
write a bunch of glue code to do the paging, etc. Of course, as you will
notice, StyledText does its own internal layout.

If it is not possible for you to take a screen snapshot of your charts and
print that, then I am afraid you are stuck with doing your own layout. The
SWT layout classes do not help with printing. Of course, you can copy the
interesting code in those classes if it makes sense for your application.

Carolyn



"J
Re: Printing a composite [message #441775 is a reply to message #441768] Tue, 24 August 2004 19:06 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Printing a composite [message #441794 is a reply to message #441775] Wed, 25 August 2004 16:30 Go to previous message
Carolyn MacLeod is currently offline Carolyn MacLeodFriend
Messages: 149
Registered: July 2009
Senior Member
Please read this feature request - there is some internal test code in there
that may help you (Windows only).
Please add a comment about layout, and add yourself to the CC list if you
wish to track progress.
I don't think this feature is being worked on at all at the moment.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=26095

Thanks!
Carolyn

"J
Previous Topic:display formatted text - or html text?
Next Topic:Can i change the content of a compsite dynamicly?
Goto Forum:
  


Current Time: Fri Apr 26 11:07:38 GMT 2024

Powered by FUDForum. Page generated in 0.03210 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top