package com.delormeloic.generator.view.slidesforms;

import com.delormeloic.generator.model.slides.SlideWithTitle;
import com.delormeloic.generator.view.converters.FontStringConverter;
import com.delormeloic.generator.view.helpers.FontsHelper;
import com.delormeloic.generator.view.helpers.GridPaneHelper;
import com.delormeloic.generator.view.helpers.SpinnerHelper;
import com.delormeloic.generator.view.helpers.TextHelper;

import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.control.TextField;
import javafx.scene.text.Font;

/**
 * This class represents a slide with a title form.
 * 
 * @author DELORME Loïc
 * @since 1.0.0
 */
public class SlideWithTitleForm extends SlideForm
{
	/**
	 * Create a slide with a title form.
	 * 
	 * @param slideWithTitle
	 *            The slide with a title.
	 */
	public SlideWithTitleForm(SlideWithTitle slideWithTitle)
	{
		super(slideWithTitle);
	}

	/**
	 * @see com.delormeloic.generator.view.slidesforms.IFormable#toForm()
	 */
	@Override
	public Node toForm()
	{
		final SlideWithTitle slideWithTitle = (SlideWithTitle) this.slide;

		final TextField nameTextField = new TextField();
		final CheckBox headerCheckBox = new CheckBox();
		final CheckBox footerCheckBox = new CheckBox();
		final TextField titleTextField = new TextField();
		final ComboBox<Font> titleFontComboBox = new ComboBox<Font>();
		final Spinner<Integer> titleSizeSpinner = new Spinner<Integer>();

		titleFontComboBox.getItems().addAll(FontsHelper.getAllAvailableFonts());
		titleFontComboBox.setConverter(new FontStringConverter());
		titleSizeSpinner.setValueFactory(SpinnerHelper.getDefaultTextSizeSpinnerValueFactory());

		nameTextField.textProperty().bindBidirectional(slideWithTitle.getNameProperty());
		headerCheckBox.selectedProperty().bindBidirectional(slideWithTitle.getHeaderProperty());
		footerCheckBox.selectedProperty().bindBidirectional(slideWithTitle.getFooterProperty());
		titleTextField.textProperty().bindBidirectional(slideWithTitle.getTitleProperty());
		titleFontComboBox.valueProperty().bindBidirectional(slideWithTitle.getTitleFontProperty());
		titleSizeSpinner.getValueFactory().valueProperty().bindBidirectional(slideWithTitle.getTitleSizeProperty().asObject());

		final Node[] nameField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormNameField")), nameTextField };
		final Node[] headerField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormHeaderField")), headerCheckBox };
		final Node[] footerField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormFooterField")), footerCheckBox };
		final Node[] titleField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormTitleField")), titleTextField };
		final Node[] titleFontField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormTitleFontField")), titleFontComboBox };
		final Node[] titleSizeField = new Node[] { new Label(TextHelper.getText("slideWithTitleFormTitleSizeField")), titleSizeSpinner };

		return GridPaneHelper.buildGridPane(new Node[][] { nameField, GridPaneHelper.getSeparators(2), headerField, footerField, GridPaneHelper.getSeparators(2), titleField, titleFontField, titleSizeField });
	}
}
@@ -303,69 +303,8 @@
 er;%0A
-import com.delormeloic.generator.view.helpers.SpinnerHelper;%0A
 impo
@@ -499,45 +499,8 @@
 el;%0A
-import javafx.scene.control.Spinner;%0A
 impo
@@ -1388,76 +1388,8 @@
 %3E();
-%0A%09%09final Spinner%3CInteger%3E titleSizeSpinner = new Spinner%3CInteger%3E();
 %0A%0A%09%09
@@ -1525,99 +1525,8 @@
 ());
-%0A%09%09titleSizeSpinner.setValueFactory(SpinnerHelper.getDefaultTextSizeSpinnerValueFactory());
 %0A%0A%09%09
@@ -1972,130 +1972,8 @@
 ());
-%0A%09%09titleSizeSpinner.getValueFactory().valueProperty().bindBidirectional(slideWithTitle.getTitleSizeProperty().asObject());
 %0A%0A%09%09
@@ -2595,140 +2595,8 @@
 x %7D;
-%0A%09%09final Node%5B%5D titleSizeField = new Node%5B%5D %7B new Label(TextHelper.getText(%22slideWithTitleFormTitleSizeField%22)), titleSizeSpinner %7D;
 %0A%0A%09%09
@@ -2779,24 +2779,8 @@
 ield
-, titleSizeField
  %7D);

remove useless form component