| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package uk.co.javagear; |
| 22 |
|
|
| 23 |
|
import java.awt.Dimension; |
| 24 |
|
import java.awt.Graphics; |
| 25 |
|
import java.awt.GridLayout; |
| 26 |
|
import java.awt.Toolkit; |
| 27 |
|
import java.awt.event.ActionEvent; |
| 28 |
|
import java.awt.event.ActionListener; |
| 29 |
|
import java.awt.event.WindowAdapter; |
| 30 |
|
import java.awt.event.WindowEvent; |
| 31 |
|
import javax.swing.JButton; |
| 32 |
|
import javax.swing.JFrame; |
| 33 |
|
import javax.swing.JPanel; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
0 |
public final class KeyFrame extends JFrame implements ActionListener { |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
private Controllers controllers; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
private KeyConfig keyConfig; |
| 53 |
|
|
| 54 |
|
private JPanel buttons; |
| 55 |
|
|
| 56 |
|
private JButton ok; |
| 57 |
|
|
| 58 |
|
private JButton cancel; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
0 |
public KeyFrame(Controllers c) { |
| 67 |
0 |
this.controllers = c; |
| 68 |
0 |
setTitle("Key Configuration"); |
| 69 |
|
|
| 70 |
|
|
| 71 |
0 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
| 72 |
0 |
Dimension d = tk.getScreenSize(); |
| 73 |
|
|
| 74 |
0 |
setLocation(d.width / 4, d.height / 4); |
| 75 |
|
|
| 76 |
0 |
keyConfig = new KeyConfig(); |
| 77 |
0 |
getContentPane().add(keyConfig); |
| 78 |
|
|
| 79 |
0 |
keyConfig.setKeys(controllers.getKeys()); |
| 80 |
|
|
| 81 |
0 |
addWindowListener(new WindowAdapter() { |
| 82 |
|
public void windowClosing(WindowEvent e) { |
| 83 |
0 |
keyConfig.setKeys(controllers.getKeys()); |
| 84 |
0 |
setVisible(false); |
| 85 |
0 |
} |
| 86 |
|
}); |
| 87 |
|
|
| 88 |
0 |
buttons = new JPanel(new GridLayout(1, 2)); |
| 89 |
|
|
| 90 |
0 |
ok = new JButton("OK"); |
| 91 |
0 |
cancel = new JButton("Cancel"); |
| 92 |
0 |
buttons.add(ok); |
| 93 |
0 |
buttons.add(cancel); |
| 94 |
|
|
| 95 |
0 |
getContentPane().add(buttons, "South"); |
| 96 |
|
|
| 97 |
0 |
ok.addActionListener(this); |
| 98 |
0 |
cancel.addActionListener(this); |
| 99 |
|
|
| 100 |
0 |
setResizable(false); |
| 101 |
0 |
pack(); |
| 102 |
0 |
} |
| 103 |
|
|
| 104 |
|
public void actionPerformed(ActionEvent evt) { |
| 105 |
0 |
if (evt.getSource() == ok) { |
| 106 |
0 |
controllers.setKeys(keyConfig.getKeys()); |
| 107 |
0 |
this.setVisible(false); |
| 108 |
0 |
} else if (evt.getSource() == cancel) { |
| 109 |
0 |
keyConfig.setKeys(controllers.getKeys()); |
| 110 |
0 |
this.setVisible(false); |
| 111 |
|
} |
| 112 |
0 |
} |
| 113 |
|
|
| 114 |
|
public void paint(Graphics g) { |
| 115 |
0 |
keyConfig.refresh(); |
| 116 |
0 |
buttons.repaint(); |
| 117 |
0 |
} |
| 118 |
|
|
| 119 |
|
} |