Prev: catch native crash
Next: HttpServletRequest setHeader
From: G.W. Lucas on 9 Dec 2009 10:00 On Dec 8, 4:05 pm, "Knute Johnson" <knute.johnson@1:261/38.remove-n3i- this> wrote: > > You need a PageFormat to print. Keep the same PageFormat for the life of the > program. When you exit, save the orientation state and restore that when you > restart the program. > Thanks. I've looked at PageFormat and I'm afraid it's not going to solve my problem. Here's the thing... the nature of my graphics is that most of the time they ought to be printed with a landscape orientation. The default paper orientation for almost every application in the known universe is, of course, portrait. With that in mind, the ideal solution would be for the application would let the user pick an orientation the first time he prints and then present him with that same value every time after that. As a compromise solution, it would probably be okay if the Java print dialog could persist the settings from invocation to invocation within the same run of the application, but Java doesn't do that. So right now, I am stuck with making the user pick the paper orientation every time they print. They're going to hate that. There are two printDialog methods. One takes no arguments and one takes a PrintRequestAttributeSet. In theory the attribute set can be used as a way of persisting settings. The problem is that when I pass one in, Java gives me a different dialog (one which I consider pretty hokey looking and, worse, doesn't allow the user to access all the printer Properties). Failing a better solution, I'm VERY RELUCTANTLY going to call this a Java bug and do a work around. When you set up a Java PrinterJob, you register an instance of the Printable interface which implements a method called print() which is where your code is supposed to do all its work. The print() method does get a PageFormat object. I can have the program look at the page dimensions and orientation and automatically pick an orientation for the user. This approach would commit the minor affront of ignoring whatever the user selected for his orientation, but I hope that most of the time he won't care. Gary
From: G.W. Lucas on 9 Dec 2009 10:11 On Dec 9, 12:56 am, Roedy Green <see_webs...(a)mindprod.com.invalid> wrote: > This is not what you wanted to hear, but you may be stuck doing a > screen capture. Seehttp://mindprod.com/jgloss/screencapture.html > and follow links. Thanks, Roedy. I've visited your site many times. While a screen capture would most certainly not solve my problem (for one thing, I'm very concerned about dimensional accuracy in my printouts), it is something I need to look into for another application. A user can do a screen capture by hitting the print screen button and pasting into Paint or other such application, but I'd like to streamline the process by sending the output directly to a PNG file from the application (life is too short to ask the user to mess around with a lot of spurious mouse interactions). Do you have a snippet of code for grabbing the screen as a Java BufferedImage or some such form? g.
From: Knute Johnson on 9 Dec 2009 12:16 G.W. Lucas wrote: > On Dec 8, 4:05 pm, "Knute Johnson" <knute.johnson@1:261/38.remove-n3i- > this> wrote: >> You need a PageFormat to print. Keep the same PageFormat for the life of the >> program. When you exit, save the orientation state and restore that when you >> restart the program. >> > > Thanks. I've looked at PageFormat and I'm afraid it's not going to > solve my problem. Here's the thing... the nature of my graphics is > that most of the time they ought to be printed with a landscape > orientation. The default paper orientation for almost every > application in the known universe is, of course, portrait. With that > in mind, the ideal solution would be for the application would let the > user pick an orientation the first time he prints and then present him > with that same value every time after that. As a compromise solution, > it would probably be okay if the Java print dialog could persist the > settings from invocation to invocation within the same run of the > application, but Java doesn't do that. So right now, I am stuck with > making the user pick the paper orientation every time they print. > They're going to hate that. You are not paying attention. You can set the orientation in the PageFormat object anytime you want. This will present your selected orientation in the print dialog. Do it at the beginning, have the user select it the first time, it doesn't matter. Keep the same PageFormat object and the orientation (and all of the other fields too) will persist. > There are two printDialog methods. One takes no arguments and one > takes a PrintRequestAttributeSet. In theory the attribute set can be > used as a way of persisting settings. The problem is that when I pass > one in, Java gives me a different dialog (one which I consider pretty > hokey looking and, worse, doesn't allow the user to access all the > printer Properties). So don't use that, do what I suggested above. > Failing a better solution, I'm VERY RELUCTANTLY going to call this a > Java bug and do a work around. When you set up a Java PrinterJob, you > register an instance of the Printable interface which implements a > method called print() which is where your code is supposed to do all > its work. The print() method does get a PageFormat object. I can have > the program look at the page dimensions and orientation and > automatically pick an orientation for the user. This approach would > commit the minor affront of ignoring whatever the user selected for > his orientation, but I hope that most of the time he won't care. See previous comment. I've got running code with this in it. It works fine. -- Knute Johnson email s/nospam/knute2009/ -- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDemon.com<<<<<<------ Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
From: Roedy Green on 10 Dec 2009 22:48
On Wed, 9 Dec 2009 07:11:29 -0800 (PST), "G.W. Lucas" <gwlucas(a)sonalysts.com> wrote, quoted or indirectly quoted someone who said : >Thanks, Roedy. I've visited your site many times. While a screen >capture would most certainly not solve my problem (for one thing, I'm >very concerned about dimensional accuracy in my printouts), it is >something I need to look into for another application. A user can do a >screen capture by hitting the print screen button and pasting into >Paint or other such application, but I'd like to streamline the >process by sending the output directly to a PNG file from the >application (life is too short to ask the user to mess around with a >lot of spurious mouse interactions). > >Do you have a snippet of code for grabbing the screen as a Java >BufferedImage or some such form? I think you can also capture text. I have not played with this, but I think you can under program control turn the pixels of any rectangle on the screen into a png. See http://mindprod.com/jgloss/pngencoder.html for some sample code to save an image as a png. -- Roedy Green Canadian Mind Products http://mindprod.com The future has already happened, it just isn�t evenly distributed. ~ William Gibson (born: 1948-03-17 age: 61) |