/*
Uiml.Net: a Uiml.Net renderer (http://lumumba.uhasselt.be/kris/research/uiml.net/)
Copyright (C) 2003 Kris Luyten (kris.luyten@uhasselt.be)
Expertise Centre for Digital Media (http://edm.uhasselt.be)
Hasselt University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
namespace Uiml.Executing
{
using Uiml;
using System;
using System.Xml;
using System.Collections;
using System.IO;
using Uiml.Rendering;
///
/// Represents <condition> of the XML
///
public class Condition : IExecutable, IUimlElement
{
private string m_conditionType;
private System.Object m_conditionObject;
private ArrayList m_actions;
private Part m_partTree;
private IRenderer m_renderer;
///
/// Constructor
///
public Condition()
{
m_actions = new ArrayList();
}
///
/// Constructor
///
/// XML node
/// The parts of the GUI
public Condition(XmlNode xmlNode, Part partTop) : this()
{
m_partTree = partTop;
Process(xmlNode);
}
///
/// For catching events
///
///
public delegate System.Object EventNotifier();
///
/// Process the xml node <condition>
///
/// The node to process
public void Process(XmlNode n)
{
if(n.Name == CONDITION)
{
if(n.HasChildNodes)
{
XmlNodeList xnl = n.ChildNodes;
switch(xnl[0].Name)
{
case EVENT:
ConditionType = EVENT;
m_conditionObject = new Event(xnl[0]);
break;
case OPERATOR:
ConditionType = OPERATOR;
m_conditionObject = new Op(xnl[0], m_partTree);
break;
case EQUAL:
ConditionType = EQUAL;
m_conditionObject = new Equal(xnl[0], m_partTree);
break;
}
}
}
}
///
/// Execute the condition
///
///
public System.Object Execute()
{
//if(CheckCondition())
{
IEnumerator enumActions = m_actions.GetEnumerator();
while(enumActions.MoveNext())
{
Action a = (Action)enumActions.Current;
a.Execute(m_renderer);
}
}
return null;
}
///
/// Check if the event triggered satisfies the condition that was declared
///
private bool CheckCondition()
{
if (ConditionType == EVENT)
{
// always true => otherwise an error in linking the events
return true;
}
else if (ConditionType == OPERATOR)
{
((Op)m_conditionObject).CheckCondition();
}
else if (ConditionType == EQUAL)
{
((Equal)m_conditionObject).CheckCondition();
}
return false;
}
///
/// Execute the condition
///
/// The renderer for the interface
///
public System.Object Execute(IRenderer renderer)
{
m_renderer = renderer;
return Execute();
}
public void Execute(System.Object o, EventArgs a)
{
}
///
/// Attach an action to this condition
///
/// The action to be attached
public void Attach(Action a)
{
m_actions.Add(a);
}
///
/// Get or set the condition type
///
public string ConditionType
{
get { return m_conditionType; }
set { m_conditionType = value; }
}
///
/// Returns all the events this condition specifies.
///
public IEnumerator Events
{
get
{
return GetEvents().GetEnumerator();
}
}
///
/// Returns all the events this condition specifies
///
///
public ArrayList GetEvents()
{
ArrayList l = new ArrayList();
GetEvents(ref l);
return l;
}
///
/// Calculate all the events this condition specifies
///
/// A reference to the list of events
private void GetEvents(ref ArrayList l)
{
l.Add(m_conditionObject);
/*if(m_conditionObject is Event)
l.Add(m_conditionObject);
else if(m_conditionObject is Op)
((Op)m_conditionObject).GetEvents(l);
else if(m_conditionObject is Equal)
((Equal)m_conditionObject).GetEvents(l);*/
}
///
/// Get the children of this condition
///
public ArrayList Children
{
get { return null; }
}
public Object ConditionObject
{
get { return m_conditionObject; }
}
public const string CONDITION = "condition";
public const string EQUAL = "equal";
public const string OPERATOR = "op";
public const string EVENT = "event";
}
}