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.bin.Instance;
24 import jalview.util.MessageManager;
26 import java.awt.Container;
27 import java.awt.Dimension;
28 import java.awt.Rectangle;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.WindowAdapter;
32 import java.awt.event.WindowEvent;
34 import javax.swing.JButton;
35 import javax.swing.JDialog;
36 import javax.swing.JPanel;
39 * Boilerplate dialog class. Implements basic functionality necessary for model
40 * blocking/non-blocking dialogs with an OK and Cancel button ready to add to
46 public abstract class JalviewDialog extends JPanel
49 protected JDialog frame;
51 protected JButton ok = new JButton();
53 protected JButton cancel = new JButton();
55 boolean block = false;
57 public void waitForInput()
61 new Thread(new Runnable()
67 frame.setVisible(true);
74 frame.setVisible(true);
78 protected void initDialogFrame(Container content, boolean modal,
79 boolean block, String title, int width, int height)
82 frame = new JDialog(Instance.getDesktop(), modal);
83 frame.setTitle(title);
84 if (Instance.getDesktop() != null)
86 Rectangle deskr = Instance.getDesktop().getBounds();
87 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2),
88 (int) (deskr.getCenterY() - height / 2), width, height));
92 frame.setSize(width, height);
94 int minWidth = width - 100;
95 int minHeight = height - 100;
96 frame.setMinimumSize(new Dimension(minWidth, minHeight));
97 frame.setContentPane(content);
101 ok.setText(MessageManager.getString("action.ok"));
102 ok.addActionListener(new ActionListener()
105 public void actionPerformed(ActionEvent e)
111 cancel.setOpaque(false);
112 cancel.setText(MessageManager.getString("action.cancel"));
113 cancel.addActionListener(new ActionListener()
116 public void actionPerformed(ActionEvent e)
122 frame.addWindowListener(new WindowAdapter()
125 public void windowClosing(WindowEvent e)
127 // user has cancelled the dialog
134 * clean up and raise the 'dialog closed' event by calling raiseClosed
136 protected void closeDialog()
142 } catch (Exception ex)
147 protected abstract void raiseClosed();
149 protected abstract void okPressed();
151 protected abstract void cancelPressed();