001 /* IconUIResource.java -- 002 Copyright (C) 2002, 2003, 2004, 2006, Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath 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 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.plaf; 040 041 import java.awt.Component; 042 import java.awt.Graphics; 043 import java.io.Serializable; 044 045 import javax.swing.Icon; 046 047 /** 048 * An icon that is marked as <code>UIResource</code>, which 049 * indicates that it has been installed by a pluggable 050 * LookAndFeel. Such icons are replaced when the LookAndFeel 051 * changes. 052 * 053 * @author Andrew Selkirk (aselkirk@sympatico.ca) 054 * @author Sascha Brawer (brawer@dandelis.ch) 055 */ 056 public class IconUIResource implements Icon, UIResource, Serializable 057 { 058 /** 059 * Verified using the <code>serialver</code> tool of Sun JDK 1.4.1_01 060 * on GNU/Linux 2.4.18. 061 */ 062 static final long serialVersionUID = 3327049506004830542L; 063 064 065 /** 066 * The icon that is wrapped by this <code>IconUIResource</code> (never 067 * <code>null</code>). 068 */ 069 private Icon delegate; 070 071 072 /** 073 * Constructs a <code>IconUIResource</code> that wraps another 074 * icon. All messages are forwarded to the delegate icon. 075 * 076 * @param delegate the icon that is wrapped by this 077 * <code>IconUIResource</code> (<code>null</code> not permitted). 078 */ 079 public IconUIResource(Icon delegate) 080 { 081 if (delegate == null) 082 throw new IllegalArgumentException("Null 'delegate' argument."); 083 this.delegate = delegate; 084 } 085 086 087 /** 088 * Paints the icon by asking the delegate icon to paint itself. 089 * 090 * @param c the Component whose icon is being painted. Some icons 091 * use this argument to retrieve properties like the 092 * background color. 093 * 094 * @param g the graphics into which the icon will be painted. 095 * 096 * @param x the horizontal position of the icon. 097 * 098 * @param y the vertical position of the icon. 099 */ 100 public void paintIcon(Component c, Graphics g, int x, int y) 101 { 102 delegate.paintIcon(c, g, x, y); 103 } 104 105 106 /** 107 * Returns the width of the icon in pixels. The implementation 108 * determines and returns the width of the delegate icon. 109 */ 110 public int getIconWidth() 111 { 112 return delegate.getIconWidth(); 113 } 114 115 116 /** 117 * Returns the height of the icon in pixels. The implementation 118 * determines and returns the height of the delegate icon. 119 */ 120 public int getIconHeight() 121 { 122 return delegate.getIconHeight(); 123 } 124 }