/[cits3200i]/branches/gps-running-clean-r116/HighScorePlugin/Source/HighScoreSettingPageControl.cs


UCC Code Repository

Contents of /branches/gps-running-clean-r116/HighScorePlugin/Source/HighScoreSettingPageControl.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations) (download)
Sun Sep 5 15:48:34 2010 UTC (11 years, 2 months ago) by rvvs89
File size: 18227 byte(s)
Branching a local copy of the HEAD revision of the gps-running project on Google Code.
We will probably have to use this project as a template for our own plugins if we want to support SportTracks 2.1.
1 /*
2 Copyright (C) 2007, 2008 Kristian Bisgaard Lassen
3 Copyright (C) 2010 Kristian Helkjaer Lassen
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 using System;
20 using System.Collections.Generic;
21 using System.ComponentModel;
22 using System.Drawing;
23 using System.Data;
24 using System.Text;
25 using System.Windows.Forms;
26 using ZoneFiveSoftware.Common.Data.Fitness;
27 using ZoneFiveSoftware.Common.Data.Measurement;
28 using System.Diagnostics;
29 using ZoneFiveSoftware.Common.Visuals;
30 using ZoneFiveSoftware.Common.Visuals.Fitness;
31 using ZoneFiveSoftware.Common.Data.GPS;
32 using ZoneFiveSoftware.Common.Data;
33 using System.Collections;
34 using System.IO;
35 using System.Xml;
36 using GpsRunningPlugin.Properties;
37 using GpsRunningPlugin.Util;
38
39 namespace GpsRunningPlugin.Source
40 {
41 public partial class HighScoreSettingPageControl : UserControl
42 {
43 IList<IList<double>> speedZoneIndex;
44
45 public HighScoreSettingPageControl()
46 {
47 InitializeComponent();
48 paceTypeBox.DropDownStyle = ComboBoxStyle.DropDownList;
49 paceTypeBox.SelectedIndexChanged += new EventHandler(paceTypeBox_SelectedIndexChanged);
50 Plugin.GetApplication().SystemPreferences.PropertyChanged += new PropertyChangedEventHandler(HighScoreSettingPageControl_PropertyChanged);
51 }
52
53 private void correctUI(IList<Control> comp)
54 {
55 Control prev = null;
56 foreach (Control c in comp)
57 {
58 if (prev != null)
59 {
60 c.Location = new Point(prev.Location.X + prev.Size.Width,
61 prev.Location.Y);
62 }
63 prev = c;
64 }
65 }
66
67 public void ThemeChanged(ZoneFiveSoftware.Common.Visuals.ITheme visualTheme)
68 {
69 distanceInputBox.ThemeChanged(visualTheme);
70 timeInputBox.ThemeChanged(visualTheme);
71 elevationInputBox.ThemeChanged(visualTheme);
72 maxPulseBox.ThemeChanged(visualTheme);
73 minPulseBox.ThemeChanged(visualTheme);
74 }
75 public void UICultureChanged(System.Globalization.CultureInfo culture)
76 {
77 resetSettings.Text = StringResources.ResetAllSettings;
78 linkLabel1.Text = Resources.Webpage;
79 ignoreManualBox.Text = Resources.IgnoreManualEnteredBox;
80 addDistance.Text = "<-- " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionAdd;
81 removeDistance.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionRemove + " -->";
82 resetDistances.Text = StringResources.Reset;
83 addTime.Text = "<-- " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionAdd;
84 removeTime.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionRemove + " -->";
85 resetTimes.Text = StringResources.Reset;
86 addElevation.Text = "<-- " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionAdd;
87 removeElevation.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionRemove + " -->";
88 resetElevations.Text = StringResources.Reset;
89 addPulse.Text = "<-- " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionAdd;
90 removePulse.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionRemove + " -->";
91 resetPulseZone.Text = StringResources.Reset;
92 addPace.Text = "<-- " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionAdd;
93 removePace.Text = ZoneFiveSoftware.Common.Visuals.CommonResources.Text.ActionRemove + " -->";
94 resetPaceZone.Text = StringResources.Reset;
95 label1.Text = UnitUtil.HeartRate.LabelAbbr + " " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelFrom.ToLower();
96 label2.Text = UnitUtil.HeartRate.LabelAbbr + " " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelTo.ToLower();
97 label4.Text = "(" + StringResources.TimeFormat + ")";
98
99 reset();
100 }
101
102 private void reset()
103 {
104 groupBox1.Text = UnitUtil.Distance.LabelAxis;
105 groupBox2.Text = UnitUtil.Time.LabelAxis;
106 groupBox3.Text = UnitUtil.Elevation.LabelAxis;
107 groupBox4.Text = StringResources.HRZone + UnitUtil.HeartRate.LabelAbbr2;
108 groupBox5.Text = StringResources.SpeedZone;
109
110 String paceType = UnitUtil.Pace.Label;
111 paceTypeBox.Items.Add(paceType);
112 paceTypeBox.Items.Add(UnitUtil.Speed.LabelAbbr);
113 paceTypeBox.SelectedItem = paceType;
114 setPaceLabel();
115 distanceLabel.Text = UnitUtil.Distance.LabelAbbr;
116 correctUI(new Control[] { distanceInputBox, distanceLabel });
117 elevationLabel.Text = UnitUtil.Elevation.LabelAbbr;
118 correctUI(new Control[] { elevationInputBox, elevationLabel });
119 populateLists();
120 ignoreManualBox.Checked = Settings.IgnoreManualData;
121 }
122
123 void HighScoreSettingPageControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
124 {
125 if (e.PropertyName.Equals("DistanceUnits")||e.PropertyName.Equals("ElevationUnits"))
126 {
127 reset();
128 }
129 }
130
131 void paceTypeBox_SelectedIndexChanged(object sender, EventArgs e)
132 {
133 setPaceLabel();
134 populateSpeedList();
135 }
136
137 private void setPaceLabel()
138 {
139 bool isPace = UnitUtil.Pace.isLabelPace((String)paceTypeBox.SelectedItem);
140 groupBox5.Text = StringResources.SpeedZone + UnitUtil.PaceOrSpeed.LabelAbbr2(isPace);
141 paceLabelFrom.Text = UnitUtil.PaceOrSpeed.LabelAbbr(isPace) + " " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelFrom.ToLower();
142 paceLabelTo.Text = UnitUtil.PaceOrSpeed.LabelAbbr(isPace) + " " + ZoneFiveSoftware.Common.Visuals.CommonResources.Text.LabelTo.ToLower();
143
144 }
145
146 private void populateLists()
147 {
148 populateDistanceList();
149 populateTimeList();
150 populateElevationList();
151 populatePulseList();
152 populateSpeedList();
153 }
154
155 private void populateSpeedList()
156 {
157 speedZoneIndex = new List<IList<double>>();
158 speedBox.Items.Clear();
159 foreach (double min in Settings.speedZones.Keys)
160 foreach (double max in Settings.speedZones[min].Keys)
161 {
162 string from, to;
163 bool isPace = UnitUtil.Pace.isLabelPace((String)paceTypeBox.SelectedItem);
164 if (isPace)
165 {
166 from = UnitUtil.Pace.ToString(min);
167 to = UnitUtil.Pace.ToString(max);
168 }
169 else
170 {
171 from = UnitUtil.Speed.ToString(min);
172 to = UnitUtil.Speed.ToString(max);
173 }
174 speedBox.Items.Add(String.Format("{0} - {1}", from, to));
175 speedZoneIndex.Add(new double[] { min, max });
176 }
177 }
178
179 private void populatePulseList()
180 {
181 pulseBox.Items.Clear();
182 foreach (double min in Settings.pulseZones.Keys)
183 {
184 foreach (double max in Settings.pulseZones[min].Keys)
185 {
186 pulseBox.Items.Add(String.Format("{0} - {1}", min, max));
187 }
188 }
189 }
190
191 private void populateTimeList()
192 {
193 timeBox.Items.Clear();
194 foreach (TimeSpan time in Settings.times.Values)
195 {
196
197 timeBox.Items.Add(String.Format("{0}:{1}:{2}", padFront(time.Hours), padFront(time.Minutes), padFront(time.Seconds)));
198 }
199 }
200
201 private String padFront(int p)
202 {
203 if (p < 10) return "0" + p;
204 else return p.ToString();
205 }
206
207 private void populateDistanceList()
208 {
209 distanceBox.Items.Clear();
210 foreach (double distance in Settings.distances.Keys)
211 {
212 distanceBox.Items.Add(UnitUtil.Distance.ToString(distance));
213 }
214 }
215
216 private void populateElevationList()
217 {
218 elevationBox.Items.Clear();
219 foreach (double elevation in Settings.elevations.Keys)
220 {
221 elevationBox.Items.Add(UnitUtil.Elevation.ToString(elevation));
222 }
223 }
224
225 private void addDistance_Click(object sender, EventArgs e)
226 {
227 try
228 {
229 double distance = UnitUtil.Distance.Parse(distanceInputBox.Text);
230 if (distance <= 0) { throw new Exception(); }
231 if (!Settings.distances.ContainsKey(distance))
232 {
233 Settings.distances.Add(distance, true);
234 populateDistanceList();
235 }
236 }
237 catch (Exception)
238 {
239 new WarningDialog(Resources.CannotAddToDistances);
240 }
241 }
242
243 private void removeDistance_Click(object sender, EventArgs e)
244 {
245 if (distanceBox.SelectedIndex >= 0)
246 {
247 Settings.distances.RemoveAt(distanceBox.SelectedIndex);
248 populateDistanceList();
249 }
250 }
251
252 private void addTime_Click(object sender, EventArgs e)
253 {
254 try
255 {
256 int seconds = (int)UnitUtil.Time.Parse(timeInputBox.Text);
257 if (seconds <= 0) { throw new Exception(); }
258 if (!Settings.times.ContainsKey(seconds))
259 {
260 Settings.times.Add(seconds, new TimeSpan(0, 0, seconds));
261 populateTimeList();
262 }
263 }
264 catch (Exception)
265 {
266 new WarningDialog(Resources.CannotAddToTimes);
267 }
268 }
269
270 private void removeTime_Click(object sender, EventArgs e)
271 {
272 if (timeBox.SelectedIndex >= 0)
273 {
274 Settings.times.RemoveAt(timeBox.SelectedIndex);
275 populateTimeList();
276 }
277 }
278
279 private void addElevation_Click(object sender, EventArgs e)
280 {
281 try
282 {
283 double elevation = UnitUtil.Elevation.Parse(elevationInputBox.Text);
284 if (elevation <= 0) { throw new Exception(); }
285 if (!Settings.elevations.ContainsKey(elevation))
286 {
287 Settings.elevations.Add(elevation, true);
288 populateElevationList();
289 }
290 }
291 catch (Exception)
292 {
293 new WarningDialog(Resources.CannotAddToElevations);
294 }
295 }
296
297 private void resetSettings_Click(object sender, EventArgs e)
298 {
299 dialog = new YesNoDialog(Resources.ResetAllSettingsWarning);
300 dialog.Disposed += new EventHandler(dialog_Disposed);
301 dialog.ShowDialog();
302 }
303
304 YesNoDialog dialog;
305
306 private void dialog_Disposed(object sender, EventArgs e)
307 {
308 if (dialog.answer)
309 {
310 Settings.defaults();
311 populateLists();
312 }
313 }
314
315 private void addPulse_Click(object sender, EventArgs e)
316 {
317 try
318 {
319 double min = UnitUtil.HeartRate.Parse(minPulseBox.Text);
320 double max = UnitUtil.HeartRate.Parse(maxPulseBox.Text);
321 if (min < 0 || max < 0 || min > max) throw new Exception();
322 Settings.addPulse(min, max);
323 populatePulseList();
324 }
325 catch (Exception)
326 {
327 new WarningDialog(Resources.CannotAddToHRZones);
328 }
329 }
330
331 private void removePulse_Click(object sender, EventArgs e)
332 {
333 if (pulseBox.SelectedIndex >= 0)
334 {
335 String[] values = ((String)pulseBox.SelectedItem).Split('-');
336 double min = UnitUtil.HeartRate.Parse(values[0]);
337 double max = UnitUtil.HeartRate.Parse(values[1]);
338 Settings.pulseZones[min].Remove(max);
339 populatePulseList();
340 }
341 }
342
343 private void addPace_Click(object sender, EventArgs e)
344 {
345 try
346 {
347 double min, max;
348 bool isPace = UnitUtil.Pace.isLabelPace((String)paceTypeBox.SelectedItem);
349 if (isPace)
350 {
351 min = UnitUtil.Pace.Parse(maxSpeedBox.Text);
352 max = UnitUtil.Pace.Parse(minSpeedBox.Text);
353 }
354 else
355 {
356 min = UnitUtil.Speed.Parse(minSpeedBox.Text);
357 max = UnitUtil.Speed.Parse(maxSpeedBox.Text);
358 }
359 if (min <= 0 || max <= 0 || max <= min) throw new Exception();
360 Settings.addSpeed(min, max);
361 populateSpeedList();
362 }
363 catch (Exception)
364 {
365 if (UnitUtil.Pace.isLabelPace((String)paceTypeBox.SelectedItem))
366 new WarningDialog(Resources.CannotAddToPaceZones);
367 else
368 new WarningDialog(Resources.CannotAddToSpeedZones);
369 }
370 }
371
372 private void removePace_Click(object sender, EventArgs e)
373 {
374 int index = speedBox.SelectedIndex;
375 if (index >= 0)
376 {
377 Settings.speedZones[speedZoneIndex[index][0]].Remove(speedZoneIndex[index][1]);
378 populateSpeedList();
379 }
380 }
381
382 private void resetDistances_Click(object sender, EventArgs e)
383 {
384 dialog = new YesNoDialog(Resources.ResetDistancesWarning);
385 dialog.Disposed += new EventHandler(dialog_Disposed_Distances);
386 dialog.ShowDialog();
387 }
388
389 void dialog_Disposed_Distances(object sender, EventArgs e)
390 {
391 if (dialog.answer)
392 {
393 Settings.resetDistances();
394 populateDistanceList();
395 }
396 }
397
398 private void resetTimes_Click(object sender, EventArgs e)
399 {
400 dialog = new YesNoDialog(Resources.ResetTimesWarning);
401 dialog.Disposed += new EventHandler(dialog_Disposed_times);
402 dialog.ShowDialog();
403 }
404
405 void dialog_Disposed_times(object sender, EventArgs e)
406 {
407 if (dialog.answer)
408 {
409 Settings.resetTimes();
410 populateTimeList();
411 }
412 }
413
414 private void resetElevations_Click(object sender, EventArgs e)
415 {
416 dialog = new YesNoDialog(Resources.ResetElevationsWarning);
417 dialog.Disposed += new EventHandler(dialog_Disposed_elevations);
418 dialog.ShowDialog();
419 }
420
421 void dialog_Disposed_elevations(object sender, EventArgs e)
422 {
423 if (dialog.answer)
424 {
425 Settings.resetElevations();
426 populateElevationList();
427 }
428 }
429
430 private void resetPulseZone_Click(object sender, EventArgs e)
431 {
432 dialog = new YesNoDialog(Resources.ResetHRZonesWarning);
433 dialog.Disposed += new EventHandler(dialog_Disposed_pulsezones);
434 dialog.ShowDialog();
435 }
436
437 void dialog_Disposed_pulsezones(object sender, EventArgs e)
438 {
439 if (dialog.answer)
440 {
441 Settings.resetPulseZones();
442 populatePulseList();
443 }
444 }
445
446 private void resetPaceZone_Click(object sender, EventArgs e)
447 {
448 dialog = new YesNoDialog(Resources.ResetPaceZonesWarning);
449 dialog.Disposed += new EventHandler(dialog_Disposed_pacezones);
450 dialog.ShowDialog();
451 }
452
453 void dialog_Disposed_pacezones(object sender, EventArgs e)
454 {
455 if (dialog.answer)
456 {
457 Settings.resetSpeedZones();
458 populateSpeedList();
459 }
460 }
461
462 private void removeElevation_Click(object sender, EventArgs e)
463 {
464 if (elevationBox.SelectedIndex >= 0)
465 {
466 Settings.elevations.RemoveAt(elevationBox.SelectedIndex);
467 populateElevationList();
468 }
469 }
470
471 private void ignoreManualBox_CheckedChanged(object sender, EventArgs e)
472 {
473 Settings.IgnoreManualData = ignoreManualBox.Checked;
474 }
475
476 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
477 {
478 System.Diagnostics.Process.Start(new ProcessStartInfo("IExplore",
479 "http://code.google.com/p/gps-running/wiki/HighScore"));
480 }
481
482 }
483 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26