// Copyright (c) 2010, Peter Smith
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// Neither the name of the Author nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
namespace RadioFeatureSelection
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public partial class RadioInterfaceOptions : UserControl
{
#region Fields
private PS.FrequencySpeakerLocationTransmitterReceiverActiveClass frequencyAndSpeakerLocation = new PS.FrequencySpeakerLocationTransmitterReceiverActiveClass();
#endregion Fields
#region Constructors
public RadioInterfaceOptions()
{
InitializeComponent();
}
#endregion Constructors
#region Events
[Category("Radio Options")]
public event EventHandler<RadioOptionEvents> OnRadioOptionSetupComplete;
#endregion Events
#region Methods
public void FillFormFields(PS.FrequencySpeakerLocationTransmitterReceiverActiveClass frequencyAndSpeakerLocation)
{
SetFrequency(frequencyAndSpeakerLocation.Frequency);
SetSpeakerLocation(frequencyAndSpeakerLocation.SpeakerLocation);
SetActiveTransmittersAndReceivers(frequencyAndSpeakerLocation.ActiveTransmitter, frequencyAndSpeakerLocation.ActiveReceiver);
this.frequencyAndSpeakerLocation.UniqueID = frequencyAndSpeakerLocation.UniqueID;
}
private void button_Apply_Click(object sender, EventArgs e)
{
ulong frequency = 0;
if (this.textBox_Frequency.Text.Length > 0)
{
UInt64.TryParse(this.textBox_Frequency.Text, out frequency);
}
if (frequency == 0 && (this.checkBox_Receive.Checked == true | this.checkBox_TransmitReceive.Checked == true))
{
MessageBox.Show("Frequency is 0 therefore you can not have either Transmit or Receive checked");
return;
}
frequencyAndSpeakerLocation.Frequency = frequency;
frequencyAndSpeakerLocation.SpeakerLocation = SpeakerChoice();
if (this.checkBox_Receive.Checked == true)
this.frequencyAndSpeakerLocation.ActiveReceiver = true;
if (this.checkBox_TransmitReceive.Checked == true)
this.frequencyAndSpeakerLocation.ActiveTransmitter = true;
RadioOptionCompletedEvent(this.frequencyAndSpeakerLocation, DialogResult.OK);
}
private void button_Cancel_Click(object sender, EventArgs e)
{
RadioOptionCompletedEvent(this.frequencyAndSpeakerLocation, DialogResult.Cancel);
}
private void checkBox_Receive_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox_Receive.Checked == true)
{
//Only one checkbox can be checked
this.checkBox_TransmitReceive.Checked = false;
}
}
private void checkBox_TransmitReceive_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox_TransmitReceive.Checked == true)
{
//Only one checkbox can be checked
this.checkBox_Receive.Checked = false;
}
}
private void RadioOptionCompletedEvent(PS.FrequencySpeakerLocationTransmitterReceiverActiveClass frequencyAndSpeakerLocation, DialogResult dialogResult)
{
EventHandler<RadioOptionEvents> temp = OnRadioOptionSetupComplete;
if (temp != null)
temp(this, new RadioOptionEvents(frequencyAndSpeakerLocation, dialogResult));
}
private void SetActiveTransmittersAndReceivers(bool activeTransmitter, bool activeReceiver)
{
if (activeTransmitter == true)
this.checkBox_TransmitReceive.Checked = true;
else if (activeReceiver == true)
this.checkBox_Receive.Checked = true;
}
private void SetFrequency(ulong? frequency)
{
this.textBox_Frequency.Text = frequency.ToString();
}
private void SetSpeakerLocation(AudioOUT.PlayAudio.SpeakerLocation speakerLocation)
{
switch (speakerLocation)
{
case AudioOUT.PlayAudio.SpeakerLocation.Left:
this.radioButton_LeftEar.Checked = true;
break;
case AudioOUT.PlayAudio.SpeakerLocation.Right:
this.radioButton_RightEar.Checked = true;
break;
case AudioOUT.PlayAudio.SpeakerLocation.LeftRight:
this.radioButton_BothEars.Checked = true;
break;
default:
break;
}
}
/// <summary>
/// Determine which ear the sound should play to.
/// </summary>
private AudioOUT.PlayAudio.SpeakerLocation SpeakerChoice()
{
AudioOUT.PlayAudio.SpeakerLocation speakerLocation = AudioOUT.PlayAudio.SpeakerLocation.LeftRight;
if (this.radioButton_BothEars.Checked == true)
{
speakerLocation = AudioOUT.PlayAudio.SpeakerLocation.LeftRight;
}
if (this.radioButton_LeftEar.Checked == true)
{
speakerLocation = AudioOUT.PlayAudio.SpeakerLocation.Left;
}
if (this.radioButton_RightEar.Checked == true)
{
speakerLocation = AudioOUT.PlayAudio.SpeakerLocation.Right;
}
return speakerLocation;
}
#endregion Methods
}
public class RadioOptionEvents : EventArgs
{
#region Fields
private DialogResult dialogResult;
private PS.FrequencySpeakerLocationTransmitterReceiverActiveClass frequencyAndSpeakerLocation = new PS.FrequencySpeakerLocationTransmitterReceiverActiveClass();
#endregion Fields
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="MyEventArgs"/> class.
/// </summary>
/// <param name="messageData">The message data.</param>
public RadioOptionEvents(PS.FrequencySpeakerLocationTransmitterReceiverActiveClass frequencyAndSpeakerLocation, DialogResult dialogResult)
{
this.frequencyAndSpeakerLocation = frequencyAndSpeakerLocation;
this.dialogResult = dialogResult;
}
#endregion Constructors
#region Properties
public DialogResult DialogResult
{
get { return dialogResult; }
}
/// <summary>
/// Frequency, speaker location, and if active Transmitter or Receiver
/// </summary>
/// <value>Class representing values</value>
public PS.FrequencySpeakerLocationTransmitterReceiverActiveClass FrequencyAndSpeakerLocation
{
get { return frequencyAndSpeakerLocation; }
set { frequencyAndSpeakerLocation = value; }
}
#endregion Properties
}
}