//---------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="AttributeNode.cs" company="DarkWynter Studios">
//     Copyright (C)2007 DarkWynter Studios.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace DarkWynter.App
{
    public class AttributeNode
    {
        public static int colLocation = 16;
        public static int rowLocation = 16;
        public static int labelWidth = 100;
        public static int labelHeight = 16;
        public static int textWidth = 400;
        public static int textHeight = 20;
        public static int columnSpacer = 25;
        public static int rowWidth = 32;
        public static int topOfPage = 16;

        public TextBox textBox;
        public Label label;
        public XmlAttribute attribute;
        public int nodeType;

         /// <summary>
         /// Create and Position a standard Label
         /// </summary>
         /// <param name="panel">Panel you are using</param>
         /// <param name="labelText">The Text for the Label</param>
        public AttributeNode(Panel panel, String labelText)
        {
            // Move cursor to next row down
            rowLocation += rowWidth;
            nodeType = 0;

            // Create Lable
            label = new Label();
            label.Text = labelText;
            label.Location = new Point(colLocation, rowLocation);
            label.Size = new Size(labelWidth, labelHeight);

            // Style
            label.ForeColor = Color.LightGray;
            label.Font = new Font(label.Font, FontStyle.Bold);
            
            // Add to Panel
            panel.Controls.Add(label);
        }
        /// <summary>
        /// Convert an Xml Object into a Label and TextBox
        /// </summary>
        /// <param name="panel">Panel you are using</param>
        /// <param name="nodeAttribute">Attributes from the node</param>
        public AttributeNode(Panel panel, XmlAttribute nodeAttribute)
        {
            // Move cursor to next row down
            rowLocation += rowWidth;
            nodeType = 1;
            attribute = nodeAttribute;

            // Create Label
            label = new Label();
            label.Text = attribute.Name;
            label.Location = new Point(colLocation, rowLocation);
            label.Size = new Size(labelWidth, labelHeight);

            // Style
            label.ForeColor = Color.LightGray;


            // Create Textbox
            textBox = new TextBox();
            textBox.Text = attribute.Value;
            textBox.Location = new Point(labelWidth + columnSpacer, rowLocation);
            textBox.Size = new Size(textWidth, textHeight);


            // Add to Panel
            panel.Controls.Add(label);
            panel.Controls.Add(textBox);
        }
        /// <summary>
        /// Clones the Label
        /// </summary>
        /// <param name="panel">Panel you are using</param>
        /// <returns>AttributeNode</returns>
        public AttributeNode Clone(Panel panel)
        {
            // Reset carriage return to top of page
            AttributeNode.rowLocation = AttributeNode.topOfPage;

            // Init Clone Node
            AttributeNode attrNode = new AttributeNode(panel, attribute);
            attrNode.nodeType = nodeType;

            // Clone Label 
            attrNode.label = new Label();
            attrNode.label.Text = label.Text;
            attrNode.label.Location = label.Location;
            attrNode.label.Size = label.Size;

            // Clone Textbox
            if (nodeType == 1)
            {
                attrNode.textBox.Text = textBox.Text;
                attrNode.textBox.Location = textBox.Location;
                attrNode.textBox.Size = textBox.Size;
            }
            return attrNode;
        }
    }

}