2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import java.awt.Container;
22 import java.awt.Rectangle;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.WindowEvent;
26 import java.awt.event.WindowListener;
28 import javax.swing.JButton;
29 import javax.swing.JDialog;
30 import javax.swing.JPanel;
33 * Boilerplate dialog class. Implements basic functionality necessary for model
34 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
40 public abstract class JalviewDialog extends JPanel
43 protected JDialog frame;
45 protected JButton ok = new JButton();
47 protected JButton cancel = new JButton();
49 boolean block = false;
51 public void waitForInput()
55 new Thread(new Runnable()
60 frame.setVisible(true);
67 frame.setVisible(true);
71 protected void initDialogFrame(Container content, boolean modal,
72 boolean block, String title, int width, int height)
75 frame = new JDialog(Desktop.instance, modal);
76 frame.setTitle(title);
77 if (Desktop.instance != null)
79 Rectangle deskr = Desktop.instance.getBounds();
80 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
81 (int) (deskr.getCenterY() - height / 2), width, height));
85 frame.setSize(width, height);
87 frame.setContentPane(content);
92 ok.addActionListener(new ActionListener()
94 public void actionPerformed(ActionEvent e)
100 cancel.setOpaque(false);
101 cancel.setText("Cancel");
102 cancel.addActionListener(new ActionListener()
104 public void actionPerformed(ActionEvent e)
110 frame.addWindowListener(new WindowListener()
114 public void windowOpened(WindowEvent e)
116 // TODO Auto-generated method stub
121 public void windowIconified(WindowEvent e)
123 // TODO Auto-generated method stub
128 public void windowDeiconified(WindowEvent e)
130 // TODO Auto-generated method stub
135 public void windowDeactivated(WindowEvent e)
137 // TODO Auto-generated method stub
142 public void windowClosing(WindowEvent e)
144 // user has cancelled the dialog
149 public void windowClosed(WindowEvent e)
154 public void windowActivated(WindowEvent e)
156 // TODO Auto-generated method stub
163 * clean up and raise the 'dialog closed' event by calling raiseClosed
165 protected void closeDialog()
171 } catch (Exception ex)
176 protected abstract void raiseClosed();
178 protected abstract void okPressed();
180 protected abstract void cancelPressed();