2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.Dimension;
27 import java.awt.Rectangle;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.WindowEvent;
31 import java.awt.event.WindowListener;
33 import javax.swing.JButton;
34 import javax.swing.JDialog;
35 import javax.swing.JPanel;
38 * Boilerplate dialog class. Implements basic functionality necessary for model
39 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
45 public abstract class JalviewDialog extends JPanel
48 protected JDialog frame;
50 protected JButton ok = new JButton();
52 protected JButton cancel = new JButton();
54 boolean block = false;
56 private int DEFAULT_MIN_WIDTH = 300;
58 private int DEFAULT_MIN_HEIGHT = 250;
60 public void waitForInput()
64 new Thread(new Runnable()
70 frame.setVisible(true);
77 frame.setVisible(true);
81 protected void initDialogFrame(Container content, boolean modal,
82 boolean block, String title, int width, int height)
85 frame = new JDialog(Desktop.instance, modal);
86 frame.setTitle(title);
87 if (Desktop.instance != null)
89 Rectangle deskr = Desktop.instance.getBounds();
90 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
91 (int) (deskr.getCenterY() - height / 2), width, height));
95 frame.setSize(width, height);
97 int minWidth = width - 100;
98 int minHeight = height - 100;
99 frame.setMinimumSize(new Dimension(minWidth, minHeight));
100 frame.setContentPane(content);
104 ok.setText(MessageManager.getString("action.ok"));
105 ok.addActionListener(new ActionListener()
108 public void actionPerformed(ActionEvent e)
114 cancel.setOpaque(false);
115 cancel.setText(MessageManager.getString("action.cancel"));
116 cancel.addActionListener(new ActionListener()
119 public void actionPerformed(ActionEvent e)
125 frame.addWindowListener(new WindowListener()
129 public void windowOpened(WindowEvent e)
131 // TODO Auto-generated method stub
136 public void windowIconified(WindowEvent e)
138 // TODO Auto-generated method stub
143 public void windowDeiconified(WindowEvent e)
145 // TODO Auto-generated method stub
150 public void windowDeactivated(WindowEvent e)
152 // TODO Auto-generated method stub
157 public void windowClosing(WindowEvent e)
159 // user has cancelled the dialog
164 public void windowClosed(WindowEvent e)
169 public void windowActivated(WindowEvent e)
171 // TODO Auto-generated method stub
178 * clean up and raise the 'dialog closed' event by calling raiseClosed
180 protected void closeDialog()
186 } catch (Exception ex)
191 protected abstract void raiseClosed();
193 protected abstract void okPressed();
195 protected abstract void cancelPressed();