//Read public StatusGraphic this[double value] { get { try { StatusGraphic foundStatusGraphic = null; foreach (double graphicKey in _statusGraphics.Keys) { if (foundStatusGraphic == null) { foundStatusGraphic = (StatusGraphic)_statusGraphics[graphicKey]; } if (value <= graphicKey) { break; } foundStatusGraphic = (StatusGraphic)_statusGraphics[graphicKey]; } if (foundStatusGraphic == null) { throw new KeyNotFoundException(); } if (foundStatusGraphic.IsValueInRange(value)) { return(foundStatusGraphic); } throw new KeyNotFoundException(); } catch (Exception ex) { throw new KeyNotFoundException("Can't find", ex); } } }
internal void RemoveStatusGraphic(StatusGraphic statusGraphic) { var currentStatusGraphics = _statusGraphics ?? new StatusGraphicCollection(); if (Changes.ContainsKey(EProperty.StatusGraphics)) { currentStatusGraphics = Changes[EProperty.StatusGraphics] as StatusGraphicCollection ?? new StatusGraphicCollection(); } currentStatusGraphics.Remove(statusGraphic); if (Changes.ContainsKey(EProperty.StatusGraphics)) { Changes[EProperty.StatusGraphics] = currentStatusGraphics; } else { Changes.Add(EProperty.StatusGraphics, currentStatusGraphics); } if (_cacheChanges) { return; } _statusGraphics = currentStatusGraphics; }
//Create public void Add(StatusGraphic statusGraphic) { if (Contains(statusGraphic)) { throw new ArgumentException("A status graphic with that value set already exists"); } _statusGraphics.Add(statusGraphic.IsRange ? statusGraphic.RangeMin : statusGraphic.Value, statusGraphic); }
public bool Contains(StatusGraphic statusGraphic) { try { var unused = statusGraphic.IsRange ? this[statusGraphic.RangeMin] : this[statusGraphic.Value]; return(true); } catch (KeyNotFoundException exception) { return(false); } }
public void Remove(StatusGraphic statusGraphic) { var itemKey = statusGraphic.IsRange ? statusGraphic.RangeMin : statusGraphic.Value; var itemToDelete = this[itemKey]; if (itemToDelete.GetHashCode() == statusGraphic.GetHashCode()) { _statusGraphics.Remove(itemKey); } }
//TODO Button Script? #endregion #region Status Graphics //Add Status Graphics public FeatureFactory AddGraphicForValue(string imagePath, double targetValue, string statusText = "") { if (string.IsNullOrWhiteSpace(imagePath)) { throw new ArgumentNullException(nameof(imagePath)); } if (_feature.HasGraphicForValue(targetValue)) { throw new ArgumentException($"The value {targetValue} already has a graphic bound to it.", nameof(targetValue)); } var statusGraphic = new StatusGraphic(imagePath, targetValue, statusText); _feature.AddStatusGraphic(statusGraphic); return(this); }
public FeatureFactory AddGraphicForRange(string imagePath, double minValue, double maxValue, string statusText = "") { if (string.IsNullOrWhiteSpace(imagePath)) { throw new ArgumentNullException(nameof(imagePath)); } var tempRange = new ValueRange(minValue, maxValue); if (_feature.HasGraphicForRange(tempRange)) { throw new ArgumentException($"Some or all of the values in the range {tempRange.Min}-{tempRange.Max} already has a control bound to it."); } var statusGraphic = new StatusGraphic(imagePath, minValue, maxValue); statusGraphic.Label = statusText; _feature.AddStatusGraphic(statusGraphic); return(this); }
public bool ContainsValue(double value) { try { StatusGraphic foundStatusGraphic = null; foreach (double statusControlKey in _statusGraphics.Keys) { if (foundStatusGraphic == null) { foundStatusGraphic = (StatusGraphic)_statusGraphics[statusControlKey]; } if (value <= statusControlKey) { break; } foundStatusGraphic = (StatusGraphic)_statusGraphics[statusControlKey]; } return(foundStatusGraphic != null && foundStatusGraphic.IsValueInRange(value)); } catch (Exception) { return(false); } }