🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17095

Re: Anyone out there willing to help?

#17095
From: Chris Hill
Date: Mon, 21 Dec 1998 00:00
107 lines
6396 bytes
On Sun, 20 Dec 1998 20:26:29 -0600, "Ross Dukeshier"
<dukeman@flash.net> wrote:

>I would think you'd just have to use the PageFormat's getImageableX and
>getImageableY combined with the getImageableWidth and getImageableHeight
>methods to draw a Rectangle, but I'd guess you've done that and it doesn't
>work.  It wouldn't surprise me, but maybe it's off by one pixel.  Have you
>tried adding 5 or so to each value (subtracting on the lower bounds) to get
>it to draw it?

It isn't an off by X problem.  It seems to me that the clipping and/or
coordinate system is inconsistent with the values returned for the
imageable properties.  The left and right on my printer have a 0.25"
non-printable margin.  I have not been able to get output closer than
0.5" from the left.  I can get output 0.25" from the right side of the
page.

Where is the origin in the coordinate system?  At imageableX and y?

>The PrintJob dialog isn't a JDK thing as far as I know.  The JVM just brings
>up the same dialog the native machine uses.  If you try to print from Word,
>you get the same dialog.  This dialog doesn't play with others in that it is
>supposed to return the properties you selected in the properties object you
>passed to the getPrintJob method.  If you think about it, this is divergent
>from the way Java does things as you can't normally have an "out" parameter
>in a Java method.  Basically, the properties object you send will be ignored
>and the dialog never sets them for a return.  I'm sure this is something
>Windows failed to do as they didn't expect anyone but them to be using it
>(or they did and wanted to cause problems - who knows).  Anyway, I assumed
>the reason for a totally platform independent printing approach in JDK 1.2
>was because they didn't want to rely on certain other companies to fix their
>stuff.

There is no firm requirement for a Windows application that prints to
display a dialog.  When you Press the printer toolbar button in Word,
it prints the entire current document without a dialog.

I've worked with Windows for years, although not with the print
dialog.  AFAIK from reading the Win32 documentation, the Windows
printer dialog does allow you do examine the data that was entered
upon return.

I don't think Windows failed to do anything, I think Java failed to
use Windows correctly.  Java must ultimately call the native OS
functions to print.  Java is responsible for using them correctly.

>Hadn't thought about it, but now that you mention it, I don't remember
>seeing anything to give me the properties back.  You don't think they missed
>that do ya?  If so, then this time you can blame Sun for screwing it up.
>You'd be able to use the printer options again during the run I suppose, but
>not as default on another session.  I'll have to look for that one, but it's
>on the back-burner until I get all the kinks worked out of the printing
>itself.

You send the properties in, so you can check them when getPrintJob
returns (the function could add properties or modify them).  I don't
know if it is possible to do what you describe.  In theory, you could
save the properties and pass them to the getPrintJob function each
time.  This is probably the bug you mentioned, the function doesn't
save its state in the properties.  If the mechanism worked, there
could be a "display dialog" property to bypass the dialog if desired.

>I'm to the point where I can print out a page.  My problem wasn't with the
>setColor stuff as I'd heard about that one from someone else.  I was trying
>to sub-class Book and make it Printable as I thought it should be and it
>didn't like it.  Anyway, I can print, but for some reason, it doesn't print
>out anything after the first page (second one is now blank - think I need to
>set the color twice? hehehe).  Test output shows the print method is getting
>called for the second page and that it's drawing the right Strings on the
>graphics object, but again, nothing comes out on it.  I'm thinking it may
>have something to do with not having it Pageable, but I'd think that if that
>was the case it wouldn't call it a second time.  Any ideas?

Book implements Pageable.  Can't you call setPageable and pass a book
that you have filled with printables (using Book.append)?  I haven't
tried this, but it looks like you call either setPageable or
setPrintable, but not both.  So to print a Book, call setPageable.

I don't think you need to use Pageable at all do you?  Isn't
Printable.print called until it returns NO_SUCH_PAGE?  I just use
Printable.

>Here's the code as it stands now.  Please run it and see if you can find
>anything in the print method I'm missing.  If you have ideas on how to make
>it paginate better, I'd love to hear them - seems a little awkward, but
>that's why I thought Book was the right way to go at first.  Also, if you
>have any ideas on how to make it word wrap, I'm all ears - that's the next
>step after I get it to just give me all the pages.  A method for the Font
>class to pull the number of words from a string that fit within a specified
>Imageable width would have been nice.  Any ideas on how to implements such a
>thing?

I needed to import java.awt.* before I could compile.

Your example did print two pages on my machine.

Doesn't this code assume that the imageable area of the page is
centered on the paper?  On my machine it is not (top != bottom).  You
might want to use getImageableX and getImageableY.
      int x = (int) ((pf.getWidth() - pf.getImageableWidth())/2);
      int y = (int) ((pf.getHeight()-pf.getImageableHeight())/2);

BTW does your print function get called twice for each page?  That
also happened in my example.

Chris Hill
hillca@cs.purdue.edu
Technical Details
Message-ID: <367df9a6.135230401@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <75i7jh$5gi4@forums.borland.com> <75j357$5ga10@forums.borland.com> <75jciv$6fp4@forums.borland.com> <367d5347.92639278@forums.borland.com> <75kbl4$7921@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,5cf86e902afbf4b
X-Google-Attributes: gidf74b3,public
From: hillca@cs.purdue.edu (Chris Hill)
Subject: Re: Anyone out there willing to help?
Date: 1998/12/21
Message-ID: <367df9a6.135230401@forums.borland.com>
X-Deja-AN: 424439724
References: <75i7jh$5gi4@forums.borland.com> <75j357$5ga10@forums.borland.com> <75jciv$6fp4@forums.borland.com> <367d5347.92639278@forums.borland.com> <75kbl4$7921@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language