package j3deditor.bin.util.preferences;


import j3deditor.bin.util.UserData;
import j3deditor.bin.util.Utilities;

import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;


/**
 * View tab.
 *
 * @author Risto Seene
 */
public class ViewTab extends JPanel{

	/**
	 * check box that specifies if the main window
	 * is opened in the full screen mode or not.
	 */
	private JCheckBox fullscreen;

	/**
	 * check box that specifies if the internal frames
	 * are opened in the maximized mode or not.
	 */
	private JCheckBox maximized;

	/** if checked internal frames are dragged in OUTLINE DRAG mode. */
	private JRadioButton outline;

	/** if checked internal frames are dragged in LIVE DRAG mode. */
	private JRadioButton live;
	
	/** if checked stack traces of exceptions will be shown. */
	private JCheckBox stacktrace;


	/**
	 * Creates an instance of <code>ViewTab</code> and
	 * initializes its components.
	 */
	public ViewTab(){
		setLayout(null);
		setName(Utilities.translator.translate(getClass(), "title"));
		initContent();
	}


	/**
	 * Initializes the content of this panel.
	 */
	private void initContent(){
		JLabel window = new JLabel(Utilities.translator.translate(getClass(), "window"));
		window.setBounds(20, 10, (int)(window.getPreferredSize().getWidth()), (int)(window.getPreferredSize().getHeight()));
		add(window);

		fullscreen = new JCheckBox(Utilities.translator.translate(getClass(), "screenmode"));
		fullscreen.setSelected(Utilities.userdata.getBooleanData("fullscreen"));
		fullscreen.setBounds(10, 30, (int)(fullscreen.getPreferredSize().getWidth()), (int)(fullscreen.getPreferredSize().getHeight()));
		add(fullscreen);

		JSeparator s1 = new JSeparator();
		s1.setBounds(20, 60, 200, (int)(s1.getPreferredSize().getHeight()));
		add(s1);

		JLabel iframe = new JLabel(Utilities.translator.translate(getClass(), "iframe"));
		iframe.setBounds(20, 80, (int)(iframe.getPreferredSize().getWidth()), (int)(iframe.getPreferredSize().getHeight()));
		add(iframe);

		maximized = new JCheckBox(Utilities.translator.translate(getClass(), "max"));
		maximized.setSelected(Utilities.userdata.getBooleanData("internalframe_maximized"));
		maximized.setBounds(10, 100, (int)(maximized.getPreferredSize().getWidth()), (int)(maximized.getPreferredSize().getHeight()));
		add(maximized);

		outline = new JRadioButton(Utilities.translator.translate(getClass(), "odrag"));
		live = new JRadioButton(Utilities.translator.translate(getClass(), "ldrag"));
		if(Utilities.userdata.getIntData("desktoppane_dragmode") == 1){
			outline.setSelected(true);
		} else {
			live.setSelected(true);
		}
		
		outline.setBounds(10, 125, (int)(outline.getPreferredSize().getWidth()), (int)(outline.getPreferredSize().getHeight()));
		add(outline);
		live.setBounds(10, 145, (int)(live.getPreferredSize().getWidth()), (int)(live.getPreferredSize().getHeight()));
		add(live);

		ButtonGroup bGroup = new ButtonGroup();
		bGroup.add(outline);
		bGroup.add(live);

		JSeparator s2 = new JSeparator();
		s2.setBounds(20, 175, 200, (int)(s2.getPreferredSize().getHeight()));
		add(s2);
		
		JLabel error = new JLabel(Utilities.translator.translate(this.getClass(), "error"));
		error.setBounds(20, 195, (int)(error.getPreferredSize().getWidth()), (int)(error.getPreferredSize().getHeight()));
		add(error);
		
		stacktrace = new JCheckBox(Utilities.translator.translate(this.getClass(), "stacktrace"));
		stacktrace.setSelected(Utilities.userdata.getBooleanData("stacktrace"));
		stacktrace.setBounds(10, 215, (int)(stacktrace.getPreferredSize().getWidth()), (int)(stacktrace.getPreferredSize().getHeight()));
		add(stacktrace);
	}


	/**
	 * Passes the values shown on this tab to the central
	 * <code>UserData</code> object.
	 */
	public void saveChanges(){
		UserData userdata = Utilities.userdata;
		userdata.setData("fullscreen", fullscreen.isSelected());
		userdata.setData("internalframe_maximized", maximized.isSelected());
		if(outline.isSelected()){
			userdata.setData("desktoppane_dragmode", 1);
		} else {
			userdata.setData("desktoppane_dragmode", 0);
		}
	}

}
