PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/ViewportConstraints/ConstraintCollection.cs

#
C# | 69 lines | 56 code | 7 blank | 6 comment | 8 complexity | 10e63bf087d2714e55c6b9943315b0b6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System.Linq;
  2. using System.Windows;
  3. using Microsoft.Research.DynamicDataDisplay;
  4. using Microsoft.Research.DynamicDataDisplay.Common;
  5. using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
  6. using System;
  7. using System.Collections.Specialized;
  8. namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
  9. {
  10. /// <summary>
  11. /// Represents a collection of <see cref="ViewportConstraint"/>s.
  12. /// <remarks>
  13. /// ViewportConstraint that is being added should not be null.
  14. /// </remarks>
  15. /// </summary>
  16. public sealed class ConstraintCollection : D3Collection<ViewportConstraint>
  17. {
  18. private readonly Viewport2D viewport;
  19. internal ConstraintCollection(Viewport2D viewport)
  20. {
  21. if (viewport == null)
  22. throw new ArgumentNullException("viewport");
  23. this.viewport = viewport;
  24. }
  25. protected override void OnItemAdding(ViewportConstraint item)
  26. {
  27. if (item == null)
  28. throw new ArgumentNullException("item");
  29. }
  30. protected override void OnItemAdded(ViewportConstraint item)
  31. {
  32. item.Changed += OnItemChanged;
  33. ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
  34. if (attachable != null)
  35. {
  36. attachable.Attach(viewport);
  37. }
  38. }
  39. private void OnItemChanged(object sender, EventArgs e)
  40. {
  41. OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
  42. }
  43. protected override void OnItemRemoving(ViewportConstraint item)
  44. {
  45. ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
  46. if (attachable != null)
  47. {
  48. attachable.Detach(viewport);
  49. }
  50. item.Changed -= OnItemChanged;
  51. }
  52. internal DataRect Apply(DataRect oldVisible, DataRect newVisible, Viewport2D viewport)
  53. {
  54. DataRect res = newVisible;
  55. foreach (var constraint in this)
  56. {
  57. res = constraint.Apply(oldVisible, res, viewport);
  58. }
  59. return res;
  60. }
  61. }
  62. }