package jalview.gui;
import java.awt.Component;
-import java.awt.Container;
import java.awt.Dialog.ModalityType;
import java.awt.HeadlessException;
import java.awt.Window;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import jalview.util.Platform;
private Component parentComponent;
- private Map<Object, Callable> callbacks = new HashMap<>();
+ private Map<Object, Callable<Void>> callbacks = new HashMap<>();
/*
* JalviewJS reports user choice in the dialog as the selected
initialValueButton = jb;
int buttonAction = buttonActions[i];
- Callable action = callbacks.get(buttonAction);
+ Callable<Void> action = callbacks.get(buttonAction);
jb.setText((String) o);
jb.addActionListener(new ActionListener()
{
{
Object obj = e.getSource();
- Object joptionpaneObject = getAncestorClass(obj,
- JOptionPane.class);
+ if (obj == null || !(obj instanceof Component))
+ {
+ jalview.bin.Console.debug(
+ "Could not find Component source of event object "
+ + obj);
+ return;
+ }
+ Object joptionpaneObject = SwingUtilities.getAncestorOfClass(
+ JOptionPane.class, (Component) obj);
if (joptionpaneObject == null
|| !(joptionpaneObject instanceof JOptionPane))
{
joptionpane.setValue(buttonAction);
if (action != null)
Executors.newSingleThreadExecutor().submit(action);
- // joptionpane.transferFocusBackward();
joptionpane.transferFocusBackward();
joptionpane.setVisible(false);
- // put focus and raise parent window if possible, unless cancel
- // button pressed
+ // put focus and raise parent window if possible, unless cancel or
+ // no button pressed
boolean raiseParent = (parentComponent != null);
if (buttonAction == JOptionPane.CANCEL_OPTION)
raiseParent = false;
}
*/
@Override
- public JvOptionPane setResponseHandler(Object response, Callable action)
+ public JvOptionPane setResponseHandler(Object response,
+ Callable<Void> action)
{
callbacks.put(response, action);
return this;
{
Object o = options[i];
int buttonAction = buttonActions[i];
- Callable action = callbacks.get(buttonAction);
+ Callable<Void> action = callbacks.get(buttonAction);
JButton jb;
if (buttons != null && buttons.length > i && buttons[i] != null)
{
return false;
}
-
- /**
- * Get parent JOptionPane if there is one
- */
- public static Container getAncestorClass(Object o, Class cl)
- {
- Container c;
- if (o instanceof Container)
- c = (Container) o;
- else
- return null;
- Container p = c.getParent();
- if (p == null)
- return null;
- if (p.getClass() == cl)
- {
- return p;
- }
- else if (p instanceof Component)
- {
- return getAncestorClass((Component) p, cl);
- }
- return null;
- }
}