/// <summary>
        /// Adds a filter to this collection.
        /// </summary>
        /// <param name="name">The name of the filter to add.</param>
        /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
        /// <returns>True if the filter was successfully added; otherwise false.</returns>
        public bool AddFilter(string name, MapDrawFilterHelper filter)
        {
            // Validate the name
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            // Validate the filter object
            if (filter == null)
            {
                return(false);
            }

            // Check if the name is already in use
            if (_filters.ContainsKey(name))
            {
                return(false);
            }

            // Add
            _filters.Add(name, filter);

            // Raise events
            if (Added != null)
            {
                Added.Raise(this, new MapDrawFilterHelperCollectionEventArgs(name, filter));
            }

            return(true);
        }
        /// <summary>
        /// Handles the Click event of the <see cref="btnAdd"/> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            var c = Collection;

            if (c == null)
            {
                return;
            }

            var name = string.Empty;

            // Get the new filter's name
            do
            {
                const string msgInitial = "Enter the name of the new filter.";
                const string msgRetry   = "A filter with that name already exists. Please try another name.";

                name = InputBox.Show("New filter name", string.IsNullOrEmpty(name) ? msgInitial : msgRetry, name);

                // User aborted
                if (string.IsNullOrEmpty(name))
                {
                    return;
                }
            }while (!string.IsNullOrEmpty(name) && c.TryGetFilter(name) != null);

            // Create and add the new filter
            var filter = new MapDrawFilterHelper();

            if (c.AddFilter(name, filter))
            {
                // Select the new filter
                lstItems.SelectedItem = filter;
            }
        }
        /// <summary>
        /// Reads a filter from an <see cref="IValueReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        /// <returns>The name of the filter and the filter object.</returns>
        static KeyValuePair <string, MapDrawFilterHelper> ReadFilter(IValueReader reader)
        {
            var key = reader.ReadString(_filterKeyValueName);

            var valueReader = reader.ReadNode(_filterValueValueName);
            var value       = new MapDrawFilterHelper(valueReader);

            return(new KeyValuePair <string, MapDrawFilterHelper>(key, value));
        }
        /// <summary>
        /// Tries to get a filter's name.
        /// </summary>
        /// <param name="filter">The <see cref="MapDrawFilterHelper"/> to get the name of.</param>
        /// <returns>The name of the <paramref name="filter"/>, or null if the <paramref name="filter"/> is invalid or is not
        /// in this collection.</returns>
        public string TryGetName(MapDrawFilterHelper filter)
        {
            if (filter == null)
            {
                return(null);
            }

            return(_filters.FirstOrDefault(x => x.Value == filter).Key);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the string to draw for a list item.
        /// </summary>
        /// <param name="x">The list item.</param>
        /// <returns>The string to draw for a list item.</returns>
        string GetDrawString(MapDrawFilterHelper x)
        {
            var c = Collection;

            if (x == null)
                return "[NULL]";

            if (c == null)
                return x.ToString();
            else
                return c.TryGetName(x) ?? x.ToString();
        }
        /// <summary>
        /// Gets the string to draw for a list item.
        /// </summary>
        /// <param name="x">The list item.</param>
        /// <returns>The string to draw for a list item.</returns>
        string GetDrawString(MapDrawFilterHelper x)
        {
            var c = Collection;

            if (x == null)
            {
                return("[NULL]");
            }

            if (c == null)
            {
                return(x.ToString());
            }
            else
            {
                return(c.TryGetName(x) ?? x.ToString());
            }
        }
        /// <summary>
        /// Adds a filter to this collection.
        /// </summary>
        /// <param name="name">The name of the filter to add.</param>
        /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
        /// <returns>True if the filter was successfully added; otherwise false.</returns>
        public bool AddFilter(string name, MapDrawFilterHelper filter)
        {
            // Validate the name
            if (string.IsNullOrEmpty(name))
                return false;

            // Validate the filter object
            if (filter == null)
                return false;

            // Check if the name is already in use
            if (_filters.ContainsKey(name))
                return false;

            // Add
            _filters.Add(name, filter);

            // Raise events
            if (Added != null)
                Added.Raise(this, new MapDrawFilterHelperCollectionEventArgs(name, filter));

            return true;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionRenameEventArgs"/> class.
 /// </summary>
 /// <param name="filterName">The name of the filter.</param>
 /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
 /// <param name="oldName">The old name of the filter.</param>
 public MapDrawFilterHelperCollectionRenameEventArgs(string filterName, MapDrawFilterHelper filter, string oldName)
     : base(filterName, filter)
 {
     _oldName = oldName;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionRenameEventArgs"/> class.
 /// </summary>
 /// <param name="filterName">The name of the filter.</param>
 /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
 /// <param name="oldName">The old name of the filter.</param>
 public MapDrawFilterHelperCollectionRenameEventArgs(string filterName, MapDrawFilterHelper filter, string oldName)
     : base(filterName, filter)
 {
     _oldName = oldName;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionEventArgs"/> class.
 /// </summary>
 /// <param name="filterName">The name of the filter.</param>
 /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
 public MapDrawFilterHelperCollectionEventArgs(string filterName, MapDrawFilterHelper filter)
 {
     _filterName = filterName;
     _filter = filter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionEventArgs"/> class.
 /// </summary>
 /// <param name="filter">The name of the filter and the <see cref="MapDrawFilterHelper"/> itself.</param>
 public MapDrawFilterHelperCollectionEventArgs(KeyValuePair<string, MapDrawFilterHelper> filter)
 {
     _filterName = filter.Key;
     _filter = filter.Value;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Handles the Click event of the <see cref="btnAdd"/> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            var c = Collection;
            if (c == null)
                return;

            var name = string.Empty;

            // Get the new filter's name
            do
            {
                const string msgInitial = "Enter the name of the new filter.";
                const string msgRetry = "A filter with that name already exists. Please try another name.";

                name = InputBox.Show("New filter name", string.IsNullOrEmpty(name) ? msgInitial : msgRetry, name);

                // User aborted
                if (string.IsNullOrEmpty(name))
                    return;
            }
            while (!string.IsNullOrEmpty(name) && c.TryGetFilter(name) != null);

            // Create and add the new filter
            var filter = new MapDrawFilterHelper();

            if (c.AddFilter(name, filter))
            {
                // Select the new filter
                lstItems.SelectedItem = filter;
            }
        }
        /// <summary>
        /// Reads a filter from an <see cref="IValueReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        /// <returns>The name of the filter and the filter object.</returns>
        static KeyValuePair<string, MapDrawFilterHelper> ReadFilter(IValueReader reader)
        {
            var key = reader.ReadString(_filterKeyValueName);

            var valueReader = reader.ReadNode(_filterValueValueName);
            var value = new MapDrawFilterHelper(valueReader);

            return new KeyValuePair<string, MapDrawFilterHelper>(key, value);
        }
        /// <summary>
        /// Tries to get a filter's name.
        /// </summary>
        /// <param name="filter">The <see cref="MapDrawFilterHelper"/> to get the name of.</param>
        /// <returns>The name of the <paramref name="filter"/>, or null if the <paramref name="filter"/> is invalid or is not
        /// in this collection.</returns>
        public string TryGetName(MapDrawFilterHelper filter)
        {
            if (filter == null)
                return null;

            return _filters.FirstOrDefault(x => x.Value == filter).Key;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionEventArgs"/> class.
 /// </summary>
 /// <param name="filterName">The name of the filter.</param>
 /// <param name="filter">The <see cref="MapDrawFilterHelper"/>.</param>
 public MapDrawFilterHelperCollectionEventArgs(string filterName, MapDrawFilterHelper filter)
 {
     _filterName = filterName;
     _filter     = filter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapDrawFilterHelperCollectionEventArgs"/> class.
 /// </summary>
 /// <param name="filter">The name of the filter and the <see cref="MapDrawFilterHelper"/> itself.</param>
 public MapDrawFilterHelperCollectionEventArgs(KeyValuePair <string, MapDrawFilterHelper> filter)
 {
     _filterName = filter.Key;
     _filter     = filter.Value;
 }