Tobias Krais wrote:
> Hi Matthias,
>
>
> Mathias Bauer schrieb:
>> Tobias Krais wrote:
>>
>>> Hi together again,
>>>
>>> I implemented a protocol handler for the CommandURL .Judas:PrintTrays.
>>> The target of this new protocol is to print a document on different
>>> printer trays (page one on tray with letter paper, the others on the
>>> tray with normal paper). After sending the print command via API I added
>>> a PrintJobListener:
>>> -----%<-----
>>> // Querying for the interface XPrintable on the loaded document
>>> XPrintable xPrintable = (XPrintable)
>>> UnoRuntime.queryInterface(XPrintable.class,
>>> this.xComponent);
>>>
>>> // Adding a print job listener
>>> XPrintJobBroadcaster selection = (XPrintJobBroadcaster)
>>> UnoRuntime.queryInterface(XPrintJobBroadcaster.class,
>>> xPrintable);
>>> OOPrintJobListener ooPrintJobListener = new OOPrintJobListener();
>>> ooPrintJobListener.setDebug(debug);
>>> selection.addPrintJobListener(ooPrintJobListener);
>>>
>>> // Setting the property "Pages" so that only the desired pages
>>> // will be printed.
>>> PropertyValue[] printOpts = new PropertyValue[1];
>>> printOpts[0] = new PropertyValue();
>>> printOpts[0].Name = "Pages";
>>> printOpts[0].Value = myPages;
>>>
>>> try {
>>> xPrintable.print(printOpts);
>>> } catch (IllegalArgumentException e) {}
>>>
>>> // Watch print process and continue if done.
>>> // TODO: see OO Bug id 72240; don't print a non-existing page, other-
>>> // wise here is a loop.
>>> while (ooPrintJobListener.getStatus() == null ||
>>> ooPrintJobListener.getStatus() == PrintableState.JOB_STARTED)
>>> {
>>> try {
>>> Thread.sleep(2000);
>>> }
>>> catch (InterruptedException e) {}
>>> }
>>> -----%<-----
>
>> Why do you want to "sleep" in your listener? Perhaps you can avoid that.
>> Without understanding what you are trying to achieve it's hard to give
>> any useful hints.
>
> The code above answers half. I have to wait till the print job is done
> and then I can send a second print job (same code again), otherwise the
> second one will be fired too fast and wont be printed. For this I
> implemented a PrintJobListener that checks every two seconds if the
> PrintableState changed to be able to continue setting the second print job.
First you should stop the timed waiting. Let your code return and wait
for the JOB_FAILED/COMPLETED/ABORTED notification. Here you can start
your next print job.
> I don't think there is a workaround. It's a pity, because I would like
> to pop up a message if the print job failed - but I cannot pop up a
> message from the second thread.
At least on Windows this is a limitation created by the OS. OOo can't
open a message box in any other thread than the "OOo main thread". But
if I understood you correctly you can achieve your goal by letting your
listener start the next print job.
Ciao,
Mathias
--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[EMAIL PROTECTED]".
I use it for the OOo lists and only rarely read other mails sent to it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]