gpt4 book ai didi

java - 执行调度同步?

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:32 24 4
gpt4 key购买 nike

我正在开发一个已加载文档的 java Applet。在此小程序上,我有一个自定义的“打印”按钮,它基本上启动文档的打印过程。这是按下此按钮后执行的代码:

PropertyValue[] printProperties = new PropertyValue[1];
printProperties[0] = new PropertyValue();
printProperties[0].Name = "Print";
printProperties[0].Value = new Boolean(true);

xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);
dispatcher.executeDispatch(xDispatchProvider, ".uno:Print","_self", 0, printProperties);

someOtherProcess();

此代码打开 native (?)打印对话框,这是预期的行为,并且到目前为止有效。问题是“someOtherProcess”方法。我需要在打印对话框关闭后立即执行此方法,方法是按“打印”按钮或取消/关闭打印对话框。

由于executeDispatch是异步的,我尝试使用PropertyValue[]中的“SynchronMode”使其同步,但没有成功。

我找到了一种监听打印事件的方法,这些事件在打印过程开始或取消时触发。这是整个代码:

PropertyValue[] printProperties = new PropertyValue[1];
printProperties[0] = new PropertyValue();
printProperties[0].Name = "Print";
printProperties[0].Value = new Boolean(true);

xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);

dispatcher.executeDispatch(xDispatchProvider, ".uno:Print","_self", 0, printProperties);

XPrintJobBroadcaster xPrintJobBroadcaster = (XPrintJobBroadcaster)UnoRuntime.queryInterface(XPrintJobBroadcaster.class, xComponent);
xPrintJobBroadcaster.addPrintJobListener(new MyPrintJobListener());



class MyPrintJobListener implements XPrintJobListener {
public void printJobEvent(PrintJobEvent printJobEvent) {
AppletLogger.log("printing");
}
public void disposing(com.sun.star.lang.EventObject eventObject) {
AppletLogger.log("disposing");
}
}

当打印过程开始、完成、取消等时,“printJobEvent”会被触发,但我找不到方法来知道打印对话框是否已被取消或关闭,因为这不会触发任何打印事件。

所以我的主要问题是,有没有办法以同步方式打开打印对话框,以便程序等待打印对话框关闭?有没有办法监听 native 打印对话框窗口的关闭事件?

提前致谢!

最佳答案

检查State属性(property)。如果取消打印,则应首先显示 JOB_STARTED(即 0),然后显示 JOB_ABORTED(即 3)。

class MyPrintJobListener implements XPrintJobListener {
public void printJobEvent(PrintJobEvent printJobEvent) {
AppletLogger.log("print status: " + printJobEvent.State.getValue());
}
public void disposing(com.sun.star.lang.EventObject eventObject) {
AppletLogger.log("disposing");
}
}

调度员也不为我工作。请改用 API 接口(interface):

XPrintJobBroadcaster xPrintJobBroadcaster = (XPrintJobBroadcaster)
UnoRuntime.queryInterface(XPrintJobBroadcaster.class, xComponent);
xPrintJobBroadcaster.addPrintJobListener(new MyPrintJobListener());

XPrintable xPrintable =
(XPrintable)UnoRuntime.queryInterface(XPrintable.class, xComponent);
xPrintable.print(printProperties);

try { Thread.sleep(10000); } catch (Exception e) {} // Wait for print job.

关于java - 执行调度同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37692575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com