Singleton de la factory
authorPAMPHILE Jonathan <pamphile@efrei.fr>
Mon, 14 Sep 2009 23:49:47 +0200
changeset 54 c724ac229181
parent 53 09d0bc6970b5
child 56 0662bd606c28
Singleton de la factory Menu XML intégré avec treeview
src/FingersDance.ActionFactory/ActionFactory.cs
src/FingersDance.ActionFactory/ActionGenerator.cs
src/FingersDance.ActionFactory/FingersDance.ActionFactory.csproj
src/FingersDance.Control.Menu/FingersDance.Control.Menu.csproj
src/FingersDance.Control.Menu/Item.cs
src/FingersDance.Control.Menu/Menu.cs
src/FingersDance.Control.Menu/SurfaceMenuTest.xaml.cs
src/FingersDance.Control.Menu/UserControlMenu.xaml
src/FingersDance.Control.Menu/UserControlMenu.xaml.cs
src/FingersDance.Control.Player/UserControlPlayer.xaml
src/FingersDance/FingersDance.csproj
src/FingersDance/MainSurfaceWindow.xaml.cs
src/FingersDance/Menu.iri
--- a/src/FingersDance.ActionFactory/ActionFactory.cs	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.ActionFactory/ActionFactory.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -3,25 +3,23 @@
 using System.Linq;
 using System.Text;
 using FingersDance.Control.Player;
-using FingersDance.Actions;
 
 namespace FingersDance.ActionFactory
 {
     public class ActionFactory
     {
-        private Dictionary<String, Type> actionDict = new Dictionary<string, Type>();
+        private static ActionGenerator _Factory;
 
         public ActionFactory()
+        { }
+
+        public ActionGenerator GetGenerator()
         {
-            actionDict.Add("ActionPlayMedia", typeof(FingersDance.Actions.ActionPlayMedia));
-            actionDict.Add("ActionShowMessage", typeof(FingersDance.Actions.ActionShowMessage));
-            actionDict.Add("ActionOpenMedia", typeof(FingersDance.Actions.ActionOpenMedia));
-            actionDict.Add("ActionStopMedia", typeof(FingersDance.Actions.ActionStopMedia));            
-        }
-
-        public ActionBase GetAction(string T, object Args)
-        {
-            return (ActionBase)Activator.CreateInstance(actionDict[T]);
+            if (_Factory == null)
+            {
+                _Factory = new ActionGenerator();
+            }
+            return _Factory;
         }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.ActionFactory/ActionGenerator.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FingersDance.Actions;
+
+namespace FingersDance.ActionFactory
+{
+    public class ActionGenerator
+    {
+        private Dictionary<String, Type> actionDict = new Dictionary<string, Type>();
+
+        public ActionGenerator()
+        {
+            actionDict.Add("ActionPlayMedia", typeof(FingersDance.Actions.ActionPlayMedia));
+            actionDict.Add("ActionShowMessage", typeof(FingersDance.Actions.ActionShowMessage));
+            actionDict.Add("ActionOpenMedia", typeof(FingersDance.Actions.ActionOpenMedia));
+            actionDict.Add("ActionStopMedia", typeof(FingersDance.Actions.ActionStopMedia));            
+        }
+
+        public ActionBase GetAction(string T, object Args)
+        {
+            return (ActionBase)Activator.CreateInstance(actionDict[T]);
+        }
+    }
+}
--- a/src/FingersDance.ActionFactory/FingersDance.ActionFactory.csproj	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.ActionFactory/FingersDance.ActionFactory.csproj	Mon Sep 14 23:49:47 2009 +0200
@@ -46,6 +46,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ActionFactory.cs" />
+    <Compile Include="ActionGenerator.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
--- a/src/FingersDance.Control.Menu/FingersDance.Control.Menu.csproj	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.Control.Menu/FingersDance.Control.Menu.csproj	Mon Sep 14 23:49:47 2009 +0200
@@ -88,6 +88,8 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Item.cs" />
+    <Compile Include="Menu.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
@@ -131,5 +133,15 @@
       <SubType>Designer</SubType>
     </Page>
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\FingersDance.ActionFactory\FingersDance.ActionFactory.csproj">
+      <Project>{C7B905EA-0678-4DA0-8EF8-7F9CBD22818E}</Project>
+      <Name>FingersDance.ActionFactory</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\FingersDance.Actions\FingersDance.Actions.csproj">
+      <Project>{1E80D5A1-C45C-443B-8992-4A4D78D280FC}</Project>
+      <Name>FingersDance.Actions</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.Menu/Item.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FingersDance.Control.Menu
+{
+    [Serializable]
+    public class Item
+    {
+        public List<Item> Items = new List<Item>();
+        public string Name = "";
+        public string Action = "";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.Menu/Menu.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FingersDance.Control.Menu
+{
+    [Serializable]
+    public class Menu
+    {
+        public List<Item> Items = new List<Item>();
+    }
+}
--- a/src/FingersDance.Control.Menu/SurfaceMenuTest.xaml.cs	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.Control.Menu/SurfaceMenuTest.xaml.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -25,6 +25,8 @@
         /// <summary>
         /// Default constructor.
         /// </summary>
+        /// 
+
         public SurfaceWindow1()
         {
             InitializeComponent();
--- a/src/FingersDance.Control.Menu/UserControlMenu.xaml	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.Control.Menu/UserControlMenu.xaml	Mon Sep 14 23:49:47 2009 +0200
@@ -8,47 +8,19 @@
 	x:Name="UserControl"
 	Width="245" Height="Auto" xmlns:Custom="http://schemas.microsoft.com/surface/2008">
 
-	<StackPanel x:Name="LayoutRoot" Width="Auto" Height="Auto">
-		<StackPanel.Background>
-			<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
-				<GradientStop Color="#FF000000" Offset="0"/>
-				<GradientStop Color="#FF444444" Offset="0.991"/>
-				<GradientStop Color="#FF757575" Offset="0.906"/>
-				<GradientStop Color="#FF414141" Offset="0.772"/>
-			</LinearGradientBrush>
-		</StackPanel.Background>
-		<Custom:SurfaceButton FontSize="18" FontWeight="Normal" Foreground="#FFAEAEAE" HorizontalAlignment="Stretch" x:Name="ButtonAnnotation" Width="Auto" Height="45" Content="Annotation" ContactDown="ButtonAnnotation_ContactDown" Click="ButtonAnnotation_Click"/>
-		<StackPanel RenderTransformOrigin="0.5,0.5" Visibility="Collapsed" HorizontalAlignment="Right" x:Name="PanelAnnotation" Width="208" Height="Auto">
-			<StackPanel.RenderTransform>
-				<TransformGroup>
-					<ScaleTransform ScaleX="1" ScaleY="1"/>
-					<SkewTransform AngleX="0" AngleY="0"/>
-					<RotateTransform Angle="0"/>
-					<TranslateTransform X="0" Y="0"/>
-				</TransformGroup>
-			</StackPanel.RenderTransform>
-			<Custom:SurfaceButton FontSize="14" FontWeight="Normal" Foreground="#FFAEAEAE" Width="Auto" Height="25" Content="Cinématographique" Visibility="Visible" Background="#72FFFFFF" x:Name="ButtonChildCine" ContactDown="ButtonChildCine_ContactDown" Click="ButtonChildCine_Click"/>
-			<StackPanel x:Name="PanelChildCine" Width="Auto" Height="Auto" Visibility="Collapsed" HorizontalAlignment="Right" Background="{x:Null}">
-				<Custom:SurfaceButton Height="25" Content="Mouvement de Caméra" x:Name="ButtonChild1MouvCam" Click="ButtonChild1MouvCam_Click" ContactDown="ButtonChild1MouvCam_ContactDown"/>
-				<StackPanel x:Name="PanelChild1MouvCam" Height="Auto" Visibility="Collapsed" HorizontalAlignment="Right">
-					<Custom:SurfaceButton Content="MouvCam1" x:Name="buttonMouvCam1"/>
-					<Custom:SurfaceButton Content="MouvCam2" x:Name="bouttonMouvCam2"/>
-				</StackPanel>
-				<Custom:SurfaceButton Height="25" Content="Axe de Caméra" x:Name="buttonChild1AxeCam" Click="buttonChild1AxeCam_Click" ContactDown="buttonChild1AxeCam_ContactDown"/>
-				<StackPanel x:Name="PanelChild1AxeCam" Height="Auto" Visibility="Collapsed" HorizontalAlignment="Right">
-					<Custom:SurfaceButton Content="Axe camèra1" x:Name="buttonAxeCam1"/>
-					<Custom:SurfaceButton Content="Axe camèra2" x:Name="buttonAxeCam2"/>
-					<Custom:SurfaceButton Content="Axe camèra3" x:Name="buttonAxeCam3"/>
-					<Custom:SurfaceButton Content="Axe camèra4" x:Name="buttonAxeCam4"/>
-				</StackPanel>
-			</StackPanel>
-			<Custom:SurfaceButton FontSize="14" FontWeight="Normal" Foreground="#FFAEAEAE" Width="Auto" Height="26" Content="Chorégraphique" Background="#72FFFFFF" Visibility="Visible" x:Name="ButtonChildChore" Click="ButtonChildChore_Click" ContactDown="ButtonChildChore_ContactDown"/>
-			<StackPanel x:Name="PanelChildChore" Width="Auto" Height="Auto" Visibility="Collapsed" HorizontalAlignment="Right" Background="#FFA6A6A6">
-				<Custom:SurfaceButton Content="ChildChore1" x:Name="button1"/>
-				<Custom:SurfaceButton Content="ChildChore2" x:Name="button2"/>
-			</StackPanel>
-		</StackPanel>
-		<Custom:SurfaceButton FontSize="18" FontWeight="Normal" Foreground="#FFAEAEAE" x:Name="ButtonRecherche" Width="Auto" Height="45" Content="Recherche" ContactDown="ButtonRecherche_ContactDown" Click="ButtonRecherche_Click"/>
-		<StackPanel Visibility="Collapsed" HorizontalAlignment="Right" x:Name="PanelRecherche" Width="262" Height="45"/>
-	</StackPanel>
+    <StackPanel x:Name="LayoutRoot" Width="Auto" Height="Auto">
+        <StackPanel.Background>
+            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
+                <GradientStop Color="#FF000000" Offset="0"/>
+                <GradientStop Color="#FF444444" Offset="0.991"/>
+                <GradientStop Color="#FF757575" Offset="0.906"/>
+                <GradientStop Color="#FF414141" Offset="0.772"/>
+            </LinearGradientBrush>
+        </StackPanel.Background>
+
+
+
+
+
+    </StackPanel>
 </UserControl>
\ No newline at end of file
--- a/src/FingersDance.Control.Menu/UserControlMenu.xaml.cs	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.Control.Menu/UserControlMenu.xaml.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -7,6 +7,9 @@
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Navigation;
+using Microsoft.Surface;
+using Microsoft.Surface.Presentation;
+using System.Xml.Serialization;
 
 namespace FingersDance.Control.Menu
 {
@@ -23,32 +26,97 @@
         //Premet de deplacer les sous menus vers la droite pour avoir un effect tree view
          private void initChildSize()
         {
-             //Niveau 1
-            PanelAnnotation.Width -= 0.10*this.Width;
-            PanelRecherche.Width -= 0.10 * this.Width;
-             //Niveau 2
-            PanelChildChore.Width -= 0.10 * this.Width;
-            PanelChildCine.Width -= 0.10 * this.Width;
-             //Niveau 3
-            PanelChild1AxeCam.Width -= 0.05 * this.Width;
-            PanelChild1MouvCam.Width -= 0.05 * this.Width;
-
+            StreamReader reader = null;
+            reader = new StreamReader("../../Menu.iri");
+            XmlSerializer serializer = new XmlSerializer(typeof(Menu));
+            Menu temp = (Menu)serializer.Deserialize(reader);
+            foreach (Item elt in temp.Items)
+                try
+                {
+                    LayoutRoot.Children.Add(CreateMenuItem(elt));
+                }
+                catch (Exception) { }
+            reader.Close();
         }
 
-         #region Events
-         //Annotation
-        private void ButtonAnnotation_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
-        {
-            if (PanelAnnotation.Visibility == Visibility.Collapsed)
-            {
-                PanelAnnotation.Visibility = Visibility.Visible;
-            }
-            else
-            {
-                PanelAnnotation.Visibility = Visibility.Collapsed;
-            }
-        }
+         public StackPanel CreateMenuItem(Item item)
+         {
+             try
+             {
+                 StackPanel MItem = new StackPanel();
+                 Microsoft.Surface.Presentation.Controls.SurfaceButton ItemButton = new Microsoft.Surface.Presentation.Controls.SurfaceButton();
+                 ItemButton.Content = item.Name;
+                 if (item.Items.Count > 0)
+                 {
+                     ItemButton.ContactDown += ButtonMenu_ContactDown;
+                     ItemButton.Click += ButtonMenu_ContactDown;
+                     MItem.Children.Add(ItemButton);
+                     StackPanel Temp = new StackPanel();
+                     Temp.Margin = new Thickness(15,0,0,0);
+                     foreach (Item elt in item.Items)
+                         try
+                         {
+                             Temp.Children.Add(CreateMenuItem(elt));
+                         }
+                         catch (Exception) { }
+                     Temp.Name = ItemButton.Content + "Panel";
+                     Temp.Visibility = Visibility.Collapsed;
+                     MItem.Children.Add(Temp);
+                 }
+                 else
+                 {
+                     ItemButton.ContactDown += GenerateAction;
+                     ItemButton.Click += GenerateAction;
+                     MItem.Children.Add(ItemButton);
+                 }
+                 return MItem;
+             }
+             catch (Exception ex)
+             {
+                 throw ex;
+             }
+         }
 
+         private void GenerateAction(Object sender, RoutedEventArgs Event)
+         {
+             try
+             {
+                 ActionFactory.ActionGenerator AG = (new ActionFactory.ActionFactory()).GetGenerator();
+                 FingersDance.Actions.ActionBase action = AG.GetAction("Action" + ((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content, null);
+                 if (action != null)
+                 {
+                     //action.Execute();
+                     //this.debug.addToList(action.GetType().ToString());
+                 }
+             }
+             catch (Exception e) { }
+         }
+
+         private void ButtonMenu_ContactDown(object sender, RoutedEventArgs e)
+         {
+             foreach (UIElement Child in ((Panel)((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Parent).Children)
+                 try
+                 {
+                     if (((StackPanel)Child).Name.Equals(((Microsoft.Surface.Presentation.Controls.SurfaceButton)sender).Content + "Panel"))
+                     {
+                         if (((StackPanel)Child).Visibility == Visibility.Collapsed)
+                         {
+                             ((StackPanel)Child).Visibility = Visibility.Visible;
+                         }
+                         else
+                         {
+                             ((StackPanel)Child).Visibility = Visibility.Collapsed;
+                         }
+                         return;
+                     }
+                 }
+                 catch (Exception ex) { }
+         }
+
+        #region Events
+
+     /*    
+        //Annotation
         private void ButtonAnnotation_Click(object sender, RoutedEventArgs e)
         {
             if (PanelAnnotation.Visibility == Visibility.Collapsed)
@@ -180,6 +248,8 @@
                 PanelChild1AxeCam.Visibility = Visibility.Collapsed;
             }
         }
+        */
+        
         #endregion
 
     
--- a/src/FingersDance.Control.Player/UserControlPlayer.xaml	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance.Control.Player/UserControlPlayer.xaml	Mon Sep 14 23:49:47 2009 +0200
@@ -15,7 +15,7 @@
         <Grid x:Name="LayoutRoot" Width="{Binding Path=ActualWidth, ElementName=UserControl, Mode=Default}" Height="{Binding Path=ActualHeight, ElementName=UserControl, Mode=Default}" Background="{x:Null}" >
         	<Viewbox Margin="0,0,0,0" Width="{Binding Path=ActualWidth, ElementName=UserControl, Mode=Default}" Height="{Binding Path=ActualHeight, ElementName=UserControl, Mode=Default}" Stretch="Uniform">
         		<Grid Width="560" Height="400">
-        			<MediaElement x:Name="MediaElementVideo" MediaOpened="MediaElementVideo_MediaOpened" Stretch="Fill" ScrubbingEnabled="False" StretchDirection="Both" />
+        			<MediaElement x:Name="MediaElementVideo" MediaOpened="MediaElementVideo_MediaOpened" Stretch="Fill" ScrubbingEnabled="False" StretchDirection="Both" DragEnter="MediaElementVideo_DragEnter" />
         			<Custom:SurfaceButton x:Name="Rewind_area" Content="Play/Pause" ContactDown="ButtonRewind_ContactDown" Click="ButtonRewind_Click" Foreground="{x:Null}" Background="#FFF7F0F0" BorderBrush="{x:Null}" Opacity="0" Width="72" HorizontalAlignment="Left"/>
         			<Custom:SurfaceButton x:Name="Fast_Forward_area" Content="Play/Pause" ContactDown="ButtonFastForward_ContactDown" Click="ButtonFastForward_Click" Foreground="{x:Null}" Background="#FFF7F0F0" BorderBrush="{x:Null}" Opacity="0" Width="72" HorizontalAlignment="Right"/>
         			<Custom:SurfaceButton x:Name="Play_Pause_area" ContactDown="ButtonPlayPause_ContactDown" Click="ButtonPlayPause_Click" Foreground="{x:Null}" Background="#FFF7F0F0" BorderBrush="{x:Null}" Opacity="0" Margin="76,0,76,0"/>
--- a/src/FingersDance/FingersDance.csproj	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance/FingersDance.csproj	Mon Sep 14 23:49:47 2009 +0200
@@ -136,6 +136,10 @@
     </Page>
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\FingersDance.ActionFactory\FingersDance.ActionFactory.csproj">
+      <Project>{C7B905EA-0678-4DA0-8EF8-7F9CBD22818E}</Project>
+      <Name>FingersDance.ActionFactory</Name>
+    </ProjectReference>
     <ProjectReference Include="..\FingersDance.Control.Pivot\FingersDance.Control.Pivot.csproj">
       <Project>{0EC4C48C-132C-4926-9A09-A4135C58688C}</Project>
       <Name>FingersDance.Control.Pivot</Name>
--- a/src/FingersDance/MainSurfaceWindow.xaml.cs	Mon Sep 14 17:43:41 2009 +0200
+++ b/src/FingersDance/MainSurfaceWindow.xaml.cs	Mon Sep 14 23:49:47 2009 +0200
@@ -25,6 +25,10 @@
         /// <summary>
         /// Default constructor.
         /// </summary>
+        /// 
+
+        ActionFactory.ActionGenerator _Factory = new FingersDance.ActionFactory.ActionFactory().GetGenerator();
+
         public SurfaceWindow1()
         {
             InitializeComponent();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance/Menu.iri	Mon Sep 14 23:49:47 2009 +0200
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<Menu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+	<Items>
+		<Item>
+			<Name>Annotation</Name>
+			<Items>
+				<Item>
+					<Name>Cinematographique</Name>
+					<Items>
+						<Item>
+							<Name>MouvCam1</Name>
+							<Items/>
+							<Action>MouvCam1</Action>
+						</Item>
+						<Item>
+							<Name>MouvCam2</Name>
+							<Items/>
+							<Action>MouvCam2</Action>
+						</Item>
+					</Items>
+					<Action>Cinematographique</Action>
+				</Item>
+				<Item>
+					<Name>Camera</Name>
+					<Items>
+						<Item>
+							<Name>Axe camera1</Name>
+							<Items/>
+							<Action>Axe camera1</Action>
+						</Item>
+						<Item>
+							<Name>Axe camera2</Name>
+							<Items/>
+							<Action>Axe camera2</Action>
+						</Item>
+						<Item>
+							<Name>Axe camera3</Name>
+							<Items/>
+							<Action>Axe camera3</Action>
+						</Item>
+						<Item>
+							<Name>Axe camera4</Name>
+							<Items/>
+							<Action>Axe camera4</Action>
+						</Item>
+					</Items>
+					<Action>Camera</Action>
+				</Item>
+				<Item>
+					<Name>Choregraphique</Name>
+					<Items>
+						<Item>
+							<Name>ChildChore1</Name>
+							<Items/>
+							<Action>ChildChore1</Action>
+						</Item>
+						<Item>
+							<Name>ChildChore2</Name>
+							<Items/>
+							<Action>ChildChore2</Action>
+						</Item>
+					</Items>
+					<Action>Choregraphique</Action>
+				</Item>
+			</Items>
+			<Action>Annotation</Action>
+		</Item>
+		<Item>
+			<Name>ButtonRecherche</Name>
+			<Items/>
+			<Action>ButtonRecherche</Action>
+		</Item>
+	</Items>
+</Menu>
\ No newline at end of file