| View previous topic :: View next topic |
| Author |
Message |
ib4jc78 General User

Joined: 24 Jan 2008 Posts: 15
|
Posted: Sun Oct 18, 2009 3:55 pm Post subject: Getting notified that the print window gets cancelled |
|
|
I am loading a document and using the following to print it and track the progress to tell when the printing it done:
| Code: | public void printDocument () {
XPrintable xPrintable = (XPrintable)
UnoRuntime.queryInterface(XPrintable.class, xComp);
XPrintJobBroadcaster selection = (XPrintJobBroadcaster)
UnoRuntime.queryInterface(XPrintJobBroadcaster.class,
xPrintable);
MyXPrintJobListener myXPrintJobListener = new MyXPrintJobListener();
selection.addPrintJobListener(myXPrintJobListener);
dispatchCommand(".uno:Print");
docIsPrinting = true;
}
public void dispatchCommand (String sURL) {
//dispatchCommand(".uno:Print");
XController xController = xModel.getCurrentController();
PropertyValue[] lProperties = new PropertyValue[0] ;
XMultiComponentFactory xSMGR = xContext.getServiceManager();
try {
if(xController!=null)
{
XFrame xFrame = xController.getFrame();
XDispatchProvider xProvider =
(XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider .class, xFrame );
XURLTransformer xParser =
(XURLTransformer)UnoRuntime.queryInterface ( XURLTransformer .class,
xSMGR.createInstanceWithContext("com.sun.star.util.URLTransformer", xContext));
com.sun.star.util.URL[] aParseURL = new com.sun.star.util.URL[1];
aParseURL[0] = new com.sun.star.util.URL();
aParseURL[0].Complete = sURL;
xParser.parseStrict (aParseURL);
XDispatch xDispatcher = xProvider.queryDispatch(aParseURL[0],"",0);
if(xDispatcher!=null)
{
xDispatcher.dispatch (aParseURL[0],lProperties);
}
}
} catch (Exception e) {System.err.println("Dispach error\n"+e);}
}
public class MyXPrintJobListener implements XPrintJobListener {
private PrintableState status = null;
public PrintableState getStatus() {
return status;
}
public void setStatus(PrintableState status) {
this.status = status;
System.out.println(status);
}
public void printJobEvent(PrintJobEvent printJobEvent) {
if(printJobEvent.State == PrintableState.JOB_COMPLETED)
{
System.out.println("JOB_COMPLETED");
this.setStatus(PrintableState.JOB_COMPLETED);
fireDocAction(DOC_PRINTING_DONE);
docIsPrinting = false;
}
if(printJobEvent.State == PrintableState.JOB_ABORTED)
{
System.out.println("JOB_ABORTED");
this.setStatus(PrintableState.JOB_ABORTED);
fireDocAction(DOC_PRINTING_ERR);
docIsPrinting = false;
}
if(printJobEvent.State == PrintableState.JOB_FAILED)
{
System.out.println("JOB_FAILED");
this.setStatus(PrintableState.JOB_FAILED);
fireDocAction(DOC_PRINTING_ERR);
docIsPrinting = false;
return;
}
if(printJobEvent.State == PrintableState.JOB_SPOOLED)
{
System.out.println("JOB_SPOOLED");
this.setStatus(PrintableState.JOB_SPOOLED);
}
if(printJobEvent.State == PrintableState.JOB_SPOOLING_FAILED)
{
System.out.println("JOB_SPOOLING_FAILED");
this.setStatus(PrintableState.JOB_SPOOLING_FAILED);
fireDocAction(DOC_PRINTING_ERR);
docIsPrinting = false;
return;
}
if(printJobEvent.State == PrintableState.JOB_STARTED)
{
System.out.println("JOB_STARTED");
this.setStatus(PrintableState.JOB_STARTED);
fireDocAction(DOC_PRINTING_START);
docIsPrinting = true;
return;
}
} |
It works fine, but if the user presses the cancel button on the print window my app will not know and sits in a pending state, I am using the following to wait for it to finish:
| Code: | ooSs.printDocument();
synchronized(this) {
while (ooSs.docIsPrinting) { try { wait(100); } catch (InterruptedException ie) {} }
} |
Is there a better way to wait for the document to finish printing before I close it, or some way to tell if the user pressed the cancel button so I can update the docIsPrinting boolean so my app can just continue? Or is there a way to automatically dispose of the document (That will also set docIsPrinting to false) when cancel is pressed because I have the document loaded hidden? Thanks! - Jeremy |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Fri Oct 23, 2009 8:33 pm Post subject: |
|
|
I assume that there are no other events, and that an abort event is not sent to the listener... I know, it feels like a dumb question, especially when your code seems to be so complete. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|