package com.approximatrix.draco.general.ui.preferences;

import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.approximatrix.draco.application.preferences.UIPreferences;

public class UIPreferencesPanel extends JPanel implements PreferencesPanel,ChangeListener {

	public static final String TAB_TITLE = "User Interface";
	
	private static final String HELP_KEY = "uipreferences";
	
	private UIPreferences prefs = null;
	private JSpinner iconSize = null; 
	
	public UIPreferencesPanel(UIPreferences prefs) {
		this.prefs = prefs;
		initialize();
	}
	
	private void initialize() {
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout());
		panel.add(new JLabel("Toolbar Icon Size: "));
		panel.add(getIconSpinner());
		this.add(panel);
	}
	
	private JSpinner getIconSpinner() {
		if(iconSize == null) {
			iconSize = new JSpinner(new SpinnerNumberModel(prefs.getIconSize(),1,prefs.getMaxIconSize(),1));
			iconSize.addChangeListener(this);
		}
		return iconSize;
	}

	public void stateChanged(ChangeEvent e) {
		if(e.getSource() == getIconSpinner())
			prefs.setIconSize(((SpinnerNumberModel)getIconSpinner().getModel()).getNumber().intValue());
		
	}

	public String getHelpKey() {
		return HELP_KEY;
	}
}
