/
Form1.cs
289 lines (232 loc) · 10.1 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using WMPLib;
namespace DesignPatternObserver_Animorphe
{
public partial class Form1 : Form
{
public string AppPath = Application.StartupPath;
//Instanciation du classe Mediaplayer pour l'alarme
private WMPLib.WindowsMediaPlayer mplayer = new WMPLib.WindowsMediaPlayer();
private WMPLib.WindowsMediaPlayer playerTete = new WMPLib.WindowsMediaPlayer();
private WMPLib.WindowsMediaPlayer playerCorps = new WMPLib.WindowsMediaPlayer();
private WMPLib.WindowsMediaPlayer playerPattes = new WMPLib.WindowsMediaPlayer();
#region Attributs de la Form1
private SujetConcret monSujet;
private ObservateurConcret monObservateurLV;
/// <summary>
/// Getter & setter pour régler des problèmes d'encapsulation dans l'update().
/// </summary>
public PictureBox PicTete
{
get { return picTete; }
set { picTete = value; }
}
/// <summary>
/// Getter & setter pour régler des problèmes d'encapsulation dans l'update().
/// </summary>
public PictureBox PicCorps
{
get { return picCorps; }
set { picCorps = value; }
}
/// <summary>
/// Getter & setter pour régler des problèmes d'encapsulation dans l'update().
/// </summary>
public PictureBox PicPattes
{
get { return picPattes; }
set { picPattes = value; }
}
#endregion
#region Constructeur
/// <summary>
/// Constructeur de la Form1
/// </summary>
public Form1()
{
InitializeComponent();
// ----------Creation du sujet concret------------
monSujet = new SujetConcret();
monObservateurLV = new ObservateurConcret(monSujet);
monSujet.Attach(monObservateurLV);
}
#endregion
#region Methodes
#region btn Start / Générér
/// <summary>
/// Evenement btn_Start_Click qui permet la génération de l'animorphe
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Start_Click(object sender, EventArgs e)
{
//Task maTache = new Task(GenererDesAnimorphes);
//maTache.Start();
//Instanciation de la Class Anyorphe
Animorphe hybride = new Animorphe();
//Mise en place de l'abonnement à l'observer et du notify()
monSujet.AjouterAnimorphe(hybride, lstViewAnimaux, this);
//Affichage les labels dans les groupbox de la form1
lbl_TeteNom.Text = hybride.Tete;
lbl_CorpsNom.Text = hybride.Corps;
lbl_PattesNom.Text = hybride.Pattes;
lbl_AnimorpheNom.Text = hybride.Nom;
}
#endregion
#region DoubleClick sur une ligne de la listView
/// <summary>
/// Cet Evenement MouseDoubleClick permet, lorsque l'on selectionne par DoubleCick d'une ligne dans la listview "lstViewAnimaux",
/// d'afficher dans les pictureBox les images de l'animorphe en question.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lstViewAnimaux_MouseDoubleClick(object sender, MouseEventArgs e)
{
//recherche de l'item selectionné dans la ListView dans List<Animorphe>
int indexSelected = monSujet.MesAnimorphes.FindIndex(x => x.Nom == lstViewAnimaux.SelectedItems[0].SubItems[0].Text);
Animorphe SeletedAnimal = monSujet.MesAnimorphes[indexSelected];
//réaffectation des textes des Labels de la form1
lbl_AnimorpheNom.Text = SeletedAnimal.Nom;
lbl_TeteNom.Text = SeletedAnimal.Tete;
lbl_CorpsNom.Text = SeletedAnimal.Corps;
lbl_PattesNom.Text = SeletedAnimal.Pattes;
//Affectation des images dans les pictureBox et stretching des images
Object oT = Properties.Resources.ResourceManager.GetObject(SeletedAnimal.Tete + "Tete");
picTete.Image = (Image)oT;
picTete.SizeMode = PictureBoxSizeMode.StretchImage;
Object oC = Properties.Resources.ResourceManager.GetObject(SeletedAnimal.Corps + "Corps");
picCorps.Image = (Image)oC;
picCorps.SizeMode = PictureBoxSizeMode.StretchImage;
Object oP = Properties.Resources.ResourceManager.GetObject(SeletedAnimal.Pattes + "Pattes");
picPattes.Image = (Image)oP;
picPattes.SizeMode = PictureBoxSizeMode.StretchImage;
//Activation du son
if (chkBox_SonActivation.Checked == true)
{
chkBox_Son.Enabled = true;
//Selection du Mode Sonore
//Son Synchrone /Simultané
if (chkBox_Son.Checked == true)
{
chkBox_Son.Text = @"Mode Sonore : Synchrone";
playerTete.URL = AppPath +"\\Sons\\"+ SeletedAnimal.Tete + "Tete.mp3";
playerTete.controls.play();
//Thread.Sleep(500);
playerCorps.URL = AppPath +"\\Sons\\"+ SeletedAnimal.Corps + "Corps.mp3";
playerCorps.controls.play();
//Thread.Sleep(500);
playerPattes.URL = AppPath + "\\Sons\\" + SeletedAnimal.Pattes + "Pattes.mp3";
playerPattes.controls.play();
}
//Son Séquencé en playlist
else
{
chkBox_Son.Text = @"Mode Sonore : Séquencé";
WMPLib.IWMPPlaylist playlist = mplayer.playlistCollection.newPlaylist("myplaylist");
WMPLib.IWMPMedia media;
media = mplayer.newMedia(AppPath + "\\Sons\\" + SeletedAnimal.Tete + "Tete.mp3");
playlist.appendItem(media);
media = mplayer.newMedia(AppPath + "\\Sons\\" + SeletedAnimal.Corps + "Corps.mp3");
playlist.appendItem(media);
media = mplayer.newMedia(AppPath + "\\Sons\\" + SeletedAnimal.Pattes + "Pattes.mp3");
playlist.appendItem(media);
mplayer.currentPlaylist = playlist;
mplayer.controls.play();
}
}
}
#endregion
#region btn Attach & Detach
/// <summary>
/// Attacher un observer au sujet observé
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Attach_Click(object sender, EventArgs e)
{
monSujet.Attach(monObservateurLV);
//Mise à jour complète de la liste des animorphes créés et ajouter dans la liste
lstViewAnimaux.Items.Clear();
foreach (var item in monSujet.MesAnimorphes)
{
int indexAnimorphe = monSujet.MesAnimorphes.IndexOf(item);
//Animorphe temp = monSujet.MesAnimorphes[indexAnimorphe];
ListViewItem lvi = new ListViewItem(monSujet.MesAnimorphes[indexAnimorphe].Nom);
lvi.SubItems.Add(monSujet.MesAnimorphes[indexAnimorphe].Tete);
lvi.SubItems.Add(monSujet.MesAnimorphes[indexAnimorphe].Corps);
lvi.SubItems.Add(monSujet.MesAnimorphes[indexAnimorphe].Pattes);
//Afficher le lvi dans la ListView "lstViewAnimaux"
lstViewAnimaux.Items.Add(lvi);
}
btn_Attach.Enabled = false;
btn_Detach.Enabled = true;
MessageBox.Show("Votre Abonnent a bien été renouvelé. Félicitations !\nLa mise à jour s'est bien déroulée", "Avertissement sur Abonnement");
}
/// <summary>
/// Detacher un observateur di sujet observé
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Detach_Click(object sender, EventArgs e)
{
monSujet.Detach(monObservateurLV);
btn_Attach.Enabled = true;
btn_Detach.Enabled = false;
MessageBox.Show("Votre Abonnent a bien été résilié. Dommage !\nAu revoir !!!", "Avertissement sur Abonnement");
}
#endregion
#region Checked Box status event
/// <summary>
/// Evenment de modification de la checked box Mode Son
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void chkBx_Son_CheckedChanged(object sender, EventArgs e)
{
if (chkBox_Son.Checked)
{
chkBox_Son.Text = @"Mode Sonore : Synchrone";
}
else
{
chkBox_Son.Text = @"Mode Sonore : Séquencé";
}
}
/// <summary>
/// Evenment de modification de la checked box Activation Son
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void chkBox_SonActivation_CheckedChanged(object sender, EventArgs e)
{
if (chkBox_SonActivation.Checked)
{
chkBox_Son.Enabled = true;
}
else
{
chkBox_Son.Enabled = false;
}
}
#endregion
//loop -> net used anymore
//private void GenererDesAnimorphes()
//{
// do
// {
// Animorphe hybride = new Animorphe();
// monSujet.AjouterAnimorphe(hybride, lstViewAnimaux, this);
// //Affichage les labels dans les groupbox de la form1
// lbl_TeteNom.Text = hybride.Tete;
// lbl_CorpsNom.Text = hybride.Corps;
// lbl_PattesNom.Text = hybride.Pattes;
// lbl_AnimorpheNom.Text = hybride.Nom;
// Thread.Sleep(2000);
// } while (true);
//}
#endregion
}
}