diff --git a/README.md b/README.md index b185909..ca315fb 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Star SUDOKU +# StarSUDOKU ## TL;DR Java version of the popular Sudoku puzzle game. Intends to provide an advanced user interface. -With Star SUDOKU you can create random sudoku grids or design your own to play/solve. +With StarSUDOKU you can create random sudoku grids or design your own to play/solve. It can be used as sudoku generator, solver. You can export sudoku grids as PDF, RTF, HTML, XML and CSV. ![](screen1.png?raw=true) @@ -13,8 +13,10 @@ It can be used as sudoku generator, solver. You can export sudoku grids as PDF, ### This Readme includes: 1. System requirements -2. How to build Star SUDOKU -3. Running Star SUDOKU on your system +2. How to build StarSUDOKU + * How to build an Windows EXE + * How to extend StarSUDOKU +3. Running StarSUDOKU 4. Features 5. Instructions * Entering numbers in a cell @@ -31,15 +33,15 @@ It can be used as sudoku generator, solver. You can export sudoku grids as PDF, 1. System requirements ---------------------- -Star SUDOKU is written in JAVA programming language, this means that it can be run on any Operating System which has JAVA Runtime Environment (JRE). +StarSUDOKU is written in JAVA programming language, this means that it can be run on any Operating System which has JAVA Runtime Environment (JRE). You need JRE 1.7.0 (also know as JRE 7) or above. You can download JRE for free at www.java.com -2. How to build Star SUDOKU +2. How to build StarSUDOKU --------------------------- -If you want to build Star SUDOKU on your local machine you need to install the Java Development Kit (JDK). You need JDK 1.7.0 or above. +If you want to build StarSUDOKU on your local machine you need to install the Java Development Kit (JDK). You need JDK 1.7.0 or above. -Star SUDOKU uses the Gradle build system, you can build the project locally just by typing the following in the console: +StarSUDOKU uses the Gradle build system, you can build the project locally just by typing the following in the console: ``` ./gradlew build @@ -52,7 +54,19 @@ On Windows use: The generated jar file can be found in the folder _build/libs_ -### How to extend Star SUDOKU +### How to build an Windows EXE +The Gradle build script provides a way to build an Windows executable. You can even do this on a non-Windows machine. For that purpose you need an external application called +[Launch4j](http://launch4j.sourceforge.net/). Download it and install it on your local machine. The version used to test this feature is 3.8, but it will probably work with +other versions too. In addition to this, you need to create an environment variable called `LAUNCH4J_HOME` which points to the folder where you have installed the application. + +After that you can build the exe file by running: +``` +./gradlew launch4j +``` + +The generated exe file can be found in the folder _build/launch4j_ + +### How to extend StarSUDOKU If you want to import the project in an IDE such as Eclipse or IntelliJ IDEA then Gradle provides a way to generate all the necessary project files. Generate Eclipse project: @@ -65,18 +79,18 @@ Generate IntelliJ IDEA project: ./gradlew idea ``` -3. Running Star SUDOKU on your system -------------------------------------- +3. Running StarSUDOKU +--------------------- -To start Star SUDOKU try one of the following options: +To start StarSUDOKU try one of the following options: -* Double click on the jar File to start Star SUDOKU. If this didn't work, then you didn't associate your jar Files with your JRE. +* For Windows users we also provide an exe file, which ist just a wrapper for the jar file. Double click on the exe file to start the application. -* For Windows users we also provide an exe file, which ist just a wrapper for the JAR file. Double click on the exe file to start the application. +* Double click on the jar File to start StarSUDOKU. If this didn't work, then you didn't associate your jar Files with your JRE. * Double click on `StarSUDOKU.bat` for Windows users or on `StarSUDOKU` for Linux users. This will start the application, but only if you have built it with Gradle first. -* Open the console go to your Star SUDOKU folder and type: +* Open the console go to your StarSUDOKU folder and type: ``` java -jar StarSUDOKU-1.0.jar ``` @@ -95,7 +109,7 @@ java -jar StarSUDOKU-1.0.jar \* An user custom level means that you can enter a number between 1 and 81. And next time you generate a new puzzle exactly that many numbers will be shown at the Sudoku grid. So if you enter 81 then the next puzzle will already be solved when you generate it. -\*\* Number distribution in Star SUDOKU means, how are the numbers distributed when you generate a new puzzle. There are 3 numbers distributions: +\*\* Number distribution in StarSUDOKU means, how are the numbers distributed when you generate a new puzzle. There are 3 numbers distributions: * Evenly filled 3x3 Squares - means all 3x3 Squares are evenly filled with numbers, when you start a new puzzle. * Evenly distributed numbers - means that all numbers from 1 to 9 are evenly distributed. So when you generate a new puzzle there will be even number of 1s, 2s, 3s and so on... @@ -133,7 +147,7 @@ Click on the cell with the middle mouse button. ### Design mode -Click on the 'Design New Sudoku' Button to start the Design Mode, by default Star Sudoku starts with Design Mode on. Enter Your numbers in the Grid and hit 'Play the designed Sudoku' button, if the game cannot find any solution to the numbers you've just entered then a dialog window is shown, otherwise You can begin solving the Sudoku puzzle. +Click on the 'Design New Sudoku' Button to start the Design Mode, by default StarSUDOKU starts with Design Mode on. Enter Your numbers in the Grid and hit 'Play the designed Sudoku' button, if the game cannot find any solution to the numbers you've just entered then a dialog window is shown, otherwise You can begin solving the Sudoku puzzle. ### Additional options @@ -156,4 +170,4 @@ If you complete the puzzle successfully you will be informed by a pop up window Jivko Vantchev -And to You for using Star SUDOKU :) +And to You for using StarSUDOKU :) diff --git a/build.gradle b/build.gradle index c84694e..71ba5f2 100644 --- a/build.gradle +++ b/build.gradle @@ -39,12 +39,12 @@ jar { // Windows wrapper configuration to generate windows exe file with Launch4J task launch4jConfig(type: Copy) { - from 'src/main/resources/launch4j.xml' + from 'src/main/resources/launch4j/launch4j.xml' into 'build/launch4j' expand( JAR_FILE: project.jar.archivePath, VERSION: project.version, - ICON: file('src/main/resources/sudoku-icon.ico') + ICON: file('src/main/resources/launch4j/sudoku-icon.ico') ) } @@ -63,4 +63,3 @@ task launch4j(type: Exec, dependsOn: [':jar', ':launch4jConfig']) { commandLine launch4jDir + "/launch4j", launch4jCfg } } - diff --git a/src/main/java/StarSUDOKUMain.java b/src/main/java/StarSUDOKUMain.java index e099e6c..4081120 100644 --- a/src/main/java/StarSUDOKUMain.java +++ b/src/main/java/StarSUDOKUMain.java @@ -1,34 +1,37 @@ /* Main created on 10.07.2006 */ +import com.devng.starsudoku.GV; +import com.devng.starsudoku.gui.SudokuMainFrame; + import javax.swing.JOptionPane; import javax.swing.UIManager; public class StarSUDOKUMain { - public static void main(String[] args) { + public static void main(String[] args) throws Exception { + final String os = System.getProperty("os.name").toLowerCase(); - if(System.getProperty("os.name").toLowerCase().startsWith("windows")) { - try { - UIManager - .setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - com.devng.starsudoku.GV.isWin = true; - } catch (Exception exc) { - com.devng.starsudoku.GV.isWin = false; - exc.printStackTrace(); - } - } + if(os.startsWith("windows")) { + // The system Look and Feel only looks good on Windows + UIManager.setLookAndFeel(GV.LAF.SYSTEM.getLookAndFeelClassName()); + GV.useSystemLAF = true; + } else { + UIManager.setLookAndFeel(GV.LAF.METAL.getLookAndFeelClassName()); + } - String jVer = System.getProperty("java.version"); + final String jVer = System.getProperty("java.version"); if(jVer.compareToIgnoreCase("1.7.0") < 0) { - String errorMsg = "Your Java version is too old!

Star SUDOKU requires JAVA Runtime Environment JRE 1.7.0 / JRE 7 or above.
Please download the latest JRE at www.java.com"; + String errorMsg = "Your Java version is too old!

" + + "Star SUDOKU requires JAVA Runtime Environment JRE 1.7.0 / JRE 7 or above.
" + + "Please download the latest JRE at www.java.com"; JOptionPane.showMessageDialog(null, errorMsg, "Fatal error", JOptionPane.ERROR_MESSAGE); return; } - com.devng.starsudoku.gui.SudokuMainFrame f = - new com.devng.starsudoku.gui.SudokuMainFrame(); + final SudokuMainFrame f = new SudokuMainFrame(); + f.generateNewSudoku(); f.setVisible(true); } } diff --git a/src/main/java/com/devng/starsudoku/GV.java b/src/main/java/com/devng/starsudoku/GV.java index 7d4826f..a9e19ee 100644 --- a/src/main/java/com/devng/starsudoku/GV.java +++ b/src/main/java/com/devng/starsudoku/GV.java @@ -6,11 +6,11 @@ import java.awt.*; /** - * Global Variabls + * Global Variables */ public class GV { - public static final String NAME = "Star SUDOKU "; + public static final String NAME = "StarSUDOKU"; // Keep in sync with the build.gradle public static final String VERSION = "1.0"; @@ -84,19 +84,22 @@ public enum NumDistributuon {evenlyDistributedNumbers, evenlyFilled3x3Square3, r //LOOK AND FEEL public enum LAF { - METAL, SYSTEM - } + NIMBUS("javax.swing.plaf.nimbus.NimbusLookAndFeel"), - ; + METAL("javax.swing.plaf.metal.MetalLookAndFeel"), - public static boolean isWin = false; + SYSTEM(UIManager.getSystemLookAndFeelClassName()); - public final static String METAL = "javax.swing.plaf.metal.MetalLookAndFeel"; + private final String lookAndFeelClassName; - public final static String SYSTEM = UIManager.getSystemLookAndFeelClassName(); + LAF(String lookAndFeelClassName) { + this.lookAndFeelClassName = lookAndFeelClassName; + } - //public final static String MOTIF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; - //public final static String WIN = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; - //public final static String GTK = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; + public String getLookAndFeelClassName() { + return lookAndFeelClassName; + } + } + public static boolean useSystemLAF = false; } diff --git a/src/main/java/com/devng/starsudoku/gui/SudokuGuiGrid.java b/src/main/java/com/devng/starsudoku/gui/SudokuGuiGrid.java index fe920e7..662ef1b 100644 --- a/src/main/java/com/devng/starsudoku/gui/SudokuGuiGrid.java +++ b/src/main/java/com/devng/starsudoku/gui/SudokuGuiGrid.java @@ -31,8 +31,7 @@ public class SudokuGuiGrid extends JPanel implements SudokuObserver { protected boolean isPaintPause; - private class SudokuGuiCell extends JPanel - implements MouseListener, FocusListener { + private class SudokuGuiCell extends JPanel implements MouseListener, FocusListener { private Color bg; private Color bgSelected; @@ -241,7 +240,7 @@ public SudokuGuiGrid(SudokuGrid grid, UndoRedoStack uRS) { this.sgrid = grid; this.dimCell = new Dimension(52, 52); this.uRS = uRS; - this.helpingLines = true; + this.helpingLines = false; setLayout(new GridLayout(9, 9)); cells = new SudokuGuiCell[9][9]; diff --git a/src/main/java/com/devng/starsudoku/gui/SudokuMainFrame.java b/src/main/java/com/devng/starsudoku/gui/SudokuMainFrame.java index e1fa177..d68374b 100644 --- a/src/main/java/com/devng/starsudoku/gui/SudokuMainFrame.java +++ b/src/main/java/com/devng/starsudoku/gui/SudokuMainFrame.java @@ -223,7 +223,7 @@ public String toString() { public SudokuMainFrame() { - super(GV.NAME + GV.VERSION); + super(GV.NAME + " " + GV.VERSION); bHUp = new ButtonHandlerUp(); bHDown = new ButtonHandlerDown(); @@ -456,7 +456,7 @@ private void initMenu() { mOptions.addSeparator(); - opHLines = new JCheckBoxMenuItem("Draw helping lines", true); + opHLines = new JCheckBoxMenuItem("Draw helping lines", false); opHLines.addItemListener(cH); opHLines.setMnemonic('D'); mOptions.add(opHLines); @@ -476,13 +476,13 @@ private void initMenu() { menu.add(mLAF); { ButtonGroup bGr4 = new ButtonGroup(); - lafMetal = new JRadioButtonMenuItem("Java Look And Feel", !GV.isWin); + lafMetal = new JRadioButtonMenuItem("Java Look And Feel", !GV.useSystemLAF); lafMetal.addActionListener(mH); lafMetal.setMnemonic('M'); mLAF.add(lafMetal); bGr4.add(lafMetal); - lafSys = new JRadioButtonMenuItem("System Look And Feel", GV.isWin); + lafSys = new JRadioButtonMenuItem("System Look And Feel", GV.useSystemLAF); lafSys.addActionListener(mH); lafSys.setMnemonic('S'); mLAF.add(lafSys); @@ -659,7 +659,7 @@ public boolean accept(File f) { } public String getDescription() { - return GV.NAME + "Save File (*.ssud)"; + return GV.NAME + " Save File (*.ssud)"; } }); fc.setAcceptAllFileFilterUsed(false); @@ -836,7 +836,7 @@ private void setAboutPanel() { about = new JPanel(); about.setLayout(new BoxLayout(about, BoxLayout.Y_AXIS)); - about.add(new JLabel("" + GV.NAME + GV.VERSION + " Copyright (c) 2006 - 2015 Nikolay G. Georgiev")); + about.add(new JLabel("" + GV.NAME + " " + GV.VERSION + " Copyright (c) 2006 - 2015 Nikolay Georgiev")); about.add(Box.createVerticalStrut(10)); @@ -845,7 +845,7 @@ private void setAboutPanel() { about.add(Box.createVerticalStrut(20)); - about.add(new JLabel("This program is released under the Mozilla Public License 2.0 .
A copy of this is included with your copy of Star SUDOKU
and can also be found at:")); + about.add(new JLabel("This program is released under the Mozilla Public License 2.0 .
A copy of this is included with your copy of StarSUDOKU
and can also be found at:")); about.add(new HTMLLink("https://www.mozilla.org/MPL/2.0/", false)); @@ -855,7 +855,7 @@ private void setAboutPanel() { about.add(new HTMLLink("http://www.lowagie.com/iText/", false)); } - private void generateNewSud() { + public void generateNewSudoku() { if (guiGrid.isPaintPause) { resumePause(); } @@ -1213,15 +1213,7 @@ private void setGridToFinished() { private void setLookAndFeel(GV.LAF laf) { try { - switch (laf) { - case METAL: - UIManager.setLookAndFeel(GV.METAL); - break; - case SYSTEM: - UIManager.setLookAndFeel(GV.SYSTEM); - break; - } - + UIManager.setLookAndFeel(laf.getLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(this); this.pack(); } catch (Exception e) { @@ -1254,7 +1246,7 @@ public void actionPerformed(ActionEvent e) { JButton tmp = (JButton) e.getSource(); if (tmp == bUp[0]) { - generateNewSud(); + generateNewSudoku(); } else if (tmp == bUp[1]) { doNewDesign(); } else if (tmp == bUp[2]) { @@ -1334,7 +1326,7 @@ public void actionPerformed(ActionEvent e) { JMenuItem tmp = (JMenuItem) e.getSource(); if (tmp == sudNew) { - generateNewSud(); + generateNewSudoku(); } else if (tmp == sudOpen) { doLoad(); } else if (tmp == sudSaveAs) { @@ -1361,8 +1353,6 @@ public void actionPerformed(ActionEvent e) { setLookAndFeel(GV.LAF.METAL); } else if (tmp == lafSys) { setLookAndFeel(GV.LAF.SYSTEM); - } else if (tmp == lafSys) { - setLookAndFeel(GV.LAF.SYSTEM); } else if (tmp == helpAbout) { doAbout(); } else if (tmp == sudExit) { diff --git a/src/main/java/com/devng/starsudoku/io/Export.java b/src/main/java/com/devng/starsudoku/io/Export.java index 116052a..6455290 100644 --- a/src/main/java/com/devng/starsudoku/io/Export.java +++ b/src/main/java/com/devng/starsudoku/io/Export.java @@ -14,7 +14,7 @@ public static String getHTMLString(SerGrid sg) { StringBuilder sb = new StringBuilder(3000); sb.append("\n"); sb.append("\n"); - sb.append("\tStar SUDOKU\n"); + sb.append("\t" + GV.NAME + "\n"); sb.append("\t