keyboard: add shortcut keys to Game menu
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@770 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
a1fc7c20a2
commit
f55492f8b8
2 changed files with 41 additions and 0 deletions
|
@ -400,15 +400,43 @@ public class MainWindow extends JFrame
|
||||||
return pane;
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupKeys(JMenu menu, String prefix)
|
||||||
|
{
|
||||||
|
if (strings.containsKey(prefix+".access_key")) {
|
||||||
|
String mnemonic = strings.getString(prefix+".access_key");
|
||||||
|
menu.setMnemonic(
|
||||||
|
KeyStroke.getKeyStroke(mnemonic).getKeyCode()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupKeys(JMenuItem menuItem, String prefix)
|
||||||
|
{
|
||||||
|
if (strings.containsKey(prefix+".access_key")) {
|
||||||
|
String mnemonic = strings.getString(prefix+".access_key");
|
||||||
|
menuItem.setMnemonic(
|
||||||
|
KeyStroke.getKeyStroke(mnemonic).getKeyCode()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (strings.containsKey(prefix+".shortcut")) {
|
||||||
|
String shortcut = strings.getString(prefix+".shortcut");
|
||||||
|
menuItem.setAccelerator(
|
||||||
|
KeyStroke.getKeyStroke(shortcut)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void makeMenu()
|
private void makeMenu()
|
||||||
{
|
{
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
JMenu gameMenu = new JMenu(strings.getString("menu.game"));
|
JMenu gameMenu = new JMenu(strings.getString("menu.game"));
|
||||||
|
setupKeys(gameMenu, "menu.game");
|
||||||
menuBar.add(gameMenu);
|
menuBar.add(gameMenu);
|
||||||
|
|
||||||
JMenuItem menuItem;
|
JMenuItem menuItem;
|
||||||
menuItem = new JMenuItem(strings.getString("menu.game.new"));
|
menuItem = new JMenuItem(strings.getString("menu.game.new"));
|
||||||
|
setupKeys(menuItem, "menu.game.new");
|
||||||
menuItem.addActionListener(wrapActionListener(
|
menuItem.addActionListener(wrapActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev)
|
public void actionPerformed(ActionEvent ev)
|
||||||
|
@ -419,6 +447,7 @@ public class MainWindow extends JFrame
|
||||||
gameMenu.add(menuItem);
|
gameMenu.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem(strings.getString("menu.game.load"));
|
menuItem = new JMenuItem(strings.getString("menu.game.load"));
|
||||||
|
setupKeys(menuItem, "menu.game.load");
|
||||||
menuItem.addActionListener(wrapActionListener(
|
menuItem.addActionListener(wrapActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev)
|
public void actionPerformed(ActionEvent ev)
|
||||||
|
@ -429,6 +458,7 @@ public class MainWindow extends JFrame
|
||||||
gameMenu.add(menuItem);
|
gameMenu.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem(strings.getString("menu.game.save"));
|
menuItem = new JMenuItem(strings.getString("menu.game.save"));
|
||||||
|
setupKeys(menuItem, "menu.game.save");
|
||||||
menuItem.addActionListener(wrapActionListener(
|
menuItem.addActionListener(wrapActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev)
|
public void actionPerformed(ActionEvent ev)
|
||||||
|
@ -439,6 +469,7 @@ public class MainWindow extends JFrame
|
||||||
gameMenu.add(menuItem);
|
gameMenu.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem(strings.getString("menu.game.save_as"));
|
menuItem = new JMenuItem(strings.getString("menu.game.save_as"));
|
||||||
|
setupKeys(menuItem, "menu.game.save_as");
|
||||||
menuItem.addActionListener(wrapActionListener(
|
menuItem.addActionListener(wrapActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev)
|
public void actionPerformed(ActionEvent ev)
|
||||||
|
@ -449,6 +480,7 @@ public class MainWindow extends JFrame
|
||||||
gameMenu.add(menuItem);
|
gameMenu.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem(strings.getString("menu.game.exit"));
|
menuItem = new JMenuItem(strings.getString("menu.game.exit"));
|
||||||
|
setupKeys(menuItem, "menu.game.exit");
|
||||||
menuItem.addActionListener(wrapActionListener(
|
menuItem.addActionListener(wrapActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev)
|
public void actionPerformed(ActionEvent ev)
|
||||||
|
|
|
@ -69,11 +69,20 @@ menu.overlays.FIRE_OVERLAY = Fire Coverage
|
||||||
menu.overlays.POLICE_OVERLAY = Police Coverage
|
menu.overlays.POLICE_OVERLAY = Police Coverage
|
||||||
|
|
||||||
menu.game = Game
|
menu.game = Game
|
||||||
|
menu.game.access_key = G
|
||||||
menu.game.new = New City...
|
menu.game.new = New City...
|
||||||
|
menu.game.new.access_key = N
|
||||||
|
menu.game.new.shortcut = ctrl N
|
||||||
menu.game.load = Load City...
|
menu.game.load = Load City...
|
||||||
|
menu.game.load.access_key = L
|
||||||
|
menu.game.load.shortcut = ctrl O
|
||||||
menu.game.save = Save City
|
menu.game.save = Save City
|
||||||
|
menu.game.save.access_key = S
|
||||||
|
menu.game.save.shortcut = ctrl S
|
||||||
menu.game.save_as = Save City as...
|
menu.game.save_as = Save City as...
|
||||||
|
menu.game.save_as.access_key = A
|
||||||
menu.game.exit = Exit
|
menu.game.exit = Exit
|
||||||
|
menu.game.exit.access_key = X
|
||||||
|
|
||||||
menu.options = Options
|
menu.options = Options
|
||||||
menu.options.auto_budget = Auto Budget
|
menu.options.auto_budget = Auto Budget
|
||||||
|
|
Reference in a new issue