uk.co.keang.sudoku
Class Generator

java.lang.Object
  extended by uk.co.keang.sudoku.Generator

public class Generator
extends java.lang.Object

Generates a sudoku grid

Author:
A.G.Docherty

Nested Class Summary
static class Generator.PuzzleStoreItem
           
 
Field Summary
static int MAX_QUEUE_SIZE
           
 
Constructor Summary
Generator()
           
 
Method Summary
 void addStoreListener(StoreListener l)
          Adds a listener.
 void cancelGenerate()
          Cancels any ongoing generation
(package private)  Puzzle generatePuzzle(Puzzle.PuzzleDifficulty difficulty, java.beans.PropertyChangeListener listener)
          Generates a puzzle with this difficulty level
 void load()
          Loads the puzzles in this store
 void removeAllStoreListeners()
          Removes the listener
 void removeStoreListener(StoreListener l)
          Removes the listener
 void save()
          Saves the puzzles in this store
 void startBackgroundGeneration()
          Starts the background generator thread.
 void stopBackgroundGeneration()
          Stops the background generator thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_QUEUE_SIZE

public static final int MAX_QUEUE_SIZE
See Also:
Constant Field Values
Constructor Detail

Generator

Generator()
Method Detail

startBackgroundGeneration

public void startBackgroundGeneration()
Starts the background generator thread. As puzzles are generated they are placed into a store for quick retrieval.


stopBackgroundGeneration

public void stopBackgroundGeneration()
Stops the background generator thread. The store is not emptied of previously generated puzzles.


generatePuzzle

Puzzle generatePuzzle(Puzzle.PuzzleDifficulty difficulty,
                      java.beans.PropertyChangeListener listener)
Generates a puzzle with this difficulty level

Parameters:
difficulty - the difficulty level of the puzzle to generate
listener - a listener of progress events. For each new attempt an event is sent.
Returns:
the puzzle or null if cancelled

cancelGenerate

public void cancelGenerate()
Cancels any ongoing generation


addStoreListener

public void addStoreListener(StoreListener l)
Adds a listener.

Parameters:
l - - the listener to add

removeStoreListener

public void removeStoreListener(StoreListener l)
Removes the listener

Parameters:
l - - the listener to remove

removeAllStoreListeners

public void removeAllStoreListeners()
Removes the listener


save

public void save()
          throws java.io.FileNotFoundException
Saves the puzzles in this store

Throws:
java.io.FileNotFoundException

load

public void load()
          throws java.io.IOException,
                 IllegalGridException
Loads the puzzles in this store

Throws:
IllegalGridException
java.io.IOException