Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Printing a Table
Printing a Table [message #466102] Mon, 02 January 2006 10:14 Go to next message
Sebastian is currently offline SebastianFriend
Messages: 26
Registered: July 2009
Junior Member
Hi all.

Does somebody know how to print a table in SWT? I don't want to print only
the content, I need to print the whole table.

Thanks SB
Re: Printing a Table [message #466167 is a reply to message #466102] Wed, 04 January 2006 07:49 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 26
Registered: July 2009
Junior Member
Hello. I have a method to print the current view of a table, but is it
somehow possible to print the whole table and not only a cut-out of it?

Here is my code to print the current cut-out of the table I see on the
screen:



print.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Point tableSize = table.getSize();

final Image tableImage =
new Image(Display.getCurrent(), 750, tableSize.y);

GC tableGC = new GC(table);
tableGC.copyArea(tableImage, 0, 0);

Shell shell = new Shell();
PrintDialog dialog = new PrintDialog(shell);
PrinterData data = dialog.open();
Printer printer = new Printer(data);

ImageData tableImageData = tableImage.getImageData();
tableImageData.transparentPixel = -1;

int scaleFactor = 5;
Rectangle trim = printer.computeTrim(-500, -500, 0, 0);

if (printer.startJob("DeployHistory-Print")) {
GC gc = new GC(printer);
if (printer.startPage()) {
gc.drawImage(
tableImage,
0,
0,
tableImageData.width,
tableImageData.height,
-trim.x,
-trim.y,
scaleFactor * tableImageData.width,
scaleFactor * tableImageData.height);
printer.endPage();
}
printer.endJob();
}
printer.dispose();
tableGC.dispose();
}
});
Re: Printing a Table [message #466178 is a reply to message #466167] Wed, 04 January 2006 16:04 Go to previous messageGo to next message
Joe Mihalich is currently offline Joe MihalichFriend
Messages: 25
Registered: July 2009
Junior Member
Sebastian,

There is no way automated way to print a table.
Probably mainly because you rarely want the actual print-out
to look exactly like it is displayed in the application.

Normally you want everything to be paged, with
headers and footers on the page, plus the ability to
fit the the text (scaled down) to fit on one page, etc.

The way I did it was just going through each cell
of each row, and drawing the text of the cell to the
printer GC...and I had to do my own paging based
on the hieight of the printer DC, plus accumulated
height of each row that I printed out.

It is quite complex to get everything working.

Joe
Re: Printing a Table [message #466211 is a reply to message #466178] Wed, 04 January 2006 22:07 Go to previous messageGo to next message
Peter Kliem is currently offline Peter KliemFriend
Messages: 35
Registered: July 2009
Member
Hi Sebastian,

I do agree with Joe. You might have a look at the (very beta) JaretTable
(www.jaret.de): it includes printing the table.

Peter
Joe Mihalich wrote:
> Sebastian,
>
> There is no way automated way to print a table.
> Probably mainly because you rarely want the actual print-out
> to look exactly like it is displayed in the application.
>
> Normally you want everything to be paged, with
> headers and footers on the page, plus the ability to
> fit the the text (scaled down) to fit on one page, etc.
>
> The way I did it was just going through each cell
> of each row, and drawing the text of the cell to the
> printer GC...and I had to do my own paging based
> on the hieight of the printer DC, plus accumulated
> height of each row that I printed out.
>
> It is quite complex to get everything working.
>
> Joe
>
>
Re: Printing a Table [message #466242 is a reply to message #466178] Thu, 05 January 2006 13:44 Go to previous messageGo to next message
Sebastian is currently offline SebastianFriend
Messages: 26
Registered: July 2009
Junior Member
Hello.

Thank you for your answers. I thought so, that it won't become easy to
implement it, because I found nothing about this problem.
Does soembody know, if it will be included in later versions of Eclipse
and SWT?

@Joe
Can you please post me your code, that I can have a look on it? I also
tried to do this, but I never had such a structure like in the table.

f.e.:
1st_column 2nd_column 3rd_column
test1 test2 test3
test234 a_much_to_long_text a_new_text
abc def ghi

What can I do, that all entries of a column are among each other and not
shifted?
Re: Printing a Table [message #466273 is a reply to message #466242] Thu, 05 January 2006 17:54 Go to previous messageGo to next message
Joe Mihalich is currently offline Joe MihalichFriend
Messages: 25
Registered: July 2009
Junior Member
Hey,

I would otherwise be happy to post the code, but
I have a rather large printing infrastructure that this code
works off of, and it's not something where I can just post
the contents of a method.

Regarding your question though, there are two solutions:

1) Pre-calculate the max column width (using text extents)
for each row of a page. Then make column 2 (for instance)
start at the same location for each row where the "x" of
column 2 is greater than the max width of column 1.

2) Instead of drawing row 1, then row 2, then row 3, reverse your
loop, and draw by columns. that way you don't have to
pre-calculate
the max width of every column...you draw column 1 first keeping
the maximum width of all column 1 for a given page as you draw
each cell. Then when you get to column 2, you know the the
max "x", so just continue your look, setting your column 2
starting
"x" to be greater than that max value.

I actually chose number 2 in my implementation.

Hope that helps.
Joe




"Sebastian" <s-bayerlein@gmx.de> wrote in message
news:4cd4aac847387d6a193e454258890d9a$1@www.eclipse.org...
> Hello.
>
> Thank you for your answers. I thought so, that it won't become easy to
> implement it, because I found nothing about this problem. Does soembody
> know, if it will be included in later versions of Eclipse and SWT?
> @Joe
> Can you please post me your code, that I can have a look on it? I also
> tried to do this, but I never had such a structure like in the table.
> f.e.:
> 1st_column 2nd_column 3rd_column
> test1 test2 test3
> test234 a_much_to_long_text a_new_text abc def
> ghi
> What can I do, that all entries of a column are among each other and not
> shifted?
>
Re: Printing a Table [message #466543 is a reply to message #466102] Wed, 11 January 2006 10:07 Go to previous message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Hi,

sorry for the late answer. You could try KPrint
see http://www.kupzog.de/fkmk_uk/Programming/Downloads/downloads .html
This is a SWT formatted printing utility that also supports printing SWT
tables (and KTables).

Regards,
Friederich

Sebastian wrote:
> Hi all.
>
> Does somebody know how to print a table in SWT? I don't want to print
> only the content, I need to print the whole table.
> Thanks SB


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel +49 241 9979356
Fax +49 221 726670
www.kupzog.de/fkmk
Previous Topic:Opening a GEF editor crashes Eclipse/JVM with cairo error
Next Topic:Undo on Text widgets
Goto Forum:
  


Current Time: Sun Dec 08 00:22:16 GMT 2024

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

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

Back to the top