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
|
package tim.prune.function;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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, I18nManager.getText(getNameKey()));
_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);
JEditorPane kp = new JEditorPane("text/html", I18nManager.getText("dialog.keys.keylist"));
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(new ActionListener()
{
public void actionPerformed(ActionEvent 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;
}
}
|