import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.beans.PropertyVetoException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Random;
import java.util.Vector;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
if (!forceClose)
{
String viewerName = getViewerName();
+
+ int confirm = JvOptionPane.CANCEL_OPTION;
String prompt = MessageManager
.formatMessage("label.confirm_close_viewer", new Object[]
{ binding.getViewerTitle(viewerName, false), viewerName });
prompt = JvSwingUtils.wrapTooltip(true, prompt);
- int confirm = JvOptionPane.showConfirmDialog(this, prompt,
- MessageManager.getString("label.close_viewer"),
- JvOptionPane.YES_NO_CANCEL_OPTION);
+ String title = MessageManager.getString("label.close_viewer");
+ confirm = showCloseDialog(title, prompt);
+
/*
* abort closure if user hits escape or Cancel
*/
{
// abort possible quit handling if CANCEL chosen
if (confirm == JvOptionPane.CANCEL_OPTION)
+ {
+ try
+ {
+ // this is a bit futile
+ this.setClosed(false);
+ } catch (PropertyVetoException e)
+ {
+ }
QuitHandler.abortQuit();
+ }
return;
}
forceClose = confirm == JvOptionPane.YES_OPTION;
dispose();
}
+ private int showCloseDialog(final String title, final String prompt)
+ {
+ confirmResponse = JvOptionPane.CANCEL_OPTION;
+
+ if (QuitHandler.quitting())
+ {
+
+ Callable<Void> yesCall = () -> {
+ Console.debug("YES");
+ confirmResponse = JvOptionPane.YES_OPTION;
+ return null;
+ };
+ Callable<Void> noCall = () -> {
+ Console.debug("NO");
+ confirmResponse = JvOptionPane.NO_OPTION;
+ return null;
+ };
+ Callable<Void> cancelCall = () -> {
+ Console.debug("CANCEL");
+ confirmResponse = JvOptionPane.CANCEL_OPTION;
+ return null;
+ };
+ Callable<Void>[] calls = new Callable[] { yesCall, noCall,
+ cancelCall };
+ String cancelQuit = MessageManager.getString("action.cancel_quit");
+ String[] buttonsText = { MessageManager.getString("action.yes"),
+ MessageManager.getString("action.no"), cancelQuit };
+ JvOptionPane dialog = JvOptionPane.frameDialog(prompt,
+ MessageManager.getString("label.close_viewer"),
+ JvOptionPane.WARNING_MESSAGE, buttonsText, cancelQuit, calls,
+ false);
+ // wait for response
+ ExecutorService executor = dialog.getExecutor();
+ executor.shutdown();
+ try
+ {
+ Console.debug("### executor.awaitTermination() starting");
+ executor.awaitTermination(60, TimeUnit.SECONDS);
+ Console.debug("### executor.awaitTermination() finished");
+ } catch (InterruptedException e)
+ {
+ }
+ }
+ else
+ {
+ confirmResponse = JvOptionPane.showConfirmDialog(this, prompt,
+ MessageManager.getString("label.close_viewer"),
+ JvOptionPane.YES_NO_CANCEL_OPTION,
+ JvOptionPane.WARNING_MESSAGE);
+ }
+ return confirmResponse;
+ }
+
@Override
public void showHelp_actionPerformed()
{
&& viewerActionMenu.getItemCount() > 0
&& viewerActionMenu.isVisible();
}
+
+ private static int confirmResponse = 0;
}