bug fix relating to file picker.
This commit is contained in:
+21
-13
@@ -1,8 +1,10 @@
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
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.Dimension;
|
||||
@@ -16,7 +18,7 @@ public class App extends JFrame {
|
||||
private Nav nav;
|
||||
|
||||
// Data fields
|
||||
private Settings settings;
|
||||
private Settings s;
|
||||
private SudokuChecker checker;
|
||||
|
||||
/**
|
||||
@@ -24,8 +26,8 @@ public class App extends JFrame {
|
||||
*/
|
||||
public App() {
|
||||
super("Sudoku");
|
||||
settings = new Settings();
|
||||
nav = new Nav(settings, false);
|
||||
s = new Settings();
|
||||
nav = new Nav(s, false);
|
||||
initSetup();
|
||||
add(createApp());
|
||||
}
|
||||
@@ -38,31 +40,37 @@ public class App extends JFrame {
|
||||
// values from Settings.
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setLayout(new BorderLayout());
|
||||
setPreferredSize(new Dimension(750, 550));
|
||||
setPreferredSize(s.getDimension());
|
||||
setSize(getPreferredSize());
|
||||
setResizable(false);
|
||||
setResizable(s.getResizable());
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Set the look and feel for the app to be cross-platform.
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getCrossPlatformLookAndFeelClassName()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
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() {
|
||||
// TODO: Create the root JPanel holding all other GUI components.
|
||||
JPanel root = new JPanel();
|
||||
private Root createApp() {
|
||||
Root root = new Root(s);
|
||||
root.add(nav);
|
||||
|
||||
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.
|
||||
* 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 gui.backend.Settings;
|
||||
|
||||
/**
|
||||
* A custom JComboBox with the appropriate styling for the Sudoku app.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,9 @@ package gui;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import gui.backend.Settings;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package gui;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import gui.backend.Settings;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
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.
|
||||
*
|
||||
@@ -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.IOException;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
|
||||
@@ -37,6 +38,12 @@ public class Settings {
|
||||
// The font to be used throughout the application.
|
||||
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
|
||||
* or reading in the settings from settings file if it exists.
|
||||
@@ -137,6 +144,50 @@ public class Settings {
|
||||
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.
|
||||
*
|
||||
@@ -151,7 +202,13 @@ public class Settings {
|
||||
* settings file.
|
||||
*/
|
||||
private void defaultSettings() {
|
||||
// Setup the default directory for .sdku puzzle files.
|
||||
defaultDirectory = appDirectory + "puzzles";
|
||||
File dir = new File(defaultDirectory);
|
||||
|
||||
if(!dir.exists() || !dir.isDirectory())
|
||||
dir.mkdirs();
|
||||
|
||||
newFileProperties = 0;
|
||||
|
||||
// Load the font from the system directory.
|
||||
@@ -162,6 +219,8 @@ public class Settings {
|
||||
else
|
||||
font = new Font("Arial", Font.PLAIN, 12);
|
||||
|
||||
dimension = new Dimension(750, 550);
|
||||
resizable = false;
|
||||
updateSettingsFile();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package gui.backend;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import gui.Cell;
|
||||
|
||||
/**
|
||||
* The SudokuChecker class is responsible for calculating the solution to
|
||||
* a given Sudoku puzzle.
|
||||
@@ -6,6 +6,7 @@ function Run {
|
||||
java App $flag
|
||||
rm *.class
|
||||
rm gui/*.class
|
||||
rm gui/backend/*.class
|
||||
}
|
||||
|
||||
if ($args.Length -eq 1) {
|
||||
|
||||
@@ -2,6 +2,8 @@ run() {
|
||||
javac *.java
|
||||
java App $1
|
||||
rm *.class
|
||||
rm gui/*.class
|
||||
rm gui/backend/*.class
|
||||
}
|
||||
|
||||
if($# -eq 1) then
|
||||
|
||||
Reference in New Issue
Block a user