Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/swing/plaf/synth/SynthIcon.java
38918 views
/*1* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.swing.plaf.synth;2526import javax.swing.plaf.synth.*;27import java.awt.*;28import javax.swing.*;29import javax.swing.border.Border;30import javax.swing.plaf.UIResource;3132/**33* An icon that is passed a SynthContext. Subclasses need only implement34* the variants that take a SynthContext, but must be prepared for the35* SynthContext to be null.36*37* @author Scott Violet38*/39public abstract class SynthIcon implements Icon {40public static int getIconWidth(Icon icon, SynthContext context) {41if (icon == null) {42return 0;43}44if (icon instanceof SynthIcon) {45return ((SynthIcon)icon).getIconWidth(context);46}47return icon.getIconWidth();48}4950public static int getIconHeight(Icon icon, SynthContext context) {51if (icon == null) {52return 0;53}54if (icon instanceof SynthIcon) {55return ((SynthIcon)icon).getIconHeight(context);56}57return icon.getIconHeight();58}5960public static void paintIcon(Icon icon, SynthContext context, Graphics g,61int x, int y, int w, int h) {62if (icon instanceof SynthIcon) {63((SynthIcon)icon).paintIcon(context, g, x, y, w, h);64}65else if (icon != null) {66icon.paintIcon(context.getComponent(), g, x, y);67}68}6970/**71* Paints the icon at the specified location.72*73* @param context Identifies hosting region, may be null.74* @param x x location to paint to75* @param y y location to paint to76* @param w Width of the region to paint to, may be 077* @param h Height of the region to paint to, may be 078*/79public abstract void paintIcon(SynthContext context, Graphics g, int x,80int y, int w, int h);8182/**83* Returns the desired width of the Icon.84*85* @param context SynthContext requesting the Icon, may be null.86* @return Desired width of the icon.87*/88public abstract int getIconWidth(SynthContext context);8990/**91* Returns the desired height of the Icon.92*93* @param context SynthContext requesting the Icon, may be null.94* @return Desired height of the icon.95*/96public abstract int getIconHeight(SynthContext context);9798/**99* Paints the icon. This is a cover method for100* <code>paintIcon(null, g, x, y, 0, 0)</code>101*/102public void paintIcon(Component c, Graphics g, int x, int y) {103paintIcon(null, g, x, y, 0, 0);104}105106/**107* Returns the icon's width. This is a cover methods for108* <code>getIconWidth(null)</code>.109*110* @return an int specifying the fixed width of the icon.111*/112public int getIconWidth() {113return getIconWidth(null);114}115116/**117* Returns the icon's height. This is a cover method for118* <code>getIconHeight(null)</code>.119*120* @return an int specifying the fixed height of the icon.121*/122public int getIconHeight() {123return getIconHeight(null);124}125}126127128