2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ui.plaf.gtk;
18 import com.intellij.Patches;
21 import javax.swing.plaf.synth.SynthContext;
22 import javax.swing.plaf.synth.SynthUI;
24 import java.lang.reflect.Method;
26 public class IconWrapper implements Icon {
27 private final Icon myIcon;
28 private final SynthUI myOriginalUI;
30 public IconWrapper(final Icon icon, final SynthUI originalUI) {
32 myOriginalUI = originalUI;
36 public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
37 if (Patches.USE_REFLECTION_TO_ACCESS_JDK7) {
39 Method paintIcon = myIcon.getClass().getMethod("paintIcon", SynthContext.class, Graphics.class, int.class, int.class, int.class, int.class);
40 paintIcon.setAccessible(true);
41 paintIcon.invoke(myIcon, myOriginalUI.getContext((JComponent)c), g, x, y, getIconWidth(), getIconHeight());
44 catch (Exception ignore) { }
46 myIcon.paintIcon(c, g, x, y);
50 public int getIconWidth() {
51 return myIcon.getIconWidth();
55 public int getIconHeight() {
56 return myIcon.getIconHeight();