2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.util.MessageManager;
25 import java.awt.Container;
26 import java.awt.Rectangle;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.WindowEvent;
30 import java.awt.event.WindowListener;
32 import javax.swing.JButton;
33 import javax.swing.JDialog;
34 import javax.swing.JPanel;
37 * Boilerplate dialog class. Implements basic functionality necessary for model
38 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
44 public abstract class JalviewDialog extends JPanel
47 protected JDialog frame;
49 protected JButton ok = new JButton();
51 protected JButton cancel = new JButton();
53 boolean block = false;
55 public void waitForInput()
59 new Thread(new Runnable()
64 frame.setVisible(true);
71 frame.setVisible(true);
75 protected void initDialogFrame(Container content, boolean modal,
76 boolean block, String title, int width, int height)
79 frame = new JDialog(Desktop.instance, modal);
80 frame.setTitle(title);
81 if (Desktop.instance != null)
83 Rectangle deskr = Desktop.instance.getBounds();
84 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
85 (int) (deskr.getCenterY() - height / 2), width, height));
89 frame.setSize(width, height);
91 frame.setContentPane(content);
95 ok.setText(MessageManager.getString("action.ok"));
96 ok.addActionListener(new ActionListener()
98 public void actionPerformed(ActionEvent e)
104 cancel.setOpaque(false);
105 cancel.setText(MessageManager.getString("action.cancel"));
106 cancel.addActionListener(new ActionListener()
108 public void actionPerformed(ActionEvent e)
114 frame.addWindowListener(new WindowListener()
118 public void windowOpened(WindowEvent e)
120 // TODO Auto-generated method stub
125 public void windowIconified(WindowEvent e)
127 // TODO Auto-generated method stub
132 public void windowDeiconified(WindowEvent e)
134 // TODO Auto-generated method stub
139 public void windowDeactivated(WindowEvent e)
141 // TODO Auto-generated method stub
146 public void windowClosing(WindowEvent e)
148 // user has cancelled the dialog
153 public void windowClosed(WindowEvent e)
158 public void windowActivated(WindowEvent e)
160 // TODO Auto-generated method stub
167 * clean up and raise the 'dialog closed' event by calling raiseClosed
169 protected void closeDialog()
175 } catch (Exception ex)
180 protected abstract void raiseClosed();
182 protected abstract void okPressed();
184 protected abstract void cancelPressed();