예제 #1
0
        private static double GetMaxValue(Itemkey key)
        {
            if (key == Itemkey.ScreenFontPoints)
            {
                return(UnitViewModel.MaxFontSizeValue);
            }

            return(UnitViewModel.MaxPercentageSizeValue);
        }
예제 #2
0
        private static double GetMinValue(Itemkey key)
        {
            if (key == Itemkey.ScreenFontPoints)
            {
                return(MinFontSizeValue);
            }

            return(MinPercentageSizeValue);
        }
예제 #3
0
        private double GetMinValue(Itemkey key)
        {
            if (key == Itemkey.ScreenFontPoints)
            {
                return(UnitViewModel.MinFontSizeValue);
            }

            return(UnitViewModel.MinPercentageSizeValue);
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
        /// <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;
        }
예제 #6
0
        /// <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());
               }
        }
예제 #7
0
        /// <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());
            }
        }
예제 #8
0
        /// <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());
              }
        }
예제 #9
0
        /// <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());
            }
        }
예제 #10
0
        /// <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());
            }
        }
예제 #11
0
        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());
            }
        }
예제 #12
0
        /// <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);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
 /// <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);
예제 #15
0
        /// <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));
        }
예제 #16
0
        /// <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);
        }
예제 #17
0
        private double GetMinValue(Itemkey key)
        {
            if (key == Itemkey.ScreenFontPoints)
            return UnitViewModel.MinFontSizeValue;

              return UnitViewModel.MinPercentageSizeValue;
        }
예제 #18
0
        /// <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;
        }
예제 #19
0
        /// <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;
        }
예제 #20
0
        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());
               }
        }
예제 #21
0
 /// <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);
예제 #22
0
        /// <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));
        }
예제 #23
0
        /// <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);
        }