/* @(#)ConcentrationSettings.java   13 November 2006 */

/* Useful imports */

import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;


public class ConcentrationSettings
    extends DisplayPanel
    implements WindowConstants
{
    {
        LookAndFeelTools.setNetFontSizeAdjustment(4);
    }
    
    
    /** Table panel gap. */
    private static final int gap = 20;
    
    
    /** The index that selects shapes. */
    public static final int SHAPES  = 0;
    
    /** The index that selects photos. */
    public static final int PHOTOS  = 1;
    
    /** The index that selects letters. */
    public static final int LETTERS = 2;
    
    /** The index that selects numbers. */
    public static final int NUMBERS = 3;
    
    
    /** The radio panel for selecting tile contents. */
    private RadioPanel selectTile =
        new RadioPanel(
            new String[] {
                "Use shapes for tiles",
                "Use photos for tiles",
                "Use letters from A to Z for tiles",
                "Use numbers from 0 to 99 for tiles" },
            0 );
    
    
    /** The index that selects a 3 by 3 grid size. */
    public static final int GRID_3 = 0;
    
    /** The index that selects a 3 by 3 grid size. */
    public static final int GRID_4 = 1;
    
    /** The index that selects a 3 by 3 grid size. */
    public static final int GRID_5 = 2;
    
    /** The index that selects a 3 by 3 grid size. */
    public static final int GRID_6 = 3;
    
    
    /** The radio panel for selecting the tile grid size. */
    private RadioPanel selectGrid =
        new RadioPanel(
            new String[] {
                "Use 3 by 3 grid",
                "Use 4 by 4 grid",
                "Use 5 by 5 grid",
                "Use 6 by 6 grid" },
            3 );
    
    
    private SimpleAction newGame =
        new SimpleAction("Make New Concentration Game") {
            public void perform() { newGame(); }
    };
    
    
    private Object[] mainStuff =
        { selectTile, selectGrid, newGame };
    
    private VTable mainTable =
        new VTable(mainStuff, gap, gap, CENTER);
    
    
    private Paintable[][] paintables = new Paintable[4][];
    
    {
        paintables[SHAPES] = GameShapes.makeShapePaintables();
        
        paintables[PHOTOS] = GameImages.getImagePaintables();
        
        paintables[LETTERS] = GameText.makeLetterPaintables();
        
        paintables[NUMBERS] = GameText.makeNumberPaintables();
    }
    
    /** The length of the PHOTOS paintables. */
    private int photosCount = paintables[PHOTOS].length;
    
    /** The tile type. */
    private int tileType = SHAPES;
    
    /** The grid type. */
    private int gridType = GRID_6;
    
    /** The grid size. */
    private int gridSize = 6;
    
    
    public ConcentrationSettings() {
        selectTile.setBorder(Borders.title("Select Tile Type"));
        
        selectGrid.setBorder(Borders.title("Select Grid Size"));
        
        mainTable.emptyBorder(gap);
        mainTable.titleBorder("Concentration Settings");
        
        add(mainTable);
    }
    
    
    private void newGame() {
        setParameters();
        
        ConcentrationGame game =
            new ConcentrationGame
                (paintables[tileType], gridSize);
        
        JPTFrame frame = game.frame("Concentration Game");
        
        frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    
    /**
     * Use the GUI to set the tile type and grid size
     * for tile and grid construction.
     */
    private void setParameters() {
        tileType = selectTile.getSelectedIndex();
        
        if ((tileType == PHOTOS) && (photosCount == 0)) {
            String message = "Photos failed to load\n"
                + "Will use shapes instead";
            
            GeneralDialog.showOKDialog(message, "Warning");
            
            tileType = SHAPES;
        }
        
        gridType = selectGrid.getSelectedIndex();
        gridSize = gridType + 3;
    }
    
    
    public static void main(String[] args) {
        ConcentrationSettings settings =
            new ConcentrationSettings();
        
        JPTFrame frame = settings.frame("Settings", WEST);
        
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
}

