J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | package sun.swing.plaf.synth; |
| 26 | |
| 27 | import javax.swing.plaf.synth.*; |
| 28 | import java.awt.*; |
| 29 | import javax.swing.*; |
| 30 | import javax.swing.border.Border; |
| 31 | import javax.swing.plaf.UIResource; |
| 32 | |
| 33 | /** |
| 34 | * An icon that is passed a SynthContext. Subclasses need only implement |
| 35 | * the variants that take a SynthContext, but must be prepared for the |
| 36 | * SynthContext to be null. |
| 37 | * |
| 38 | * @author Scott Violet |
| 39 | */ |
| 40 | public abstract class SynthIcon implements Icon { |
| 41 | public static int getIconWidth(Icon icon, SynthContext context) { |
| 42 | if (icon == null) { |
| 43 | return 0; |
| 44 | } |
| 45 | if (icon instanceof SynthIcon) { |
| 46 | return ((SynthIcon)icon).getIconWidth(context); |
| 47 | } |
| 48 | return icon.getIconWidth(); |
| 49 | } |
| 50 | |
| 51 | public static int getIconHeight(Icon icon, SynthContext context) { |
| 52 | if (icon == null) { |
| 53 | return 0; |
| 54 | } |
| 55 | if (icon instanceof SynthIcon) { |
| 56 | return ((SynthIcon)icon).getIconHeight(context); |
| 57 | } |
| 58 | return icon.getIconHeight(); |
| 59 | } |
| 60 | |
| 61 | public static void paintIcon(Icon icon, SynthContext context, Graphics g, |
| 62 | int x, int y, int w, int h) { |
| 63 | if (icon instanceof SynthIcon) { |
| 64 | ((SynthIcon)icon).paintIcon(context, g, x, y, w, h); |
| 65 | } |
| 66 | else if (icon != null) { |
| 67 | icon.paintIcon(context.getComponent(), g, x, y); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Paints the icon at the specified location. |
| 73 | * |
| 74 | * @param context Identifies hosting region, may be null. |
| 75 | * @param x x location to paint to |
| 76 | * @param y y location to paint to |
| 77 | * @param w Width of the region to paint to, may be 0 |
| 78 | * @param h Height of the region to paint to, may be 0 |
| 79 | */ |
| 80 | public abstract void paintIcon(SynthContext context, Graphics g, int x, |
| 81 | int y, int w, int h); |
| 82 | |
| 83 | /** |
| 84 | * Returns the desired width of the Icon. |
| 85 | * |
| 86 | * @param context SynthContext requesting the Icon, may be null. |
| 87 | * @return Desired width of the icon. |
| 88 | */ |
| 89 | public abstract int getIconWidth(SynthContext context); |
| 90 | |
| 91 | /** |
| 92 | * Returns the desired height of the Icon. |
| 93 | * |
| 94 | * @param context SynthContext requesting the Icon, may be null. |
| 95 | * @return Desired height of the icon. |
| 96 | */ |
| 97 | public abstract int getIconHeight(SynthContext context); |
| 98 | |
| 99 | /** |
| 100 | * Paints the icon. This is a cover method for |
| 101 | * <code>paintIcon(null, g, x, y, 0, 0)</code> |
| 102 | */ |
| 103 | public void paintIcon(Component c, Graphics g, int x, int y) { |
| 104 | paintIcon(null, g, x, y, 0, 0); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the icon's width. This is a cover methods for |
| 109 | * <code>getIconWidth(null)</code>. |
| 110 | * |
| 111 | * @return an int specifying the fixed width of the icon. |
| 112 | */ |
| 113 | public int getIconWidth() { |
| 114 | return getIconWidth(null); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the icon's height. This is a cover method for |
| 119 | * <code>getIconHeight(null)</code>. |
| 120 | * |
| 121 | * @return an int specifying the fixed height of the icon. |
| 122 | */ |
| 123 | public int getIconHeight() { |
| 124 | return getIconHeight(null); |
| 125 | } |
| 126 | } |