1. /*
  2. * @(#)SynthIcon.java 1.6 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.gtk;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.border.Border;
  11. import javax.swing.plaf.UIResource;
  12. /**
  13. * An icon that is passed a SynthContext.
  14. *
  15. * @version 1.6, 01/23/03
  16. * @author Scott Violet
  17. */
  18. abstract class SynthIcon implements Icon {
  19. static int getIconWidth(Icon icon, SynthContext context) {
  20. if (icon == null) {
  21. return 0;
  22. }
  23. if (icon instanceof SynthIcon) {
  24. return ((SynthIcon)icon).getIconWidth(context);
  25. }
  26. return icon.getIconWidth();
  27. }
  28. static int getIconHeight(Icon icon, SynthContext context) {
  29. if (icon == null) {
  30. return 0;
  31. }
  32. if (icon instanceof SynthIcon) {
  33. return ((SynthIcon)icon).getIconHeight(context);
  34. }
  35. return icon.getIconHeight();
  36. }
  37. static void paintIcon(Icon icon, SynthContext context, Graphics g, int x,
  38. int y, int w, int h) {
  39. if (icon instanceof SynthIcon) {
  40. ((SynthIcon)icon).paintIcon(context, g, x, y, w, h);
  41. }
  42. else if (icon != null) {
  43. icon.paintIcon(context.getComponent(), g, x, y);
  44. }
  45. }
  46. /**
  47. * Paints the icon at the specified location.
  48. *
  49. * @param context Identifies hosting region, may be null.
  50. * @param x x location to paint to
  51. * @param y y location to paint to
  52. * @param w Width of the region to paint to, may be 0
  53. * @param h Height of the region to paint to, may be 0
  54. */
  55. public abstract void paintIcon(SynthContext context, Graphics g, int x,
  56. int y, int w, int h);
  57. /**
  58. * Returns the desired width of the Icon.
  59. *
  60. * @param context SynthContext requesting the Icon, may be null.
  61. * @return Desired width of the icon.
  62. */
  63. public abstract int getIconWidth(SynthContext context);
  64. /**
  65. * Returns the desired height of the Icon.
  66. *
  67. * @param context SynthContext requesting the Icon, may be null.
  68. * @return Desired height of the icon.
  69. */
  70. public abstract int getIconHeight(SynthContext context);
  71. /**
  72. * Paints the icon. This is a cover method for
  73. * <code>paintIcon(null, g, x, y, 0, 0)</code>
  74. */
  75. public void paintIcon(Component c, Graphics g, int x, int y) {
  76. paintIcon(null, g, x, y, 0, 0);
  77. }
  78. /**
  79. * Returns the icon's width. This is a cover methods for
  80. * <code>getIconWidth(null)</code>.
  81. *
  82. * @return an int specifying the fixed width of the icon.
  83. */
  84. public int getIconWidth() {
  85. return getIconWidth(null);
  86. }
  87. /**
  88. * Returns the icon's height. This is a cover method for
  89. * <code>getIconHeight(null)</code>.
  90. *
  91. * @return an int specifying the fixed height of the icon.
  92. */
  93. public int getIconHeight() {
  94. return getIconHeight(null);
  95. }
  96. }