1 package tim.prune.function;
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;
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;
20 import tim.prune.GenericFunction;
21 import tim.prune.I18nManager;
24 * Class to show a guide to the shortcut keys
26 public class ShowKeysScreen extends GenericFunction
29 private JDialog _dialog = null;
31 private JButton _okButton = null;
36 * @param inApp app object
38 public ShowKeysScreen(App inApp)
46 public String getNameKey() {
47 return "function.showkeys";
57 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
58 _dialog.getContentPane().add(makeContents());
61 _dialog.setLocationRelativeTo(_parentFrame);
62 _dialog.setVisible(true);
63 _okButton.requestFocus();
67 * @return the contents of the window as a Component
69 private Component makeContents()
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);
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);
86 JEditorPane kp = new JEditorPane("text/html", keyText);
87 kp.setEditable(false);
89 kp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
90 mainPanel.add(new JScrollPane(kp), BorderLayout.CENTER);
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()
98 public void actionPerformed(ActionEvent e)
103 _okButton.addKeyListener(new KeyListener() {
104 public void keyPressed(KeyEvent e)
106 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
108 public void keyTyped(KeyEvent e) {}
109 public void keyReleased(KeyEvent e) {}
111 okPanel.add(_okButton);
112 mainPanel.add(okPanel, BorderLayout.SOUTH);