blob: 66bbdab856bc3c1cac74916905f415aab42bbeef [file] [log] [blame]
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui.plaf.gtk;
import com.intellij.Patches;
import javax.swing.*;
import javax.swing.plaf.MenuItemUI;
import javax.swing.plaf.synth.SynthContext;
import java.awt.*;
import java.lang.reflect.Method;
public class IconWrapper implements Icon {
private final Icon myIcon;
private final MenuItemUI myOriginalUI;
public IconWrapper(final Icon icon, final MenuItemUI originalUI) {
myIcon = icon;
myOriginalUI = originalUI;
}
@Override
public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
if (Patches.USE_REFLECTION_TO_ACCESS_JDK7) {
try {
final Method paintIcon = myIcon.getClass().getMethod("paintIcon", SynthContext.class, Graphics.class,
int.class, int.class, int.class, int.class);
paintIcon.setAccessible(true);
paintIcon.invoke(myIcon, GtkPaintingUtil.getSynthContext(myOriginalUI, (JComponent)c), g, x, y, getIconWidth(), getIconHeight());
return;
}
catch (Exception ignore) { }
}
myIcon.paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return myIcon.getIconWidth();
}
@Override
public int getIconHeight() {
return myIcon.getIconHeight();
}
}