bug fix relating to file picker.
This commit is contained in:
+21
-13
@@ -1,8 +1,10 @@
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import gui.Settings;
|
import gui.Nav;
|
||||||
|
import gui.Root;
|
||||||
|
import gui.backend.Settings;
|
||||||
|
import gui.backend.SudokuChecker;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
@@ -16,7 +18,7 @@ public class App extends JFrame {
|
|||||||
private Nav nav;
|
private Nav nav;
|
||||||
|
|
||||||
// Data fields
|
// Data fields
|
||||||
private Settings settings;
|
private Settings s;
|
||||||
private SudokuChecker checker;
|
private SudokuChecker checker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,8 +26,8 @@ public class App extends JFrame {
|
|||||||
*/
|
*/
|
||||||
public App() {
|
public App() {
|
||||||
super("Sudoku");
|
super("Sudoku");
|
||||||
settings = new Settings();
|
s = new Settings();
|
||||||
nav = new Nav(settings, false);
|
nav = new Nav(s, false);
|
||||||
initSetup();
|
initSetup();
|
||||||
add(createApp());
|
add(createApp());
|
||||||
}
|
}
|
||||||
@@ -38,31 +40,37 @@ public class App extends JFrame {
|
|||||||
// values from Settings.
|
// values from Settings.
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setPreferredSize(new Dimension(750, 550));
|
setPreferredSize(s.getDimension());
|
||||||
setSize(getPreferredSize());
|
setSize(getPreferredSize());
|
||||||
setResizable(false);
|
setResizable(s.getResizable());
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
// Set the look and feel for the app to be cross-platform.
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(
|
UIManager.setLookAndFeel(
|
||||||
UIManager.getCrossPlatformLookAndFeelClassName()
|
UIManager.getCrossPlatformLookAndFeelClassName()
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Error with cross platform look/feel in frameSetup()."
|
"Error with cross platform look/feel in initSetup()."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the root JPanel holding all other GUI components.
|
* Create the Root JPanel for the Sudoku App. This will contain all other
|
||||||
|
* GUI components.
|
||||||
*
|
*
|
||||||
* @return JPanel
|
* Settings must be passed since, in the future, the user may be able to
|
||||||
|
* customize the layout of the app.
|
||||||
|
*
|
||||||
|
* @param settings
|
||||||
|
* @return Root
|
||||||
*/
|
*/
|
||||||
private JPanel createApp() {
|
private Root createApp() {
|
||||||
// TODO: Create the root JPanel holding all other GUI components.
|
Root root = new Root(s);
|
||||||
JPanel root = new JPanel();
|
|
||||||
root.add(nav);
|
root.add(nav);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import gui.backend.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Board class represents the Sudoku board in the GUI.
|
||||||
|
*
|
||||||
|
* It contains all other related GUI components, and is the main JPanel for
|
||||||
|
* the board. Accessible information from the Board includes:
|
||||||
|
* - the current state of the board, including filled values and notes;
|
||||||
|
* - the current difficulty;
|
||||||
|
* - the current time since the puzzle was started;
|
||||||
|
* - the current hints available; and
|
||||||
|
* - the current number of mistakes.
|
||||||
|
*/
|
||||||
|
public class Board extends JPanel {
|
||||||
|
private Settings s;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Board object with the default styling from settings.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
*/
|
||||||
|
public Board(Settings s) {
|
||||||
|
super();
|
||||||
|
this.s = s;
|
||||||
|
style();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the Board Panel with the appropriate styling.
|
||||||
|
*/
|
||||||
|
private void style() {
|
||||||
|
// TODO: Style the Board Panel.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package gui;
|
||||||
/**
|
/**
|
||||||
* A Cell represents a single cell in the Sudoku grid.
|
* A Cell represents a single cell in the Sudoku grid.
|
||||||
* This helper class is used to store the row, column, value, and possible values for a cell.
|
* This helper class is used to store the row, column, value, and possible values for a cell.
|
||||||
@@ -2,6 +2,8 @@ package gui;
|
|||||||
|
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
|
|
||||||
|
import gui.backend.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom JComboBox with the appropriate styling for the Sudoku app.
|
* A custom JComboBox with the appropriate styling for the Sudoku app.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package gui;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import gui.backend.Settings;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
package gui;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import gui.backend.Settings;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
|
||||||
import gui.ComboBox;
|
|
||||||
import gui.FileChooser;
|
|
||||||
import gui.Settings;
|
|
||||||
/**
|
/**
|
||||||
* The Nav class represents the Navigation bar at the top of the JFrame window.
|
* The Nav class represents the Navigation bar at the top of the JFrame window.
|
||||||
*
|
*
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import gui.backend.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Root class represents the root JPanel for the Sudoku app.
|
||||||
|
*
|
||||||
|
* It contains all other GUI components, and is the main JPanel for the app.
|
||||||
|
* To create a new Root object, a Settings object must be passed in for
|
||||||
|
* styling purposes.
|
||||||
|
*/
|
||||||
|
public class Root extends JPanel {
|
||||||
|
private Settings s;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Root object with the default styling from settings.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
*/
|
||||||
|
public Root(Settings s) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.s = s;
|
||||||
|
style();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the Root Panel with the appropriate styling.
|
||||||
|
*/
|
||||||
|
private void style() {
|
||||||
|
// TODO: Style the Root Panel.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package gui;
|
package gui.backend;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.FontFormatException;
|
import java.awt.FontFormatException;
|
||||||
|
|
||||||
@@ -37,6 +38,12 @@ public class Settings {
|
|||||||
// The font to be used throughout the application.
|
// The font to be used throughout the application.
|
||||||
private Font font;
|
private Font font;
|
||||||
|
|
||||||
|
// The default dimension of the application window.
|
||||||
|
private Dimension dimension;
|
||||||
|
|
||||||
|
// Resizable setting
|
||||||
|
private boolean resizable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Settings object, initializing the default settings
|
* Create a new Settings object, initializing the default settings
|
||||||
* or reading in the settings from settings file if it exists.
|
* or reading in the settings from settings file if it exists.
|
||||||
@@ -137,6 +144,50 @@ public class Settings {
|
|||||||
updateSettingsFile();
|
updateSettingsFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default dimension of the application window.
|
||||||
|
*
|
||||||
|
* The user can specify both the starting width and height of the app,
|
||||||
|
* and the app will remember the last used dimensions as well.
|
||||||
|
*
|
||||||
|
* @return Dimension
|
||||||
|
*/
|
||||||
|
public Dimension getDimension() {
|
||||||
|
return dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default dimension and write it to the settings file.
|
||||||
|
*
|
||||||
|
* @param dimension
|
||||||
|
*/
|
||||||
|
public void setDimension(Dimension dimension) {
|
||||||
|
this.dimension = dimension;
|
||||||
|
updateSettingsFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resizable setting for the application window.
|
||||||
|
*
|
||||||
|
* By default, the application window is not resizable and is considered
|
||||||
|
* an experimental feature. Dynamic layout is not yet supported.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean getResizable() {
|
||||||
|
return resizable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the resizable setting and write it to the settings file.
|
||||||
|
*
|
||||||
|
* @param resizable
|
||||||
|
*/
|
||||||
|
public void setResizable(boolean resizable) {
|
||||||
|
this.resizable = resizable;
|
||||||
|
updateSettingsFile();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open and write the settings to the settings file.
|
* Open and write the settings to the settings file.
|
||||||
*
|
*
|
||||||
@@ -151,7 +202,13 @@ public class Settings {
|
|||||||
* settings file.
|
* settings file.
|
||||||
*/
|
*/
|
||||||
private void defaultSettings() {
|
private void defaultSettings() {
|
||||||
|
// Setup the default directory for .sdku puzzle files.
|
||||||
defaultDirectory = appDirectory + "puzzles";
|
defaultDirectory = appDirectory + "puzzles";
|
||||||
|
File dir = new File(defaultDirectory);
|
||||||
|
|
||||||
|
if(!dir.exists() || !dir.isDirectory())
|
||||||
|
dir.mkdirs();
|
||||||
|
|
||||||
newFileProperties = 0;
|
newFileProperties = 0;
|
||||||
|
|
||||||
// Load the font from the system directory.
|
// Load the font from the system directory.
|
||||||
@@ -162,6 +219,8 @@ public class Settings {
|
|||||||
else
|
else
|
||||||
font = new Font("Arial", Font.PLAIN, 12);
|
font = new Font("Arial", Font.PLAIN, 12);
|
||||||
|
|
||||||
|
dimension = new Dimension(750, 550);
|
||||||
|
resizable = false;
|
||||||
updateSettingsFile();
|
updateSettingsFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
|
package gui.backend;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import gui.Cell;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SudokuChecker class is responsible for calculating the solution to
|
* The SudokuChecker class is responsible for calculating the solution to
|
||||||
* a given Sudoku puzzle.
|
* a given Sudoku puzzle.
|
||||||
@@ -6,6 +6,7 @@ function Run {
|
|||||||
java App $flag
|
java App $flag
|
||||||
rm *.class
|
rm *.class
|
||||||
rm gui/*.class
|
rm gui/*.class
|
||||||
|
rm gui/backend/*.class
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($args.Length -eq 1) {
|
if ($args.Length -eq 1) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ run() {
|
|||||||
javac *.java
|
javac *.java
|
||||||
java App $1
|
java App $1
|
||||||
rm *.class
|
rm *.class
|
||||||
|
rm gui/*.class
|
||||||
|
rm gui/backend/*.class
|
||||||
}
|
}
|
||||||
|
|
||||||
if($# -eq 1) then
|
if($# -eq 1) then
|
||||||
|
|||||||
Reference in New Issue
Block a user