// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; using DotSpatialResources = Core.Plugins.DotSpatial.Properties.Resources; using GuiResources = Core.Common.Gui.Properties.Resources; namespace Core.Plugins.DotSpatial.Legend { /// /// The view which shows the data that is added to a . /// public sealed partial class MapLegendView : UserControl, IView { private readonly TreeViewControl treeViewControl; /// /// Creates a new instance of . /// public MapLegendView() { InitializeComponent(); Text = DotSpatialResources.General_Map; treeViewControl = new TreeViewControl { Dock = DockStyle.Fill }; Controls.Add(treeViewControl); RegisterTreeNodeInfos(); } public object Data { get { return (MapData) treeViewControl.Data; } set { if (IsDisposed) { return; } treeViewControl.Data = (MapData) value; } } protected override void Dispose(bool disposing) { Data = null; if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void RegisterTreeNodeInfos() { treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapPointData => mapPointData.Name, Image = mapPointData => DotSpatialResources.PointsIcon, CanDrag = (mapPointData, parentData) => true, CanCheck = mapPointData => true, IsChecked = mapPointData => mapPointData.IsVisible, OnNodeChecked = MapPointDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapLineData => mapLineData.Name, Image = mapLineData => DotSpatialResources.LineIcon, CanDrag = (mapLineData, parentData) => true, CanCheck = mapLineData => true, IsChecked = mapLineData => mapLineData.IsVisible, OnNodeChecked = MapLineDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapPolygonData => mapPolygonData.Name, Image = mapPolygonData => DotSpatialResources.AreaIcon, CanDrag = (mapPolygonData, parentData) => true, CanCheck = mapPolygonData => true, IsChecked = mapPolygonData => mapPolygonData.IsVisible, OnNodeChecked = MapPolygonDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapDataCollection => mapDataCollection.Name, Image = mapDataCollection => GuiResources.folder, ChildNodeObjects = mapDataCollection => mapDataCollection.List.Reverse().Cast().ToArray(), CanDrop = BaseMapCanDrop, CanInsert = BaseMapCanInsert, OnDrop = BaseMapOnDrop }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapMultiLineData => mapMultiLineData.Name, Image = mapMultiLineData => DotSpatialResources.LineIcon, CanDrag = (mapMultiLineData, parentData) => true, CanCheck = mapMultiLineData => true, IsChecked = mapMultiLineData => mapMultiLineData.IsVisible, OnNodeChecked = MapMultiLineDataOnNodeChecked }); } #region MapData private void MapPointDataOnNodeChecked(MapPointData mapPointData, object parentData) { PointBasedMapDataOnNodeChecked(mapPointData, parentData); } private void MapLineDataOnNodeChecked(MapLineData mapLineData, object parentData) { PointBasedMapDataOnNodeChecked(mapLineData, parentData); } private void MapPolygonDataOnNodeChecked(MapPolygonData mapPolygonData, object parentData) { PointBasedMapDataOnNodeChecked(mapPolygonData, parentData); } private void MapMultiLineDataOnNodeChecked(MapMultiLineData mapMultiLineData, object parentData) { mapMultiLineData.IsVisible = !mapMultiLineData.IsVisible; mapMultiLineData.NotifyObservers(); var observableParent = parentData as IObservable; if (observableParent != null) { observableParent.NotifyObservers(); } } private void PointBasedMapDataOnNodeChecked(PointBasedMapData pointBasedMapData, object parentData) { pointBasedMapData.IsVisible = !pointBasedMapData.IsVisible; pointBasedMapData.NotifyObservers(); var observableParent = parentData as IObservable; if (observableParent != null) { observableParent.NotifyObservers(); } } #endregion # region MapDataCollection private static bool BaseMapCanDrop(object draggedData, object targetData) { return draggedData is MapData; } private static bool BaseMapCanInsert(object draggedData, object targetData) { return draggedData is MapData; } private static void BaseMapOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl control) { var mapData = (MapData)droppedData; var target = (MapDataCollection)newParentData; target.List.Remove(mapData); target.List.Insert(target.List.Count - position, mapData); // Note: target is the same as the previous parent in this case target.NotifyObservers(); } # endregion } }