-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsMenu.java
executable file
·90 lines (58 loc) · 2.32 KB
/
SettingsMenu.java
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
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ItemListener;
import java.util.prefs.Preferences;
import java.awt.event.ItemEvent;
public class SettingsMenu extends JMenu{
JCheckBoxMenuItem allowedMovesCheckBox;
JPopupMenu popup;
JMenuItem depthSearchButton;
public static Preferences settings;
public SettingsMenu(){
super("Settings");
settings = Preferences.userRoot().node("Settings");
//add check box
allowedMovesCheckBox = new JCheckBoxMenuItem("Show allowed moves", settings.getBoolean("showPossibleMoves",false));
allowedMovesCheckBox.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
settings.putBoolean("showPossibleMoves", false);
}
else if (e.getStateChange() == ItemEvent.SELECTED) {
settings.putBoolean("showPossibleMoves", true);
}
}
});
//create popup object
popup = new JPopupMenu();
popup.setPopupSize(200,60);
popup.setBorderPainted(true);
final JSlider slider = new JSlider(1,20,settings.getInt("depth", 10));
slider.setMajorTickSpacing(2);
slider.setSnapToTicks(true);
slider.setPaintLabels(true);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e)
{
//System.out.println(slider.getValue());
settings.putInt("depth", slider.getValue());
}
});
popup.add(slider);
//add button to invoke depth popup
depthSearchButton = new JMenuItem("Set Search Depth");
depthSearchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
popup.show(getParent().getParent(), 150, 200);
}
});
add(depthSearchButton);
addSeparator();
add(allowedMovesCheckBox);
}
}