Skip to content

Commit

Permalink
GUI preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
SudokuMonster committed Dec 31, 2019
1 parent c4276d7 commit 5209cfb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
17 changes: 15 additions & 2 deletions diuf/sudoku/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Settings {

public final static int VERSION = 1;
public final static int REVISION = 15;
public final static String SUBREV = ".6";
public final static String SUBREV = ".7";
public final static String releaseDate = "2019-12-31";
public final static String releaseYear = "2019";
public final static String releaseLicence = "Lesser General Public License";
Expand Down Expand Up @@ -610,7 +610,19 @@ public void load() {
isShowingCandidates = prefs.getBoolean("isShowingCandidates", isShowingCandidates);
isShowingCandidateMasks = prefs.getBoolean("isShowingCandidateMasks", isShowingCandidateMasks);
isBringBackSE121 = prefs.getBoolean("BringBackSE121", isBringBackSE121);
revisedRating = prefs.getInt("RevisedRatings", revisedRating);
isBlocks = prefs.getBoolean("isBlocks", isBlocks);
isX = prefs.getBoolean("isX", isX);
isDG = prefs.getBoolean("isDG", isDG);
isWindows = prefs.getBoolean("isWindows", isWindows);
isAsterisk = prefs.getBoolean("isAsterisk", isAsterisk);
isCD = prefs.getBoolean("isCD", isCD);
isGirandola = prefs.getBoolean("isGirandola", isGirandola);
isForbiddenPairs = prefs.getBoolean("isForbiddenPairs", isForbiddenPairs);
whichNC = prefs.getInt("whichNC", whichNC);
isAntiFerz = prefs.getBoolean("isAntiFerz", isAntiFerz);
isAntiKnight = prefs.getBoolean("isAntiKnight", isAntiKnight);
isToroidal = prefs.getBoolean("isToroidal", isToroidal);
revisedRating = prefs.getInt("RevisedRatings", revisedRating);
lookAndFeelClassName = prefs.get("lookAndFeelClassName", lookAndFeelClassName);
} catch (SecurityException ex) {
// Maybe we are running from an applet. Do nothing
Expand All @@ -637,6 +649,7 @@ public void save() {
prefs.putInt("whichNC", whichNC);
prefs.putBoolean("isAntiFerz", isAntiFerz);
prefs.putBoolean("isAntiKnight", isAntiKnight);
prefs.putBoolean("isToroidal", isToroidal);
prefs.putBoolean("BringBackSE121", isBringBackSE121);
prefs.putInt("RevisedRatings", revisedRating);
if (lookAndFeelClassName != null)
Expand Down
62 changes: 49 additions & 13 deletions diuf/sudoku/gui/SudokuFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,11 @@ private JCheckBoxMenuItem getMitRegularNC() {
if (mitRegularNC == null) {
mitRegularNC = new JCheckBoxMenuItem();
mitRegularNC.setText("NC");
mitRegularNC.setSelected(false);
mitRegularNC.setToolTipText("Adjacent cells can't have consecutive numbers (Excludes 1,9)");
mitRegularNC.setSelected(Settings.getInstance().whichNC() == 1);
if (mitRegularNC.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitRegularNC.setToolTipText("Adjacent cells can't have consecutive numbers (Excludes 1,9)");
mitRegularNC.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
if (mitRegularNC.isSelected()) {
Expand All @@ -1530,7 +1533,10 @@ private JCheckBoxMenuItem getMitCyclicNC() {
if (mitCyclicNC == null) {
mitCyclicNC = new JCheckBoxMenuItem();
mitCyclicNC.setText("NC+");
mitCyclicNC.setSelected(false);
mitCyclicNC.setSelected(Settings.getInstance().whichNC() == 2);
if (mitCyclicNC.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitCyclicNC.setToolTipText("Adjacent cells can't have consecutive numbers (Includes 1,9)");
mitCyclicNC.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand Down Expand Up @@ -1567,7 +1573,10 @@ private JCheckBoxMenuItem getMitToroidal() {
if (mitToroidal == null) {
mitToroidal = new JCheckBoxMenuItem();
mitToroidal.setText("Toroidal Grid");
mitToroidal.setSelected(false);
mitToroidal.setSelected(Settings.getInstance().isToroidal());
if (mitToroidal.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitToroidal.setToolTipText("Top-Bottom and Rt-Lt Wrap giving it a doughnut 3d shape");
mitToroidal.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1588,7 +1597,10 @@ private JCheckBoxMenuItem getMitAntiFerz() {
if (mitAntiFerz == null) {
mitAntiFerz = new JCheckBoxMenuItem();
mitAntiFerz.setText("King: (0,1) and (1,1)");
mitAntiFerz.setSelected(false);
mitAntiFerz.setSelected(Settings.getInstance().isAntiFerz());
if (mitAntiFerz.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitAntiFerz.setToolTipText("Cells that are a King's move away are different");
mitAntiFerz.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1612,7 +1624,10 @@ private JCheckBoxMenuItem getMitAntiKnight() {
if (mitAntiKnight == null) {
mitAntiKnight = new JCheckBoxMenuItem();
mitAntiKnight.setText("Knight: (1,2)");
mitAntiKnight.setSelected(false);
mitAntiKnight.setSelected(Settings.getInstance().isAntiKnight());
if (mitAntiKnight.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitAntiKnight.setToolTipText("Cells that are a Knight's move away are different");
mitAntiKnight.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand Down Expand Up @@ -1651,7 +1666,10 @@ private JCheckBoxMenuItem getMitLQ() {
if (mitLQ == null) {
mitLQ = new JCheckBoxMenuItem();
mitLQ.setText("Remove Blocks (Latin Square)");
mitLQ.setSelected(false);
mitLQ.setSelected(!Settings.getInstance().isBlocks());
if (mitLQ.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitLQ.setToolTipText("Remove Blocks (Popular for Latin Square Puzzles)");
mitLQ.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1674,7 +1692,10 @@ private JCheckBoxMenuItem getMitX() {
if (mitX == null) {
mitX = new JCheckBoxMenuItem();
mitX.setText("X main diagonals");
mitX.setSelected(false);
mitX.setSelected(Settings.getInstance().isX());
if (mitX.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitX.setToolTipText("Adds the 2 main diagonals (X) as constraints");
mitX.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1698,7 +1719,10 @@ private JCheckBoxMenuItem getMitDG() {
if (mitDG == null) {
mitDG = new JCheckBoxMenuItem();
mitDG.setText("Disjoint Groups");
mitDG.setSelected(false);
mitDG.setSelected(Settings.getInstance().isDG());
if (mitDG.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitDG.setToolTipText("Add 9 disjoint groups");
mitDG.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1722,7 +1746,10 @@ private JCheckBoxMenuItem getMitWindows() {
if (mitWindows == null) {
mitWindows = new JCheckBoxMenuItem();
mitWindows.setText("Windows");
mitWindows.setSelected(false);
mitWindows.setSelected(Settings.getInstance().isWindows());
if (mitWindows.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitWindows.setToolTipText("Add Window groups (Use for Windoku, Hypersudoku)");
mitWindows.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand All @@ -1746,7 +1773,10 @@ private JCheckBoxMenuItem getMitAsterisk() {
if (mitAsterisk == null) {
mitAsterisk = new JCheckBoxMenuItem();
mitAsterisk.setText("Asterisk");
mitAsterisk.setSelected(false);
if (mitAsterisk.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitAsterisk.setSelected(Settings.getInstance().isAsterisk());
mitAsterisk.setToolTipText("Adds 9-cell ASTERISK extra group");
mitAsterisk.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand Down Expand Up @@ -1774,7 +1804,10 @@ private JCheckBoxMenuItem getMitCD() {
if (mitCD == null) {
mitCD = new JCheckBoxMenuItem();
mitCD.setText("Center Dot");
mitCD.setSelected(false);
mitCD.setSelected(Settings.getInstance().isCD());
if (mitCD.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitCD.setToolTipText("Adds 9-cell CENTER DOT extra group");
mitCD.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand Down Expand Up @@ -1802,7 +1835,10 @@ private JCheckBoxMenuItem getMitGirandola() {
if (mitGirandola == null) {
mitGirandola = new JCheckBoxMenuItem();
mitGirandola.setText("Girandola");
mitGirandola.setSelected(false);
mitGirandola.setSelected(Settings.getInstance().isGirandola());
if (mitGirandola.isSelected()) {
Settings.getInstance().toggleVariants();
}
mitGirandola.setToolTipText("Adds 9-cell GIRANDOLA extra group");
mitGirandola.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Expand Down

0 comments on commit 5209cfb

Please sign in to comment.