PageRenderTime 2791ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Programming/Labs/4sem/ISP/MusicSheetEditor/Benko.MusicSheetEditor.GUI/Windows/EditSheetWindow.xaml.cs

http://bsuir-informatics-labs.googlecode.com/
C# | 325 lines | 260 code | 52 blank | 13 comment | 20 complexity | 7cd56fc97842a309c156b661a0b9ff42 MD5 | raw file
Possible License(s): AGPL-1.0, CC0-1.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Animation;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using System.Collections.ObjectModel;
  15. using Benko.MusicSheetEditor.BLL;
  16. using Benko.MusicSheetEditor.Global;
  17. namespace Benko.MusicSheetEditor.GUI
  18. {
  19. /// <summary>
  20. /// Interaction logic for EditSheetWindow.xaml
  21. /// </summary>
  22. public partial class EditSheetWindow : Window, IEditElementWindow<Sheet>
  23. {
  24. public Sheet Element { get { return m_oWorkingSheet; } }
  25. public int Handle { get; internal set; }
  26. MusicSheetsManager m_oMSManager;
  27. Sheet m_oWorkingSheet;
  28. List<Layer> m_oWorkingLayers;
  29. ObservableCollection<LayerInfo> m_oLayersInfo;
  30. LayerBuilder m_oLayerBuilder;
  31. LayerAccidentalBuilder m_oLayerAccidentalBuilder;
  32. RelativeLoudnessBuilder m_oRelativeLoudnessBuilder;
  33. GradualChangeBuilder m_oGradualChangeBuilder;
  34. ChordBuilder m_oChordBuilder;
  35. public EditSheetWindow()
  36. {
  37. InitializeComponent();
  38. m_oMSManager = MusicSheetsManager.Instance;
  39. m_oLayerAccidentalBuilder = new LayerAccidentalBuilder(this);
  40. m_oLayerBuilder = new LayerBuilder(this);
  41. m_oRelativeLoudnessBuilder = new RelativeLoudnessBuilder(this);
  42. m_oGradualChangeBuilder = new GradualChangeBuilder(this);
  43. m_oChordBuilder = new ChordBuilder(this);
  44. }
  45. public EditSheetWindow(Sheet v_oSheet, int v_iHandle)
  46. : this()
  47. {
  48. m_oWorkingSheet = v_oSheet;
  49. Handle = v_iHandle;
  50. InitializeLayers();
  51. }
  52. private void InitializeLayers()
  53. {
  54. m_oWorkingLayers = m_oWorkingSheet.GetAllLayers();
  55. m_oLayersInfo = new ObservableCollection<LayerInfo>(m_oWorkingLayers.Select(x => new LayerInfo(x)));
  56. m_oLayersInfo.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(m_oLayerInfos_CollectionChanged);
  57. LayersView.ItemsSource = m_oLayersInfo;
  58. }
  59. void l_SourceUpdated(object sender, DataTransferEventArgs e)
  60. {
  61. //var list = (ListBox)sender;
  62. }
  63. void m_oLayerInfos_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  64. {
  65. switch (e.Action)
  66. {
  67. case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
  68. foreach (var x in e.NewItems.Cast<LayerInfo>())
  69. {
  70. m_oWorkingSheet.AddLayer(x.WorkingLayer);
  71. }
  72. break;
  73. case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
  74. foreach (var x in e.OldItems.Cast<LayerInfo>())
  75. {
  76. m_oWorkingSheet.DeleteLayer(x.WorkingLayer);
  77. }
  78. break;
  79. }
  80. }
  81. private void InitializeMusicalElements()
  82. {
  83. //MusicalCollectionView.ItemsSource = m_oLayerInfos[0].m_oMusicalCollection;
  84. }
  85. private void Button_Click(object sender, RoutedEventArgs e)
  86. {
  87. var oLayer = new LayerInfo();
  88. m_oLayersInfo.Add(oLayer);
  89. m_oLayerBuilder.BuildElement(oLayer.WorkingLayer, new ElementBuiltCallBack<Layer>(LayerBuiltCallBack), null);
  90. }
  91. private void LayerBuiltCallBack(Layer v_oBuiltLayer, object v_oContext)
  92. {
  93. int a = 3;
  94. }
  95. private void LayersView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  96. {
  97. var oList = sender as ListBox;
  98. foreach (var x in oList.SelectedItems.Cast<LayerInfo>().Select(x => x.WorkingLayer))
  99. {
  100. m_oLayerBuilder.BuildElement(x, null, null);
  101. }
  102. }
  103. private void LayersView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  104. {
  105. var list = (ListBox) sender;
  106. var removeStoryBoard = (Storyboard)FindResource("RemoveItemStoryboard");
  107. ListBoxItem l;
  108. //ScaleTransform s;
  109. //s.ScaleX
  110. // l.Loaded += new RoutedEventHandler(l_Loaded);
  111. //l.Initialized += new EventHandler(l_Initialized);
  112. //foreach (var item in list)
  113. //{
  114. // //item.BeginStoryboard(removeStoryBoard);
  115. //}
  116. }
  117. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  118. {
  119. var oRes = MessageBox.Show("????????? ??????????", "?????????????? ?????????", MessageBoxButton.YesNoCancel);
  120. if (oRes == MessageBoxResult.Yes)
  121. {
  122. m_oWorkingSheet.SaveAllChanges();
  123. }
  124. if (oRes == MessageBoxResult.Cancel)
  125. {
  126. e.Cancel = true;
  127. }
  128. }
  129. private void Button_Click_1(object sender, RoutedEventArgs e)
  130. {
  131. var oList = wLayerAccidentalsView;
  132. var oCollection = (ObservableCollection<LayerAccidental>)oList.ItemsSource;
  133. if (oCollection == null)
  134. {
  135. MessageBox.Show("???????? ????", "?????????????? ?????????");
  136. return;
  137. }
  138. var oNewLayerAccidental = new LayerAccidental();
  139. oCollection.Add(oNewLayerAccidental);
  140. m_oLayerAccidentalBuilder.BuildElement(oNewLayerAccidental, new ElementBuiltCallBack<LayerAccidental>(UpdateListBox), wLayerAccidentalsView);
  141. }
  142. private void wLayerAccidentalsView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  143. {
  144. var oList = sender as ListBox;
  145. foreach (var x in oList.SelectedItems.Cast<LayerAccidental>())
  146. {
  147. m_oLayerAccidentalBuilder.BuildElement(x, new ElementBuiltCallBack<LayerAccidental>(UpdateListBox), wLayerAccidentalsView);
  148. }
  149. }
  150. private void Button_Click_2(object sender, RoutedEventArgs e)
  151. {
  152. var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
  153. if (oCollection == null)
  154. {
  155. MessageBox.Show("???????? ????", "?????????????? ?????????");
  156. return;
  157. }
  158. var oNewChord = new Chord();
  159. oCollection.Add(oNewChord);
  160. m_oChordBuilder.BuildElement(oNewChord, new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
  161. }
  162. private void wMusicalCollectionView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  163. {
  164. var oListBox = sender as ListBox;
  165. foreach (var x in oListBox.SelectedItems.Cast<MusicalElement>())
  166. {
  167. switch (x.Type)
  168. {
  169. case MusicalElementType.Chord:
  170. m_oChordBuilder.BuildElement(x as Chord,
  171. new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
  172. break;
  173. case MusicalElementType.GradualChange:
  174. m_oGradualChangeBuilder.BuildElement(x as GradualChange,
  175. new ElementBuiltCallBack<GradualChange>(UpdateListBox), wMusicalCollectionView);
  176. break;
  177. case MusicalElementType.RelativeLoudness:
  178. m_oRelativeLoudnessBuilder.BuildElement(x as RelativeLoudness,
  179. new ElementBuiltCallBack<RelativeLoudness>(UpdateListBox), wMusicalCollectionView);
  180. break;
  181. }
  182. }
  183. }
  184. private void deleteLayerButton_Click(object sender, RoutedEventArgs e)
  185. {
  186. foreach (var x in LayersView.SelectedItems.Cast<LayerInfo>().ToList())
  187. {
  188. m_oLayersInfo.Remove(x);
  189. }
  190. InitializeLayers();
  191. }
  192. protected void UpdateListBox(object v_oElement, object v_oContext)
  193. {
  194. var oList = v_oContext as ListBox;
  195. int iTmp = LayersView.SelectedIndex;
  196. LayersView.SelectedItem = null;
  197. LayersView.SelectedIndex = iTmp;
  198. }
  199. private void Button_Click_3(object sender, RoutedEventArgs e)
  200. {
  201. var oCollection = (LayerInfo)LayersView.SelectedItem;
  202. if (oCollection == null)
  203. {
  204. MessageBox.Show("???????? ????", "?????????????? ?????????");
  205. return;
  206. }
  207. foreach (var x in wLayerAccidentalsView.SelectedItems.Cast<LayerAccidental>().ToList())
  208. {
  209. oCollection.LayerAccidentals.Remove(x);
  210. }
  211. UpdateListBox(null, wLayerAccidentalsView);
  212. }
  213. private void addMusElementButton_MouseEnter(object sender, MouseEventArgs e)
  214. {
  215. }
  216. private void addMusElementButton_MouseDown(object sender, MouseButtonEventArgs e)
  217. {
  218. }
  219. private void deleteMusicElementButton_Click(object sender, RoutedEventArgs e)
  220. {
  221. var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
  222. if (oCollection == null)
  223. {
  224. MessageBox.Show("???????? ????", "?????????????? ?????????");
  225. return;
  226. }
  227. foreach(var x in wMusicalCollectionView.SelectedItems.Cast<MusicalElement>().ToList())
  228. {
  229. oCollection.Remove(x);
  230. }
  231. UpdateListBox(null, LayersView);
  232. }
  233. private void addChordButton_Click(object sender, RoutedEventArgs e)
  234. {
  235. var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
  236. if (oCollection == null)
  237. {
  238. MessageBox.Show("???????? ????", "?????????????? ?????????");
  239. return;
  240. }
  241. var oNewChord = new Chord();
  242. oCollection.Add(oNewChord);
  243. m_oChordBuilder.BuildElement(oNewChord, new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
  244. }
  245. private void addRelativeLoudnessButton_Click(object sender, RoutedEventArgs e)
  246. {
  247. var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
  248. if (oCollection == null)
  249. {
  250. MessageBox.Show("???????? ????", "?????????????? ?????????");
  251. return;
  252. }
  253. var oNewRelativeLoudness = new RelativeLoudness();
  254. oCollection.Add(oNewRelativeLoudness);
  255. m_oRelativeLoudnessBuilder.BuildElement(oNewRelativeLoudness, new ElementBuiltCallBack<RelativeLoudness>(UpdateListBox), wMusicalCollectionView);
  256. }
  257. private void addGradualChangeButton_Click(object sender, RoutedEventArgs e)
  258. {
  259. var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
  260. if (oCollection == null)
  261. {
  262. MessageBox.Show("???????? ????", "?????????????? ?????????");
  263. return;
  264. }
  265. var oNewGradualChange = new GradualChange();
  266. oCollection.Add(oNewGradualChange);
  267. m_oGradualChangeBuilder.BuildElement(oNewGradualChange, new ElementBuiltCallBack<GradualChange>(UpdateListBox), wMusicalCollectionView);
  268. }
  269. private void wMusicalCollectionView_Initialized(object sender, EventArgs e)
  270. {
  271. }
  272. }
  273. }