Thanks, that put me on the right track. My code works now! I owe you a beer. Here's what I did...
   
    Object[] attributeValues = (Object[])
        printService.getSupportedAttributeValues(
            PrinterResolution.class,
            new DocFlavor("image/png", "[B"),
            attributeSet);
       
    PrinterResolution r = (PrinterResolution)(attributeValues[0]);


The documention is correct, but really obscure on this point. Great to have the experts around.

Thanks muchly - Eric

Jennifer Godinez wrote:
Hi Eric,

Try this modification to your code:

Object r = printService.getSupportedAttributeValues(...);

PrinterResolution[] resValues = (PrinterResolution[]) r;


Jennifer


  
Delivered-To: [EMAIL PROTECTED]
X-Accept-Language: en-us, en
User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920
    
Netscape/7.0
  
Date: Tue, 25 Feb 2003 16:22:16 -0800
From: Eric Kolotyluk <[EMAIL PROTECTED]>
Subject: Re: [JAVA2D] GraphicsConfiguration and Printing
Comments: cc: Phil Race <[EMAIL PROTECTED]>, Jennifer Godinez
    
<[EMAIL PROTECTED]>
  
To: [EMAIL PROTECTED]

Thanks Jennifer and Phil on the hint about getSupportedAttributeValues.
Here's what I tried

    PrinterResolution r = (PrinterResolution)
        printService.getSupportedAttributeValues(
            PrinterResolution.class,
            new DocFlavor("image/png", "[B"),
            attributeSet);

    if (r == null)
        System.out.println("\tcan't query resolution.");
    else
        System.out.println("\tresolution = " + r.toString());

Sorry Phil, the compiler wouldn't let me use null for the DocFlavor.
When I run the program it throws classCastException at the first line of
code (but could anywhere else in the statement). Given
getSupportedAttributeValues returns (object) I can't compile the code
any other way - can I?

I also tried replacing PrinterResolution.class with

    PrinterResolution resolution =
        new PrinterResolution(100, 100, ResolutionSyntax.DPI);
and
        resolution.getCategory(),

but same result. Any other ideas? I really appreciate the quick response
from both of you.

Cheers, Eric   ... more comments below...

Jennifer Godinez wrote:

Hi Eric,

You can get PrinterResolution by calling getSupportedAttributeValues of
PrintService and passing PrinterResolution.class as your first parameter.

Jennifer


Phil Race wrote:

    
Eric,
      Please send emails as plain text as well as HTML.
      Sometimes people need to read email through non-GUI tools.


      
Good point, will do.

    
      
Is there any way to find more specific information on a print device like
        
its
  
        
resolution via attributes?.

      GraphicsConfiguration isn't useful for this.
      Printing attributes go way beyond graphics attributes.

      
Ahh, but is there a way to get the GraphicsConfiguration for a
printer/printJob? Otherwise, why does much of the other API
documentation imply there is. I'm curious and hate unresolved mysteries.

    
      You should be using javax.print and the methods are all on
      the PrintService interface.

      eg
 PrintService.getSupportedAttributeValues(PrinterResolution.class,null,
      
null);
  

      
     (i.e. no examples or tutorials).


        
      SBT. We'd like fix this but it needs resources to do so.

      
Maybe Sun could hire me. Motorola is shutting down our site, so now I'm
doing contract work where I can until I can find full-time work again.
I've been using Java since 1995, before then obj-C on NeXT. ;-) Anyway,
I know the problem, there's never enough time to document stuff right,
and too many people would rather make their fortunes publishing books.
Has anyone ever written a book exclusively on Java printing?

    
      There are PDF's etc of JavaOne talks on line at java.sun.com
      Session 2250 in 2002 would be useful and session 595 from 2001

      
Thanks for the tip.

    
      JAVA2D-INTEREST is the best list for printing questions.
      Its the only one the people who work on this stuff have time
      to read.

      
OK, I'll put my printing questions here. I have quite a few...

    
-phil.

==========
While reading the API documentation on GraphicsConfiguration,
GraphicsEnvironment, and GraphicsDevice, they all mention printers. However,
reading the Graphics2D API on PrinterJob and friends I can find no way to get
the GraphicsConfigruation related to a PrinterJob like I can with
Window.getGraphicsConfiguration. Is there actually a way to find the
GraphicsConfiguration for a printer or is the documentation teasing me?

Is there any way to find more specific information on a print device like its
resolution via attributes?. The PrintServiceAttributeSet can only be used to
setting attributes, not for inquiry. And its badly documented at that (i.e.
      
no
  
examples or tutorials). Took me too long to figure out someone else's
cleverness, only to discover you can't get the printer resolution that way.
      
I'm
  
not at all impressed with the design here.

This seems to be a black magic area and any help would be greatly
      
appreciated.
  
It would also be nice if there were a forum or new list specifically for
printing issues. Not nearly enough has been written or documented about
      
printing
  
in Java,

Cheers, Eric

===========================================================================
      
To
  
unsubscribe, send email to [EMAIL PROTECTED] and include in the body of
      
the
  
message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


      
Date: Tue, 25 Feb 2003 12:26:14 -0800
From: Eric Kolotyluk <[EMAIL PROTECTED]>
Subject: [JAVA2D] GraphicsConfiguration and Printing
To: [EMAIL PROTECTED]



        

      

  

Reply via email to