Beispiel #1
0
        /// <summary>
        /// Returns the Icon of the specified size from the Cache.
        /// </summary>
        /// <param name="AFileName">File name of the Icon incl. full path</param>
        /// <param name="AIconSize">Desired size of the Icon to be returned (should
        /// this size not be availabe then the closest match will be returned).</param>
        /// <returns>Icon of the specified size or the closest matching size.</returns>
        public Bitmap GetIcon(string AFileName, TIconSize AIconSize)
        {
            Icon TheItem;

            if (AFileName == null)
            {
                return(null);
            }
            else
            {
                AFileName = Path.GetFullPath(AFileName.Replace('\\', '/'));

                try
                {
                    TheItem = (Icon)this[AFileName + AIconSize.ToString()];
                }
                catch (KeyNotFoundException)
                {
                    FLastIconRequestedWasReturnedFromCache = false;

                    throw new EIconNotInCacheException(String.Format(
                                                           "Icon with path {0} not yet loaded into cache; add it to the cache with AddIcon Method first", AFileName));
                }

                FLastIconRequestedWasReturnedFromCache = true;

                return(TheItem.ToBitmap());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether an Icon exists in the Cache.
        /// </summary>
        /// <param name="AFileName">File name of the Icon incl. full path</param>
        /// <param name="AIconSize">size of the icon</param>
        /// <returns>True if the icon exists in the Cache, otherwise false.</returns>
        public bool ContainsIcon(string AFileName, TIconSize AIconSize)
        {
            if (AFileName == null)
            {
                return(false);
            }
            else
            {
                AFileName = Path.GetFullPath(AFileName.Replace('\\', '/'));

                return(ContainsKey(AFileName + AIconSize.ToString()));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds an Icon into the Cache.
        /// </summary>
        /// <param name="AFileName">File name of the Icon incl. full path</param>
        /// <param name="AIconSize">define which size the icon should have</param>
        public void AddIcon(string AFileName, TIconSize AIconSize)
        {
            if (AFileName == null)
            {
                return;
            }

            AFileName = Path.GetFullPath(AFileName.Replace('\\', '/'));
            Icon icon = new Icon(AFileName, GetIconSize(AIconSize));

            this.AddOrUpdate(AFileName + AIconSize.ToString(), icon, (AKey, AExistingValue) =>
            {
                return(AExistingValue);
            });
        }
Beispiel #4
0
        /// <summary>
        /// Adds an Icon into the Cache if it isn't yet in the Cache. Returns the
        /// Icon of the specified size, no matter if it was found in the Cache or
        /// whether it needed to be loaded from file first.
        /// </summary>
        /// <param name="AFileName">File name of the Icon incl. full path</param>
        /// <param name="AIconSize">Desired size of the Icon to be returned (should
        /// this size not be availabe then the closest match will be returned).</param>
        /// <returns>Icon of the specified size or the closest matching size.</returns>
        public Bitmap AddOrGetExistingIcon(string AFileName, TIconSize AIconSize)
        {
            Bitmap ReturnValue = null;

            AFileName = Path.GetFullPath(AFileName.Replace('\\', '/'));

            if (!ContainsIcon(AFileName, AIconSize))
            {
                AddIcon(AFileName, AIconSize);
                ReturnValue = GetIcon(AFileName, AIconSize);

                FLastIconRequestedWasReturnedFromCache = false;
            }
            else
            {
                ReturnValue = GetIcon(AFileName, AIconSize);
            }

            return(ReturnValue);
        }
Beispiel #5
0
        /// <summary>
        /// Returns the Size of an Icon in pixels that is specified with a <see cref="TIconSize" /> enum value.
        /// </summary>
        /// <param name="AIconSize">Icon size enum value</param>
        /// <returns>Size of an Icon in pixels for enum value specified with <paramref name="AIconSize"/></returns>
        private Size GetIconSize(TIconSize AIconSize)
        {
            switch (AIconSize)
            {
            case TIconSize.is16by16:
                return(new Size(16, 16));

            case TIconSize.is24by24:
                return(new Size(24, 24));

            case TIconSize.is32by32:
                return(new Size(32, 32));

            case TIconSize.is48by48:
                return(new Size(48, 48));

            default:
                // Fallback
                return(new Size(16, 16));
            }
        }