IconProvider.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * SteelBlue: DCI User Interfaces
  5.  * http://tidalwave.it/projects/steelblue
  6.  *
  7.  * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/steelblue-src
  22.  * git clone https://github.com/tidalwave-it/steelblue-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.ui.core.role;

  27. import javax.annotation.Nonnegative;
  28. import jakarta.annotation.Nonnull;
  29. import java.awt.image.BufferedImage;
  30. import javax.swing.Icon;
  31. import javax.swing.ImageIcon;

  32. /***************************************************************************************************************************************************************
  33.  *
  34.  * The role of an object that can provide an icon for rendering.
  35.  *
  36.  * @stereotype Role
  37.  *
  38.  * @since   2.0-ALPHA-1
  39.  * @author  Fabrizio Giudici
  40.  * @it.tidalwave.javadoc.draft
  41.  *
  42.  **************************************************************************************************************************************************************/
  43. @FunctionalInterface
  44. public interface IconProvider
  45.   {
  46.     /** Shortcut for {@link it.tidalwave.util.As}. */
  47.     public static final Class<IconProvider> _IconProvider_ = IconProvider.class;

  48.     /***********************************************************************************************************************************************************
  49.      * A default {@code IconProvider} with an empty icon.
  50.      **********************************************************************************************************************************************************/
  51.     public static final IconProvider DEFAULT = new IconProvider()
  52.       {
  53.         private final Icon EMPTY_ICON = new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_4BYTE_ABGR));

  54.         @Override @Nonnull
  55.         public Icon getIcon (@Nonnegative final int size)
  56.           {
  57.             return EMPTY_ICON;
  58.           }
  59.       };

  60.     /***********************************************************************************************************************************************************
  61.      * Returns the icon for this object. Note that the {@code size} parameter is just a hint to allow implementations
  62.      * to pick the correctly sized icon in an optimized fashion. In particular, implementations should try to do their
  63.      * best for providing an icon whose size is equal or greater than the requested one, but this is not guaranteed.
  64.      * It's up to the client code to eventually resize the returned icon for its purposes.
  65.      *
  66.      * @param  requestedSize  the requested icon size
  67.      * @return                the icon
  68.      **********************************************************************************************************************************************************/
  69.     @Nonnull
  70.     public Icon getIcon (@Nonnegative int requestedSize);
  71.   }