]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/ShowKeysScreen.java
98a9fdd04428e42ff65cd85155ae060810fcda13
[GpsPrune.git] / tim / prune / function / ShowKeysScreen.java
1 package tim.prune.function;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.FlowLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.KeyEvent;
9 import java.awt.event.KeyListener;
10
11 import javax.swing.BorderFactory;
12 import javax.swing.JButton;
13 import javax.swing.JDialog;
14 import javax.swing.JEditorPane;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JScrollPane;
18
19 import tim.prune.App;
20 import tim.prune.GenericFunction;
21 import tim.prune.I18nManager;
22
23 /**
24  * Class to show a guide to the shortcut keys
25  */
26 public class ShowKeysScreen extends GenericFunction
27 {
28         /** dialog window */
29         private JDialog _dialog = null;
30         /** Ok button */
31         private JButton _okButton = null;
32
33
34         /**
35          * Constructor
36          * @param inApp app object
37          */
38         public ShowKeysScreen(App inApp)
39         {
40                 super(inApp);
41         }
42
43         /**
44          * Get the name key
45          */
46         public String getNameKey() {
47                 return "function.showkeys";
48         }
49
50         /**
51          * Show the screen
52          */
53         public void begin()
54         {
55                 if (_dialog == null)
56                 {
57                         _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
58                         _dialog.getContentPane().add(makeContents());
59                         _dialog.pack();
60                 }
61                 _dialog.setLocationRelativeTo(_parentFrame);
62                 _dialog.setVisible(true);
63                 _okButton.requestFocus();
64         }
65
66         /**
67          * @return the contents of the window as a Component
68          */
69         private Component makeContents()
70         {
71                 JPanel mainPanel = new JPanel();
72                 mainPanel.setLayout(new BorderLayout());
73                 JLabel introLabel = new JLabel(I18nManager.getText("dialog.keys.intro") + " :");
74                 introLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
75                 mainPanel.add(introLabel, BorderLayout.NORTH);
76
77                 JEditorPane kp = new JEditorPane("text/html", I18nManager.getText("dialog.keys.keylist"));
78                 kp.setEditable(false);
79                 kp.setOpaque(false);
80                 kp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
81                 mainPanel.add(new JScrollPane(kp), BorderLayout.CENTER);
82
83                 // OK button at the bottom
84                 JPanel okPanel = new JPanel();
85                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
86                 _okButton = new JButton(I18nManager.getText("button.ok"));
87                 _okButton.addActionListener(new ActionListener()
88                 {
89                         public void actionPerformed(ActionEvent e)
90                         {
91                                 _dialog.dispose();
92                         }
93                 });
94                 _okButton.addKeyListener(new KeyListener() {
95                         public void keyPressed(KeyEvent e)
96                         {
97                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
98                         }
99                         public void keyTyped(KeyEvent e) {}
100                         public void keyReleased(KeyEvent e) {}
101                 });
102                 okPanel.add(_okButton);
103                 mainPanel.add(okPanel, BorderLayout.SOUTH);
104                 return mainPanel;
105         }
106 }