1 /* 2 * ************************************************************************************************************************************************************* 3 * 4 * TheseFoolishThings: Miscellaneous utilities 5 * http://tidalwave.it/projects/thesefoolishthings 6 * 7 * Copyright (C) 2009 - 2024 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/thesefoolishthings-src 22 * git clone https://github.com/tidalwave-it/thesefoolishthings-src 23 * 24 * ************************************************************************************************************************************************************* 25 */ 26 package it.tidalwave.role.ui; 27 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 * 36 * The role of an object that can provide an icon for rendering. 37 * 38 * @stereotype Role 39 * 40 * @author Fabrizio Giudici 41 * @it.tidalwave.javadoc.draft 42 * 43 **************************************************************************************************************************************************************/ 44 @FunctionalInterface 45 public interface IconProvider 46 { 47 public static final Class<IconProvider> _IconProvider_ = IconProvider.class; 48 49 /*********************************************************************************************************************************************************** 50 * A default {@code IconProvider} with an empty icon. 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 56 @Override @Nonnull 57 public Icon getIcon (@Nonnegative final int size) 58 { 59 return EMPTY_ICON; 60 } 61 }; 62 63 /*********************************************************************************************************************************************************** 64 * Returns the icon for this object. Note that the {@code size} parameter is just a hint to allow implementations 65 * to pick the correctly sized icon in an optimized fashion. In particular, implementations should try to do their 66 * best for providing an icon whose size is equal or greater than the requested one, but this is not guaranteed. 67 * It's up to the client code to eventually resize the returned icon for its purposes. 68 * 69 * @param requestedSize the requested icon size 70 * @return the icon 71 **********************************************************************************************************************************************************/ 72 @Nonnull 73 public Icon getIcon (@Nonnegative int requestedSize); 74 }