/Programming/Labs/4sem/ISP/MusicSheetEditor/Benko.MusicSheetEditor.GUI/Windows/EditSheetWindow.xaml.cs
C# | 325 lines | 260 code | 52 blank | 13 comment | 20 complexity | 7cd56fc97842a309c156b661a0b9ff42 MD5 | raw file
Possible License(s): AGPL-1.0, CC0-1.0
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using System.Collections.ObjectModel;
-
- using Benko.MusicSheetEditor.BLL;
- using Benko.MusicSheetEditor.Global;
-
- namespace Benko.MusicSheetEditor.GUI
- {
- /// <summary>
- /// Interaction logic for EditSheetWindow.xaml
- /// </summary>
- public partial class EditSheetWindow : Window, IEditElementWindow<Sheet>
- {
-
- public Sheet Element { get { return m_oWorkingSheet; } }
- public int Handle { get; internal set; }
-
- MusicSheetsManager m_oMSManager;
- Sheet m_oWorkingSheet;
- List<Layer> m_oWorkingLayers;
- ObservableCollection<LayerInfo> m_oLayersInfo;
-
-
- LayerBuilder m_oLayerBuilder;
- LayerAccidentalBuilder m_oLayerAccidentalBuilder;
- RelativeLoudnessBuilder m_oRelativeLoudnessBuilder;
- GradualChangeBuilder m_oGradualChangeBuilder;
- ChordBuilder m_oChordBuilder;
-
- public EditSheetWindow()
- {
- InitializeComponent();
- m_oMSManager = MusicSheetsManager.Instance;
-
- m_oLayerAccidentalBuilder = new LayerAccidentalBuilder(this);
- m_oLayerBuilder = new LayerBuilder(this);
- m_oRelativeLoudnessBuilder = new RelativeLoudnessBuilder(this);
- m_oGradualChangeBuilder = new GradualChangeBuilder(this);
- m_oChordBuilder = new ChordBuilder(this);
- }
-
-
- public EditSheetWindow(Sheet v_oSheet, int v_iHandle)
- : this()
- {
- m_oWorkingSheet = v_oSheet;
- Handle = v_iHandle;
- InitializeLayers();
- }
-
- private void InitializeLayers()
- {
- m_oWorkingLayers = m_oWorkingSheet.GetAllLayers();
- m_oLayersInfo = new ObservableCollection<LayerInfo>(m_oWorkingLayers.Select(x => new LayerInfo(x)));
- m_oLayersInfo.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(m_oLayerInfos_CollectionChanged);
- LayersView.ItemsSource = m_oLayersInfo;
- }
-
- void l_SourceUpdated(object sender, DataTransferEventArgs e)
- {
- //var list = (ListBox)sender;
- }
-
- void m_oLayerInfos_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
- switch (e.Action)
- {
- case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
- foreach (var x in e.NewItems.Cast<LayerInfo>())
- {
- m_oWorkingSheet.AddLayer(x.WorkingLayer);
- }
- break;
- case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
- foreach (var x in e.OldItems.Cast<LayerInfo>())
- {
- m_oWorkingSheet.DeleteLayer(x.WorkingLayer);
- }
- break;
- }
- }
-
- private void InitializeMusicalElements()
- {
- //MusicalCollectionView.ItemsSource = m_oLayerInfos[0].m_oMusicalCollection;
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- var oLayer = new LayerInfo();
- m_oLayersInfo.Add(oLayer);
- m_oLayerBuilder.BuildElement(oLayer.WorkingLayer, new ElementBuiltCallBack<Layer>(LayerBuiltCallBack), null);
- }
-
- private void LayerBuiltCallBack(Layer v_oBuiltLayer, object v_oContext)
- {
- int a = 3;
- }
-
- private void LayersView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- var oList = sender as ListBox;
- foreach (var x in oList.SelectedItems.Cast<LayerInfo>().Select(x => x.WorkingLayer))
- {
- m_oLayerBuilder.BuildElement(x, null, null);
- }
- }
-
- private void LayersView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var list = (ListBox) sender;
- var removeStoryBoard = (Storyboard)FindResource("RemoveItemStoryboard");
- ListBoxItem l;
-
- //ScaleTransform s;
- //s.ScaleX
-
- // l.Loaded += new RoutedEventHandler(l_Loaded);
- //l.Initialized += new EventHandler(l_Initialized);
- //foreach (var item in list)
- //{
- // //item.BeginStoryboard(removeStoryBoard);
- //}
- }
-
-
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- var oRes = MessageBox.Show("????????? ??????????", "?????????????? ?????????", MessageBoxButton.YesNoCancel);
-
- if (oRes == MessageBoxResult.Yes)
- {
- m_oWorkingSheet.SaveAllChanges();
- }
- if (oRes == MessageBoxResult.Cancel)
- {
- e.Cancel = true;
- }
- }
-
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- var oList = wLayerAccidentalsView;
- var oCollection = (ObservableCollection<LayerAccidental>)oList.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
- var oNewLayerAccidental = new LayerAccidental();
- oCollection.Add(oNewLayerAccidental);
- m_oLayerAccidentalBuilder.BuildElement(oNewLayerAccidental, new ElementBuiltCallBack<LayerAccidental>(UpdateListBox), wLayerAccidentalsView);
- }
-
- private void wLayerAccidentalsView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- var oList = sender as ListBox;
- foreach (var x in oList.SelectedItems.Cast<LayerAccidental>())
- {
- m_oLayerAccidentalBuilder.BuildElement(x, new ElementBuiltCallBack<LayerAccidental>(UpdateListBox), wLayerAccidentalsView);
- }
- }
-
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
-
- var oNewChord = new Chord();
- oCollection.Add(oNewChord);
- m_oChordBuilder.BuildElement(oNewChord, new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
- }
-
- private void wMusicalCollectionView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- var oListBox = sender as ListBox;
- foreach (var x in oListBox.SelectedItems.Cast<MusicalElement>())
- {
- switch (x.Type)
- {
- case MusicalElementType.Chord:
- m_oChordBuilder.BuildElement(x as Chord,
- new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
- break;
-
- case MusicalElementType.GradualChange:
- m_oGradualChangeBuilder.BuildElement(x as GradualChange,
- new ElementBuiltCallBack<GradualChange>(UpdateListBox), wMusicalCollectionView);
- break;
-
- case MusicalElementType.RelativeLoudness:
- m_oRelativeLoudnessBuilder.BuildElement(x as RelativeLoudness,
- new ElementBuiltCallBack<RelativeLoudness>(UpdateListBox), wMusicalCollectionView);
- break;
- }
- }
-
- }
-
- private void deleteLayerButton_Click(object sender, RoutedEventArgs e)
- {
- foreach (var x in LayersView.SelectedItems.Cast<LayerInfo>().ToList())
- {
- m_oLayersInfo.Remove(x);
- }
- InitializeLayers();
- }
-
- protected void UpdateListBox(object v_oElement, object v_oContext)
- {
- var oList = v_oContext as ListBox;
- int iTmp = LayersView.SelectedIndex;
- LayersView.SelectedItem = null;
- LayersView.SelectedIndex = iTmp;
- }
-
- private void Button_Click_3(object sender, RoutedEventArgs e)
- {
- var oCollection = (LayerInfo)LayersView.SelectedItem;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
- foreach (var x in wLayerAccidentalsView.SelectedItems.Cast<LayerAccidental>().ToList())
- {
- oCollection.LayerAccidentals.Remove(x);
- }
- UpdateListBox(null, wLayerAccidentalsView);
- }
-
- private void addMusElementButton_MouseEnter(object sender, MouseEventArgs e)
- {
-
- }
-
- private void addMusElementButton_MouseDown(object sender, MouseButtonEventArgs e)
- {
-
- }
-
- private void deleteMusicElementButton_Click(object sender, RoutedEventArgs e)
- {
- var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
- foreach(var x in wMusicalCollectionView.SelectedItems.Cast<MusicalElement>().ToList())
- {
- oCollection.Remove(x);
- }
- UpdateListBox(null, LayersView);
- }
-
- private void addChordButton_Click(object sender, RoutedEventArgs e)
- {
- var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
-
- var oNewChord = new Chord();
- oCollection.Add(oNewChord);
- m_oChordBuilder.BuildElement(oNewChord, new ElementBuiltCallBack<Chord>(UpdateListBox), wMusicalCollectionView);
- }
-
- private void addRelativeLoudnessButton_Click(object sender, RoutedEventArgs e)
- {
- var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
-
- var oNewRelativeLoudness = new RelativeLoudness();
- oCollection.Add(oNewRelativeLoudness);
- m_oRelativeLoudnessBuilder.BuildElement(oNewRelativeLoudness, new ElementBuiltCallBack<RelativeLoudness>(UpdateListBox), wMusicalCollectionView);
-
- }
-
- private void addGradualChangeButton_Click(object sender, RoutedEventArgs e)
- {
- var oCollection = (ObservableCollection<MusicalElement>)wMusicalCollectionView.ItemsSource;
- if (oCollection == null)
- {
- MessageBox.Show("???????? ????", "?????????????? ?????????");
- return;
- }
-
- var oNewGradualChange = new GradualChange();
- oCollection.Add(oNewGradualChange);
- m_oGradualChangeBuilder.BuildElement(oNewGradualChange, new ElementBuiltCallBack<GradualChange>(UpdateListBox), wMusicalCollectionView);
- }
-
- private void wMusicalCollectionView_Initialized(object sender, EventArgs e)
- {
-
- }
-
- }
- }
-
-
-