IconProvider.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * TheseFoolishThings: Miscellaneous utilities
  5.  * http://tidalwave.it/projects/thesefoolishthings
  6.  *
  7.  * Copyright (C) 2009 - 2023 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
  12.  * the License. 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
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
  23.  * git clone https://github.com/tidalwave-it/thesefoolishthings-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.role.ui;

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

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

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

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

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