package org.cmdline.sudoku;

import java.io.*;
import javax.swing.*;

public class PuzzleSaver implements Runnable {
	String puzzle = null;
	
	public PuzzleSaver(String puzzle) {
		this.puzzle = puzzle;
	}
	
	public void run() {
		JFrame frame = new JFrame("Puzzle save");
		JFileChooser chooser = new JFilePainter();
		chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
		int rc = chooser.showSaveDialog(frame);
		if (rc != JFileChooser.APPROVE_OPTION) return;
		String savepath = chooser.getSelectedFile().getPath();	
		if (!savepath.endsWith(".sdko")) savepath += ".sdko";	
		try {
			BufferedWriter os = new BufferedWriter(new FileWriter(savepath));
			os.write(puzzle,0,puzzle.length());
			os.close();
		}
		catch(IOException ioe){
			ioe.printStackTrace();
		}
	}
	
}