/*
 *  Draco Econometrics
 *  Copyright (C) 2008-2009 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  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 3 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, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.application.preferences;

import java.io.ByteArrayOutputStream;

import javax.swing.LookAndFeel;
import javax.swing.UIManager;

import com.approximatrix.draco.application.ApplicationManager;


public class UIPreferences implements DracoPreferences {

	public static String TAG = "ui";
	
	private static final int MAX_ICON_SIZE=256;
	
	private int iconSize = 32;	
	
	private String lnf = null;
	
	public UIPreferences() {
		if(ApplicationManager.GetIconLibrary() != null)
			iconSize = ApplicationManager.GetIconLibrary().getIconSize().height;
		
		// This call needs to be done safely...
		try {
			lnf = UIManager.getLookAndFeel().getClass().getName();
		} catch(Exception e) {
			lnf = UIManager.getSystemLookAndFeelClassName();
		}
	}
	
	public int getIconSize() {
		return iconSize;
	}

	public void setIconSize(int iconSize) {
		this.iconSize = Math.min(Math.max(iconSize,1),MAX_ICON_SIZE);
	}
	
	public int getMaxIconSize() {
		return MAX_ICON_SIZE;
	}

	public void apply() {
		ApplicationManager.GetIconLibrary().setIconSize(iconSize);
		
		// The following call is not recommended
		//ApplicationManager.ApplyLookAndFeel(this.lnf);

	}
	
	public String getLookAndFeel() {
		return lnf;
	}
	
	public void setLookAndFeel(String className) {
		lnf = className;
	}
	
}