001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.resource.icon; 020 021import icy.resource.ResourceUtil; 022 023import java.awt.Component; 024import java.awt.Dimension; 025import java.awt.Graphics; 026 027import javax.swing.Icon; 028 029import org.pushingpixels.flamingo.api.common.icon.ResizableIcon; 030 031/** 032 * @author Stephane 033 */ 034public class IcyApplicationIcon implements ResizableIcon 035{ 036 private static final int DEFAULT_SIZE = 32; 037 038 private final Dimension dim; 039 private Icon icon; 040 041 public IcyApplicationIcon() 042 { 043 super(); 044 045 dim = new Dimension(); 046 setDimension(new Dimension(DEFAULT_SIZE, DEFAULT_SIZE)); 047 } 048 049 @Override 050 public void setDimension(Dimension value) 051 { 052 if (!dim.equals(value)) 053 { 054 final int w = value.width; 055 056 dim.setSize(w, value.height); 057 058 if (w > 32) 059 icon = ResourceUtil.getImageIcon(ResourceUtil.IMAGE_ICY_256, w); 060 else if (w > 16) 061 icon = ResourceUtil.getImageIcon(ResourceUtil.IMAGE_ICY_32, w); 062 else 063 icon = ResourceUtil.getImageIcon(ResourceUtil.IMAGE_ICY_16, w); 064 } 065 } 066 067 @Override 068 public int getIconHeight() 069 { 070 return dim.height; 071 } 072 073 @Override 074 public int getIconWidth() 075 { 076 return dim.width; 077 } 078 079 @Override 080 public void paintIcon(Component c, Graphics g, int x, int y) 081 { 082 icon.paintIcon(c, g, x, y); 083 } 084}