package com.delormeloic.generator.model.slides;

import org.json.JSONObject;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.text.Font;

/**
 * This class represents an header.
 *
 * @author DELORME Loïc
 * @since 1.0.0
 */
public class Header implements ISerializable
{
	/**
	 * The middle text attribute.
	 */
	public static final String MIDDLE_TEXT_ATTRIBUTE = "middleText";

	/**
	 * The middle text font attribute.
	 */
	public static final String MIDDLE_TEXT_FONT_ATTRIBUTE = "middleTextFont";

	/**
	 * The middle text size attribute.
	 */
	public static final String MIDDLE_TEXT_SIZE_ATTRIBUTE = "middleTextSize";

	/**
	 * The middle text.
	 */
	private final StringProperty middleText;

	/**
	 * The middle text font.
	 */
	private final ObjectProperty<Font> middleTextFont;

	/**
	 * The middle text size.
	 */
	private final IntegerProperty middleTextSize;

	/**
	 * Create an header.
	 * 
	 * @param data
	 *            The data.
	 */
	public Header(JSONObject data)
	{
		this.middleText = new SimpleStringProperty(data.getString(MIDDLE_TEXT_ATTRIBUTE));
		this.middleTextFont = new SimpleObjectProperty<Font>(new Font(data.getString(MIDDLE_TEXT_FONT_ATTRIBUTE), IConstants.DEFAULT_FONT_SIZE));
		this.middleTextSize = new SimpleIntegerProperty(data.getInt(MIDDLE_TEXT_SIZE_ATTRIBUTE));
	}

	/**
	 * Create an header.
	 */
	public Header()
	{
		this.middleText = new SimpleStringProperty(IConstants.DEFAULT_TEXT);
		this.middleTextFont = new SimpleObjectProperty<Font>(IConstants.DEFAULT_FONT);
		this.middleTextSize = new SimpleIntegerProperty(IConstants.DEFAULT_FONT_SIZE);
	}

	/**
	 * Get the middle text.
	 * 
	 * @return The middle text.
	 */
	public String getMiddleText()
	{
		return this.middleText.get();
	}

	/**
	 * Get the middle text property.
	 * 
	 * @return The middle text property.
	 */
	public StringProperty getMiddleTextProperty()
	{
		return this.middleText;
	}

	/**
	 * Get the middle text font.
	 * 
	 * @return The middle text font.
	 */
	public Font getMiddleTextFont()
	{
		return this.middleTextFont.get();
	}

	/**
	 * Get the middle text font property.
	 * 
	 * @return The middle text font property.
	 */
	public ObjectProperty<Font> getMiddleTextFontProperty()
	{
		return this.middleTextFont;
	}

	/**
	 * Get the middle text size.
	 * 
	 * @return The middle text size.
	 */
	public int getMiddleTextSize()
	{
		return this.middleTextSize.get();
	}

	/**
	 * Get the middle text size property.
	 * 
	 * @return The middle text size property.
	 */
	public IntegerProperty getMiddleTextSizeProperty()
	{
		return this.middleTextSize;
	}

	/**
	 * @see com.delormeloic.generator.model.slides.ISerializable#toJSON()
	 */
	@Override
	public JSONObject toJSON()
	{
		final JSONObject data = new JSONObject();
		data.put(MIDDLE_TEXT_ATTRIBUTE, getMiddleText());
		data.put(MIDDLE_TEXT_FONT_ATTRIBUTE, getMiddleTextFont().getName());
		data.put(MIDDLE_TEXT_SIZE_ATTRIBUTE, getMiddleTextSize());

		return data;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		return (getMiddleText().hashCode() + getMiddleTextFont().hashCode() + getMiddleTextSize());
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object object)
	{
		if (object == null)
		{
			return false;
		}

		if (this == object)
		{
			return true;
		}

		if (!(object instanceof Header))
		{
			return false;
		}

		final Header header = (Header) object;

		if (!getMiddleText().equals(header.getMiddleText()))
		{
			return false;
		}

		if (!getMiddleTextFont().equals(header.getMiddleTextFont()))
		{
			return false;
		}

		if (getMiddleTextSize() != header.getMiddleTextSize())
		{
			return false;
		}

		return true;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return toJSON().toString();
	}
}
@@ -104,112 +104,14 @@
 rty.
-IntegerProperty;%0Aimport javafx.beans.property.ObjectProperty;%0Aimport javafx.beans.property.SimpleInteger
+Object
 Prop
@@ -663,130 +663,8 @@
 %22;%0A%0A
-%09/**%0A%09 * The middle text size attribute.%0A%09 */%0A%09public static final String MIDDLE_TEXT_SIZE_ATTRIBUTE = %22middleTextSize%22;%0A%0A
 %09/**
@@ -826,92 +826,8 @@
 t;%0A%0A
-%09/**%0A%09 * The middle text size.%0A%09 */%0A%09private final IntegerProperty middleTextSize;%0A%0A
 %09/**
@@ -1164,100 +1164,8 @@
 ));%0A
-%09%09this.middleTextSize = new SimpleIntegerProperty(data.getInt(MIDDLE_TEXT_SIZE_ATTRIBUTE));%0A
 %09%7D%0A%0A
@@ -1372,89 +1372,8 @@
 T);%0A
-%09%09this.middleTextSize = new SimpleIntegerProperty(IConstants.DEFAULT_FONT_SIZE);%0A
 %09%7D%0A%0A
@@ -2028,348 +2028,8 @@
 %09%7D%0A%0A
-%09/**%0A%09 * Get the middle text size.%0A%09 * %0A%09 * @return The middle text size.%0A%09 */%0A%09public int getMiddleTextSize()%0A%09%7B%0A%09%09return this.middleTextSize.get();%0A%09%7D%0A%0A%09/**%0A%09 * Get the middle text size property.%0A%09 * %0A%09 * @return The middle text size property.%0A%09 */%0A%09public IntegerProperty getMiddleTextSizeProperty()%0A%09%7B%0A%09%09return this.middleTextSize;%0A%09%7D%0A%0A
 %09/**
@@ -2317,69 +2317,8 @@
 ());
-%0A%09%09data.put(MIDDLE_TEXT_SIZE_ATTRIBUTE, getMiddleTextSize());
 %0A%0A%09%09
@@ -2491,30 +2491,8 @@
 de()
- + getMiddleTextSize()
 );%0A%09
@@ -2882,24 +2882,24 @@
 false;%0A%09%09%7D%0A%0A
+
 %09%09if (!getMi
@@ -2979,91 +2979,8 @@
 %09%7D%0A%0A
-%09%09if (getMiddleTextSize() != header.getMiddleTextSize())%0A%09%09%7B%0A%09%09%09return false;%0A%09%09%7D%0A%0A
 %09%09re

remove size attribute