2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import java.awt.Container;
21 import java.awt.Rectangle;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.WindowEvent;
25 import java.awt.event.WindowListener;
27 import javax.swing.JButton;
28 import javax.swing.JDialog;
29 import javax.swing.JPanel;
32 * Boilerplate dialog class. Implements basic functionality necessary for model
33 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
39 public abstract class JalviewDialog extends JPanel
42 protected JDialog frame;
44 protected JButton ok = new JButton();
46 protected JButton cancel = new JButton();
48 boolean block = false;
50 public void waitForInput()
54 new Thread(new Runnable()
59 frame.setVisible(true);
66 frame.setVisible(true);
70 protected void initDialogFrame(Container content, boolean modal,
71 boolean block, String title, int width, int height)
74 frame = new JDialog(Desktop.instance, modal);
75 frame.setTitle(title);
76 if (Desktop.instance != null)
78 Rectangle deskr = Desktop.instance.getBounds();
79 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
80 (int) (deskr.getCenterY() - height / 2), width, height));
84 frame.setSize(width, height);
86 frame.setContentPane(content);
91 ok.addActionListener(new ActionListener()
93 public void actionPerformed(ActionEvent e)
99 cancel.setOpaque(false);
100 cancel.setText("Cancel");
101 cancel.addActionListener(new ActionListener()
103 public void actionPerformed(ActionEvent e)
109 frame.addWindowListener(new WindowListener()
113 public void windowOpened(WindowEvent e)
115 // TODO Auto-generated method stub
120 public void windowIconified(WindowEvent e)
122 // TODO Auto-generated method stub
127 public void windowDeiconified(WindowEvent e)
129 // TODO Auto-generated method stub
134 public void windowDeactivated(WindowEvent e)
136 // TODO Auto-generated method stub
141 public void windowClosing(WindowEvent e)
143 // user has cancelled the dialog
148 public void windowClosed(WindowEvent e)
153 public void windowActivated(WindowEvent e)
155 // TODO Auto-generated method stub
162 * clean up and raise the 'dialog closed' event by calling raiseClosed
164 protected void closeDialog()
170 } catch (Exception ex)
175 protected abstract void raiseClosed();
177 protected abstract void okPressed();
179 protected abstract void cancelPressed();