private static double GetMaxValue(Itemkey key) { if (key == Itemkey.ScreenFontPoints) { return(UnitViewModel.MaxFontSizeValue); } return(UnitViewModel.MaxPercentageSizeValue); }
private static double GetMinValue(Itemkey key) { if (key == Itemkey.ScreenFontPoints) { return(MinFontSizeValue); } return(MinPercentageSizeValue); }
private double GetMinValue(Itemkey key) { if (key == Itemkey.ScreenFontPoints) { return(UnitViewModel.MinFontSizeValue); } return(UnitViewModel.MinPercentageSizeValue); }
/// <summary> /// Class constructor. /// </summary> /// <param name="key"></param> /// <param name="displayNameLong"></param> /// <param name="displayNameShort"></param> /// <param name="defaultValues"></param> public ListItem(Itemkey key, string displayNameLong, string displayNameShort, ObservableCollection <string> defaultValues) { this.Key = key; this.DisplayNameLong = (displayNameLong == null ? "(null)" : displayNameLong); this.DisplayNameShort = (displayNameShort == null ? "(null)" : displayNameShort); this.DefaultValues = defaultValues; }
/// <summary> /// Class constructor. /// </summary> /// <param name="key"></param> /// <param name="displayNameLong"></param> /// <param name="displayNameShort"></param> /// <param name="defaultValues"></param> public ListItem(Itemkey key, string displayNameLong, string displayNameShort, ObservableCollection<string> defaultValues) { this.Key = key; this.DisplayNameLong = (displayNameLong == null ? "(null)" : displayNameLong); this.DisplayNameShort = (displayNameShort == null ? "(null)" : displayNameShort); this.DefaultValues = defaultValues; }
/// <summary> /// Convert between different units of screen resolutions. /// </summary> /// <param name="inputUnit"></param> /// <param name="inputValue"></param> /// <param name="outputUnit"></param> /// <returns></returns> public override double Convert(Itemkey inputUnit, double inputValue, Itemkey outputUnit) { switch (inputUnit) { case Itemkey.ScreenFontPoints: return ScreenFontPoints.ToUnit(inputValue, outputUnit); case Itemkey.ScreenPercent: return ScreenPercent.ToUnit(inputValue, outputUnit); default: throw new NotImplementedException(outputUnit.ToString()); } }
/// <summary> /// Convert a font size to other values. /// </summary> /// <param name="inputValue"></param> /// <param name="targetUnit"></param> /// <param name="oneHundredPercentFontSize"></param> /// <returns></returns> public static double ToUnit(double inputValue, Itemkey targetUnit, double oneHundredPercentFontSize) { switch (targetUnit) { case Itemkey.ScreenPercent: return(inputValue * (100 / oneHundredPercentFontSize)); case Itemkey.ScreenFontPoints: return(inputValue); default: throw new NotImplementedException(targetUnit.ToString()); } }
/// <summary> /// Convert a font size to other values. /// </summary> /// <param name="targetUnit"></param> /// <returns></returns> public double ToUnit(Itemkey targetUnit) { switch (targetUnit) { case Itemkey.ScreenPercent: return this.mValue * (100 / ScreenConverter.OneHundretPercentFont); case Itemkey.ScreenFontPoints: return this.mValue; default: throw new NotImplementedException(targetUnit.ToString()); } }
/// <summary> /// Convert between different units of screen resolutions. /// </summary> /// <param name="inputUnit"></param> /// <param name="inputValue"></param> /// <param name="outputUnit"></param> /// <returns></returns> public override double Convert(Itemkey inputUnit, double inputValue, Itemkey outputUnit) { switch (inputUnit) { case Itemkey.ScreenFontPoints: return(ScreenFontPoints.ToUnit(inputValue, outputUnit, OneHundredPercentFontSize)); case Itemkey.ScreenPercent: return(ScreenPercent.ToUnit(inputValue, outputUnit, OneHundredPercentFontSize)); default: throw new NotImplementedException(outputUnit.ToString()); } }
/// <summary> /// Convert a font size to other values. /// </summary> /// <param name="targetUnit"></param> /// <returns></returns> public double ToUnit(Itemkey targetUnit) { switch (targetUnit) { case Itemkey.ScreenPercent: return(this.mValue * (100 / ScreenConverter.OneHundretPercentFont)); case Itemkey.ScreenFontPoints: return(this.mValue); default: throw new NotImplementedException(targetUnit.ToString()); } }
private static string SetUnitRangeMessage(Itemkey unit) { switch (unit) { // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenFontPoints: return(FontSizeErrorTip()); // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenPercent: return(PercentSizeErrorTip()); default: throw new System.NotSupportedException(unit.ToString()); } }
/// <summary> /// Convert current double value from current unit to /// unit as indicated by <paramref name="unitKey"/> and /// set corresponding SelectedItem. /// </summary> /// <param name="unitKey">New unit to convert double value into and set SelectedItem to.</param> /// <returns></returns> private object SetSelectedItemExecuted(Itemkey unitKey) { // Find the next selected item ListItem li = this._UnitList.SingleOrDefault(i => i.Key == unitKey); // Convert from current item to find the next selected item if (li != null) { double dValue; if (double.TryParse(this._StrValue, out dValue) == true) { double tempValue = this._UnitConverter.Convert(this.SelectedItem.Key, dValue, li.Key); if (tempValue < this.GetMinValue(unitKey)) { tempValue = this.GetMinValue(unitKey); } else if (tempValue > this.GetMaxValue(unitKey)) { tempValue = this.GetMaxValue(unitKey); } this.Value = tempValue; this._StrValue = string.Format("{0:0}", this._Value); this.SelectedItem = li; this.ValueTip = this.SetUnitRangeMessage(unitKey); // Set standard tool tip about valid range } this.RaisePropertyChanged(() => this.Value); this.RaisePropertyChanged(() => this.MinValue); this.RaisePropertyChanged(() => this.MaxValue); this.RaisePropertyChanged(() => this.StringValue); this.RaisePropertyChanged(() => this.SelectedItem); } return(null); }
/// <summary> /// Check whether the <paramref name="doubleValue"/> is within the expected /// range of <paramref name="unitToConvert"/> and output a corresponding /// error message via <paramref name="message"/> parameter if not. /// </summary> /// <param name="doubleValue"></param> /// <param name="unitToConvert"></param> /// <param name="message"></param> /// <returns>False if range is not acceptable, true otherwise</returns> private bool IsDoubleWithinRange(double doubleValue, Itemkey unitToConvert, out string message) { message = SetUnitRangeMessage(unitToConvert); switch (unitToConvert) { // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenFontPoints: if (doubleValue < MinFontSizeValue) { return(false); } else if (doubleValue > MaxFontSizeValue) { return(false); } return(true); // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenPercent: if (doubleValue < MinPercentageSizeValue) { return(false); } else if (doubleValue > MaxPercentageSizeValue) { return(false); } return(true); } return(false); }
/// <summary> /// Converter method to convert a value from one unit to the other. /// </summary> /// <param name="inputUnit">Unit of <paramref name="inputValue"/></param> /// <param name="inputValue">Amount of value to convert</param> /// <param name="outputUnit">Expected Unit of value to be converted to.</param> /// <returns>Converted value.</returns> public abstract double Convert(Itemkey inputUnit, double inputValue, Itemkey outputUnit);
/// <summary> /// Convert a font size to other values. /// </summary> /// <param name="inputValue"></param> /// <param name="targetUnit"></param> /// <returns></returns> public static double ToUnit(double inputValue, Itemkey targetUnit) { ScreenFontPoints d = new ScreenFontPoints(inputValue); return(d.ToUnit(targetUnit)); }
/// <summary> /// Convert a font size to other values. /// </summary> /// <param name="inputValue"></param> /// <param name="targetUnit"></param> /// <returns></returns> public static double ToUnit(double inputValue, Itemkey targetUnit) { ScreenFontPoints d = new ScreenFontPoints(inputValue); return d.ToUnit(targetUnit); }
private double GetMinValue(Itemkey key) { if (key == Itemkey.ScreenFontPoints) return UnitViewModel.MinFontSizeValue; return UnitViewModel.MinPercentageSizeValue; }
/// <summary> /// Check whether the <paramref name="doubleValue"/> is within the expected /// range of <paramref name="unitToConvert"/> and output a corresponding /// error message via <paramref name="message"/> parameter if not. /// </summary> /// <param name="doubleValue"></param> /// <param name="unitToConvert"></param> /// <param name="message"></param> /// <returns>False if range is not acceptable, true otherwise</returns> private bool IsDoubleWithinRange(double doubleValue, Itemkey unitToConvert, out string message) { message = this.SetUnitRangeMessage(unitToConvert); switch (unitToConvert) { // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenFontPoints: if (doubleValue < MinFontSizeValue) return false; else if (doubleValue > MaxFontSizeValue) return false; return true; // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenPercent: if (doubleValue < MinPercentageSizeValue) return false; else if (doubleValue > MaxPercentageSizeValue) return false; return true; } return false; }
/// <summary> /// Convert current double value from current unit to /// unit as indicated by <paramref name="unitKey"/> and /// set corresponding SelectedItem. /// </summary> /// <param name="unitKey">New unit to convert double value into and set SelectedItem to.</param> /// <returns></returns> private object SetSelectedItemExecuted(Itemkey unitKey) { // Find the next selected item ListItem li = this.mUnitList.SingleOrDefault(i => i.Key == unitKey); // Convert from current item to find the next selected item if (li != null) { double dValue; if (double.TryParse(this.mstrValue, out dValue) == true) { double tempValue = this.mUnitConverter.Convert(this.SelectedItem.Key, dValue, li.Key); if (tempValue < this.GetMinValue(unitKey)) tempValue = this.GetMinValue(unitKey); else if (tempValue > this.GetMaxValue(unitKey)) tempValue = this.GetMaxValue(unitKey); this.Value = tempValue; this.mstrValue = string.Format("{0:0}", this.mValue); this.SelectedItem = li; this.ValueTip = this.SetUnitRangeMessage(unitKey); // Set standard tool tip about valid range } this.RaisePropertyChanged(() => this.Value); this.RaisePropertyChanged(() => this.MinValue); this.RaisePropertyChanged(() => this.MaxValue); this.RaisePropertyChanged(() => this.StringValue); this.RaisePropertyChanged(() => this.SelectedItem); } return null; }
private string SetUnitRangeMessage(Itemkey unit) { switch (unit) { // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenFontPoints: return this.FontSizeErrorTip(); // Implement a minimum value of 2 in any way (no matter what the unit is) case Itemkey.ScreenPercent: return this.PercentSizeErrorTip(); default: throw new System.NotSupportedException(unit.ToString()); } }
/// <summary> /// Converter method to convert a value from one unit to the other. /// </summary> /// <param name="inputUnit">Unit of <paramref name="inputValue"/></param> /// <param name="inputValue">Amount of value to convert</param> /// <param name="outputUnit">Expected Unit of value to be converted to.</param> /// <returns>Converted value.</returns> public abstract double Convert(Itemkey inputUnit, double inputValue, Itemkey outputUnit);
/// <summary> /// Convert percentage unit based value into another unit based value. /// </summary> /// <param name="inputValue"></param> /// <param name="targetUnit"></param> /// <returns></returns> public static double ToUnit(double inputValue, Itemkey targetUnit) { ScreenPercent d = new ScreenPercent(inputValue); return(d.ToUnit(targetUnit)); }
/// <summary> /// Convert percentage unit based value into another unit based value. /// </summary> /// <param name="inputValue"></param> /// <param name="targetUnit"></param> /// <returns></returns> public static double ToUnit(double inputValue, Itemkey targetUnit) { ScreenPercent d = new ScreenPercent(inputValue); return d.ToUnit(targetUnit); }