3 import java.awt.Container;
4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.WindowEvent;
8 import java.awt.event.WindowListener;
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JPanel;
15 * Boilerplate dialog class. Implements basic functionality necessary for model blocking/non-blocking dialogs
16 * with an OK and Cancel button ready to add to the content pane.
20 public abstract class JalviewDialog extends JPanel
23 protected JDialog frame;
24 protected JButton ok = new JButton();
25 protected JButton cancel = new JButton();
28 public void waitForInput()
32 new Thread(new Runnable()
37 frame.setVisible(true);
44 frame.setVisible(true);
48 protected void initDialogFrame(Container content,
49 boolean modal, boolean block, String title, int width, int height)
52 frame = new JDialog(Desktop.instance, true);
53 frame.setTitle(title);
54 if (Desktop.instance!=null)
56 Rectangle deskr = Desktop.instance.getBounds();
57 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width/2),
58 (int) (deskr.getCenterY() - height/2), width, height));
60 frame.setSize(width,height);
62 frame.setContentPane(content);
67 ok.addActionListener(new ActionListener()
69 public void actionPerformed(ActionEvent e)
75 cancel.setOpaque(false);
76 cancel.setText("Cancel");
77 cancel.addActionListener(new ActionListener()
79 public void actionPerformed(ActionEvent e)
85 frame.addWindowListener(new WindowListener()
89 public void windowOpened(WindowEvent e)
91 // TODO Auto-generated method stub
96 public void windowIconified(WindowEvent e)
98 // TODO Auto-generated method stub
103 public void windowDeiconified(WindowEvent e)
105 // TODO Auto-generated method stub
110 public void windowDeactivated(WindowEvent e)
112 // TODO Auto-generated method stub
117 public void windowClosing(WindowEvent e)
119 // user has cancelled the dialog
124 public void windowClosed(WindowEvent e)
129 public void windowActivated(WindowEvent e)
131 // TODO Auto-generated method stub
137 * clean up and raise the 'dialog closed' event by calling raiseClosed
139 protected void closeDialog()
145 } catch (Exception ex)
150 protected abstract void raiseClosed();
151 protected abstract void okPressed();
152 protected abstract void cancelPressed();