File: ShowKeysScreen.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (107 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package tim.prune.function.info;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import tim.prune.App;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;

/**
 * Class to show a guide to the shortcut keys
 */
public class ShowKeysScreen extends GenericFunction
{
	/** dialog window */
	private JDialog _dialog = null;
	/** Ok button */
	private JButton _okButton = null;


	/**
	 * Constructor
	 * @param inApp app object
	 */
	public ShowKeysScreen(App inApp)
	{
		super(inApp);
	}

	/**
	 * Get the name key
	 */
	public String getNameKey() {
		return "function.showkeys";
	}

	/**
	 * Show the screen
	 */
	public void begin()
	{
		if (_dialog == null)
		{
			_dialog = new JDialog(_parentFrame, getName());
			_dialog.getContentPane().add(makeContents());
			_dialog.pack();
		}
		_dialog.setLocationRelativeTo(_parentFrame);
		_dialog.setVisible(true);
		_okButton.requestFocus();
	}

	/**
	 * @return the contents of the window as a Component
	 */
	private Component makeContents()
	{
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		JLabel introLabel = new JLabel(I18nManager.getText("dialog.keys.intro") + " :");
		introLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
		mainPanel.add(introLabel, BorderLayout.NORTH);

		String keyText = I18nManager.getText("dialog.keys.keylist");
		// If running on Mac, do global replace on "Ctrl" (or "Strg") for "Command" (or lang-specific text)
		if (System.getProperty("mrj.version") != null)
		{
			String mod = I18nManager.getText("dialog.keys.normalmodifier");
			String macmod = I18nManager.getText("dialog.keys.macmodifier");
			if (mod != null && macmod != null && mod.length() > 1 && macmod.length() > 1) {
				keyText = keyText.replaceAll(mod, macmod);
			}
		}
		JEditorPane kp = new JEditorPane("text/html", keyText);
		kp.setEditable(false);
		kp.setOpaque(false);
		kp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		mainPanel.add(new JScrollPane(kp), BorderLayout.CENTER);

		// OK button at the bottom
		JPanel okPanel = new JPanel();
		okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		_okButton = new JButton(I18nManager.getText("button.ok"));
		_okButton.addActionListener(e -> _dialog.dispose());
		_okButton.addKeyListener(new KeyListener() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
			}
			public void keyTyped(KeyEvent e) {}
			public void keyReleased(KeyEvent e) {}
		});
		okPanel.add(_okButton);
		mainPanel.add(okPanel, BorderLayout.SOUTH);
		return mainPanel;
	}
}