1/*
2 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package javax.swing.plaf.synth;
26
27import java.awt.*;
28import javax.swing.*;
29
30/**
31 * An icon that is passed a {@code SynthContext}. Subclasses need only implement
32 * the variants that take a {@code SynthContext}, but must be prepared for the
33 * {@code SynthContext} to be null.
34 *
35 * @author Scott Violet
36 */
37public interface SynthIcon extends Icon {
38
39    /**
40     * Paints the icon at the specified location for the given synth context.
41     *
42     * @param context identifies hosting region, may be null.
43     * @param g the graphics context
44     * @param x the x location to paint to
45     * @param y the y location to paint to
46     * @param width the width of the region to paint to, may be 0
47     * @param height the height of the region to paint to, may be 0
48     */
49    void paintIcon(SynthContext context, Graphics g, int x, int y,
50            int width, int height);
51
52    /**
53     * Returns the icon's width for the given synth context.
54     *
55     * @param context {@code SynthContext} requesting the Icon, may be null.
56     * @return an int specifying the width of the icon.
57     */
58    int getIconWidth(SynthContext context);
59
60    /**
61     * Returns the icon's height for the given synth context.
62     *
63     * @param context {@code SynthContext} requesting the Icon, may be null.
64     * @return an int specifying the height of the icon.
65     */
66    int getIconHeight(SynthContext context);
67
68    @Override
69    default void paintIcon(Component c, Graphics g, int x, int y) {
70        paintIcon(null, g, x, y, getIconWidth(), getIconHeight());
71    }
72
73    @Override
74    default int getIconWidth() {
75        return getIconWidth(null);
76    }
77
78    @Override
79    default int getIconHeight() {
80        return getIconHeight(null);
81    }
82}
83