/*
Tiamat - a role-playing game framework
Theme.java - stores style elements for a top-level container
 
 Copyright  (C) 2004-2005 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.tiamat.graphics;

import com.huguesjohnson.ImageLoader;
import com.huguesjohnson.PathResolver;
import com.huguesjohnson.serialization.Formatter;
import com.huguesjohnson.serialization.Storable;
import java.awt.image.BufferedImage;
import java.io.File;

/** Theme - stores style elements for a top-level container
 * @author Hugues Johnson
 */
public class Theme implements Storable{
//begin public properties
    //the color scheme for this theme
    private ColorScheme colorScheme;
    /** Returns the ColorScheme for this Theme.
     * @return The ColorScheme for this Theme.
     */
    public ColorScheme getColorScheme(){ return(this.colorScheme); }
    /** Sets the ColorScheme for this Theme.
     * @param colorScheme The new ColorScheme for this Theme.
     */
    public void setColorScheme(ColorScheme colorScheme){ this.colorScheme=colorScheme; }
    
    //image to display on a radio button when it's not selected
    private transient BufferedImage radioButtonImage;
    /** Returns the image to display on a radio button.
     * @return The image to display on a radio button.
     */
    public BufferedImage getRadioButtonImage(){ return(this.radioButtonImage); }
    
    //path to the file containing the image
    private String radioButtonImagePath; 
    /** Sets the image to display on a radio button.
     * @param radioButtonImagePath The path to the new image to display on a radio button.
     */
    public void setRadioButtonImagePath(String radioButtonImagePath){
        this.radioButtonImagePath=radioButtonImagePath;
        this.radioButtonImage=ImageLoader.loadBufferedImage(this.getRadioButtonImagePathAbsolute());
    }
    /** Returns the relative path to the image to display on a radio button.
     * @return The relative path to the image to display on a radio button.
     */
    public String getRadioButtonImagePath(){ return(this.radioButtonImagePath); }
    /** Returns the absolute path to the image to display on a radio button.
     * @return The absolute path to the image to display on a radio button.
     */
    public String getRadioButtonImagePathAbsolute(){ return(PathResolver.getAbsolutePath(this.absoluteDir,this.radioButtonImagePath)); }
    
    //image to display on a radio button when it's selected
    private transient BufferedImage radioButtonSelectedImage;
    /** Returns the image to display on a selected radio button.
     * @return The image to display on a selected radio button.
     */
    public BufferedImage getRadioButtonSelectedImage(){ return(this.radioButtonSelectedImage); }
    
    //path to the file containing the image
    private String radioButtonSelectedImagePath; 
    /** Sets the image to display on a selected radio button.
     * @param radioButtonSelectedImagePath The path to the new image to display on a selected radio button.
     */
    public void setRadioButtonSelectedImagePath(String radioButtonSelectedImagePath){
        this.radioButtonSelectedImagePath=radioButtonSelectedImagePath;
        this.radioButtonSelectedImage=ImageLoader.loadBufferedImage(this.getRadioButtonSelectedImagePathAbsolute());
    }
    /** Returns the relative path to the image to display on a selected radio button.
     * @return The relative path to the image to display on a selected radio button.
     */
    public String getRadioButtonSelectedImagePath(){ return(this.radioButtonSelectedImagePath); }
    /** Returns the absolute path to the image to display on a selected radio button.
     * @return The absolute path to the image to display on a selected radio button.
     */
    public String getRadioButtonSelectedImagePathAbsolute(){ return(PathResolver.getAbsolutePath(this.absoluteDir,this.radioButtonSelectedImagePath)); }
    
    //absolute path to the directory where images are stored
    private transient String absoluteDir;
    /** Set the absolute path to the directory where images are stored.
     * @param absoluteDir New path to the directory where images are stored.
     */
    public void setAbsoluteDir(String absoluteDir){
        if(absoluteDir.endsWith(File.separator)){
            this.absoluteDir=absoluteDir;
        } else{
            this.absoluteDir=absoluteDir+File.separator;
        }
    }
//end public properties

//begin constructors
    /** Default constructor, creates an empty theme
     */
    public Theme(){
        this.colorScheme=new ColorScheme();
    }
//end constructors
 
/* begin public methods */    
    /** The onDeserialize event should be fired after an object is de-serialized.
     * This allows objects to load transient members, set their working directory, and load Storable members if needed.
     * @param formatter the formatter to use to load any storable members
     * @param absoluteDir the working directory since all paths stored in the object should be relative
     */
    public void onDeserialize(Formatter formatter,String absoluteDir){
        this.setAbsoluteDir(absoluteDir);
        this.radioButtonImage=ImageLoader.loadBufferedImage(this.getRadioButtonImagePathAbsolute());
        this.radioButtonSelectedImage=ImageLoader.loadBufferedImage(this.getRadioButtonSelectedImagePathAbsolute());
    }
/* end public methods */    
}