3 import java.awt.Container;
4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
8 import javax.swing.JButton;
9 import javax.swing.JDialog;
10 import javax.swing.JPanel;
13 * Boilerplate dialog class. Implements basic functionality necessary for model blocking/non-blocking dialogs
14 * with an OK and Cancel button ready to add to the content pane.
18 public abstract class JalviewDialog extends JPanel
21 protected JDialog frame;
22 protected JButton ok = new JButton();
23 protected JButton cancel = new JButton();
26 public void waitForInput()
30 new Thread(new Runnable()
46 protected void initDialogFrame(Container content,
47 boolean modal, boolean block, String title, int width, int height)
50 frame = new JDialog(Desktop.instance, true);
51 frame.setTitle(title);
52 if (Desktop.instance!=null)
54 Rectangle deskr = Desktop.instance.getBounds();
55 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width/2),
56 (int) (deskr.getCenterY() - height/2), width, height));
58 frame.setSize(width,height);
60 frame.setContentPane(content);
65 ok.addActionListener(new ActionListener()
67 public void actionPerformed(ActionEvent e)
73 cancel.setOpaque(false);
74 cancel.setText("Cancel");
75 cancel.addActionListener(new ActionListener()
77 public void actionPerformed(ActionEvent e)
86 * clean up and raise the 'dialog closed' event by calling raiseClosed
88 protected void closeDialog()
94 } catch (Exception ex)
99 protected abstract void raiseClosed();
100 protected abstract void okPressed();
101 protected abstract void cancelPressed();