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 jalview.util.MessageManager;
23 import java.awt.Container;
24 import java.awt.Rectangle;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.WindowEvent;
28 import java.awt.event.WindowListener;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JPanel;
35 * Boilerplate dialog class. Implements basic functionality necessary for model
36 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
42 public abstract class JalviewDialog extends JPanel
45 protected JDialog frame;
47 protected JButton ok = new JButton();
49 protected JButton cancel = new JButton();
51 boolean block = false;
53 public void waitForInput()
57 new Thread(new Runnable()
62 frame.setVisible(true);
69 frame.setVisible(true);
73 protected void initDialogFrame(Container content, boolean modal,
74 boolean block, String title, int width, int height)
77 frame = new JDialog(Desktop.instance, modal);
78 frame.setTitle(title);
79 if (Desktop.instance != null)
81 Rectangle deskr = Desktop.instance.getBounds();
82 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
83 (int) (deskr.getCenterY() - height / 2), width, height));
87 frame.setSize(width, height);
89 frame.setContentPane(content);
93 ok.setText(MessageManager.getString("action.ok"));
94 ok.addActionListener(new ActionListener()
96 public void actionPerformed(ActionEvent e)
102 cancel.setOpaque(false);
103 cancel.setText(MessageManager.getString("action.cancel"));
104 cancel.addActionListener(new ActionListener()
106 public void actionPerformed(ActionEvent e)
112 frame.addWindowListener(new WindowListener()
116 public void windowOpened(WindowEvent e)
118 // TODO Auto-generated method stub
123 public void windowIconified(WindowEvent e)
125 // TODO Auto-generated method stub
130 public void windowDeiconified(WindowEvent e)
132 // TODO Auto-generated method stub
137 public void windowDeactivated(WindowEvent e)
139 // TODO Auto-generated method stub
144 public void windowClosing(WindowEvent e)
146 // user has cancelled the dialog
151 public void windowClosed(WindowEvent e)
156 public void windowActivated(WindowEvent e)
158 // TODO Auto-generated method stub
165 * clean up and raise the 'dialog closed' event by calling raiseClosed
167 protected void closeDialog()
173 } catch (Exception ex)
178 protected abstract void raiseClosed();
180 protected abstract void okPressed();
182 protected abstract void cancelPressed();