01: package tijmp.ui;
02:
03: import java.awt.BorderLayout;
04: import java.awt.FlowLayout;
05: import java.awt.event.ActionEvent;
06: import java.awt.event.KeyEvent;
07: import javax.swing.AbstractAction;
08: import javax.swing.JButton;
09: import javax.swing.JComponent;
10: import javax.swing.JFrame;
11: import javax.swing.JPanel;
12: import javax.swing.KeyStroke;
13: import tijmp.actions.FrameCloser;
14:
15: /** A class that can show a simple window with a single component in it.
16: */
17: public class ShowSimpleFrame {
18: public void showFrame(String title, JComponent p) {
19: JFrame f = new JFrame(title);
20: f.add(p, BorderLayout.CENTER);
21: f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
22: JPanel buttons = new JPanel();
23: buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
24: final JButton close = new JButton(new FrameCloser(f));
25: buttons.add(close);
26: f.getRootPane().setDefaultButton(close);
27:
28: /** Map escape to close the frame */
29: close.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
30: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "abort");
31: close.getActionMap().put("abort", new AbstractAction() {
32: public void actionPerformed(ActionEvent e) {
33: close.doClick();
34: }
35: });
36:
37: f.add(buttons, BorderLayout.SOUTH);
38: f.pack();
39: f.setVisible(true);
40: }
41: }
|