]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/ShowKeysScreen.java
Version 11, August 2010
[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                 String keyText = I18nManager.getText("dialog.keys.keylist");
78                 // If running on Mac, do global replace on "Ctrl" (or "Strg") for "Command" (or lang-specific text)
79                 if (System.getProperty("mrj.version") != null) {
80                         String mod = I18nManager.getText("dialog.keys.normalmodifier");
81                         String macmod = I18nManager.getText("dialog.keys.macmodifier");
82                         if (mod != null && macmod != null && mod.length() > 1 && macmod.length() > 1) {
83                                 keyText = keyText.replaceAll(mod, macmod);
84                         }
85                 }
86                 JEditorPane kp = new JEditorPane("text/html", keyText);
87                 kp.setEditable(false);
88                 kp.setOpaque(false);
89                 kp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
90                 mainPanel.add(new JScrollPane(kp), BorderLayout.CENTER);
91
92                 // OK button at the bottom
93                 JPanel okPanel = new JPanel();
94                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
95                 _okButton = new JButton(I18nManager.getText("button.ok"));
96                 _okButton.addActionListener(new ActionListener()
97                 {
98                         public void actionPerformed(ActionEvent e)
99                         {
100                                 _dialog.dispose();
101                         }
102                 });
103                 _okButton.addKeyListener(new KeyListener() {
104                         public void keyPressed(KeyEvent e)
105                         {
106                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
107                         }
108                         public void keyTyped(KeyEvent e) {}
109                         public void keyReleased(KeyEvent e) {}
110                 });
111                 okPanel.add(_okButton);
112                 mainPanel.add(okPanel, BorderLayout.SOUTH);
113                 return mainPanel;
114         }
115 }