1. /*
  2. * @(#)IconUIResource.java 1.14 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf;
  8. import java.awt.Component;
  9. import java.awt.Graphics;
  10. import java.io.Serializable;
  11. import javax.swing.Icon;
  12. import javax.swing.plaf.UIResource;
  13. /*
  14. * An Icon wrapper class which implements UIResource. UI
  15. * classes which set icon properties should use this class
  16. * to wrap any icons specified as defaults.
  17. *
  18. * This class delegates all method invocations to the
  19. * Icon "delegate" object specified at construction.
  20. * <p>
  21. * <strong>Warning:</strong>
  22. * Serialized objects of this class will not be compatible with
  23. * future Swing releases. The current serialization support is
  24. * appropriate for short term storage or RMI between applications running
  25. * the same version of Swing. As of 1.4, support for long term storage
  26. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  27. * has been added to the <code>java.beans</code> package.
  28. * Please see {@link java.beans.XMLEncoder}.
  29. *
  30. * @see javax.swing.plaf.UIResource
  31. * @version 1.14 12/19/03
  32. * @author Amy Fowler
  33. *
  34. */
  35. public class IconUIResource implements Icon, UIResource, Serializable
  36. {
  37. private Icon delegate;
  38. /**
  39. * Creates a UIResource icon object which wraps
  40. * an existing Icon instance.
  41. * @param delegate the icon being wrapped
  42. */
  43. public IconUIResource(Icon delegate) {
  44. if (delegate == null) {
  45. throw new IllegalArgumentException("null delegate icon argument");
  46. }
  47. this.delegate = delegate;
  48. }
  49. public void paintIcon(Component c, Graphics g, int x, int y) {
  50. delegate.paintIcon(c, g, x, y);
  51. }
  52. public int getIconWidth() {
  53. return delegate.getIconWidth();
  54. }
  55. public int getIconHeight() {
  56. return delegate.getIconHeight();
  57. }
  58. }