mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-72676 (access SynthUI via reflection for JDK7 compatibility)
This commit is contained in:
@@ -18,7 +18,6 @@ package com.intellij.ui.plaf.gtk;
|
||||
import com.intellij.openapi.actionSystem.impl.ActionMenuItem;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import sun.swing.plaf.synth.SynthUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.MenuItemUI;
|
||||
@@ -38,7 +37,7 @@ public class GtkMenuItemUI extends BasicMenuItemUI {
|
||||
}
|
||||
|
||||
public static boolean isUiAcceptable(final MenuItemUI ui) {
|
||||
return ui instanceof BasicMenuItemUI && ui instanceof SynthUI;
|
||||
return ui instanceof BasicMenuItemUI && GtkPaintingUtil.isSynthUI(ui);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +62,7 @@ public class GtkMenuItemUI extends BasicMenuItemUI {
|
||||
|
||||
private static Icon getCheckIconFromContext(final BasicMenuItemUI originalUI, final JCheckBoxMenuItem item) {
|
||||
if (myCachedCheckIcon == null) {
|
||||
final SynthContext context = ((SynthUI)originalUI).getContext(item);
|
||||
final SynthContext context = GtkPaintingUtil.getSynthContext(originalUI, item);
|
||||
myCachedCheckIcon = context.getStyle().getIcon(context, "CheckBoxMenuItem.checkIcon");
|
||||
}
|
||||
return myCachedCheckIcon;
|
||||
@@ -89,7 +88,7 @@ public class GtkMenuItemUI extends BasicMenuItemUI {
|
||||
disabledForeground = fg;
|
||||
}
|
||||
if (checkIcon != null && !(checkIcon instanceof IconWrapper) && !(checkIcon instanceof EmptyIcon)) {
|
||||
checkIcon = new IconWrapper(checkIcon, (SynthUI)myOriginalUI);
|
||||
checkIcon = new IconWrapper(checkIcon, myOriginalUI);
|
||||
}
|
||||
|
||||
super.update(g, c);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.ui.plaf.gtk;
|
||||
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import sun.swing.plaf.synth.SynthUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.MenuItemUI;
|
||||
@@ -32,7 +31,7 @@ public class GtkMenuUI extends BasicMenuUI {
|
||||
}
|
||||
|
||||
public static boolean isUiAcceptable(final MenuItemUI ui) {
|
||||
return ui instanceof BasicMenuUI && ui instanceof SynthUI;
|
||||
return ui instanceof BasicMenuUI && GtkPaintingUtil.isSynthUI(ui);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,7 +46,7 @@ public class GtkMenuUI extends BasicMenuUI {
|
||||
@Override
|
||||
public void update(final Graphics g, final JComponent c) {
|
||||
if (arrowIcon != null && !(arrowIcon instanceof IconWrapper)) {
|
||||
arrowIcon = new IconWrapper(arrowIcon, (SynthUI)myOriginalUI);
|
||||
arrowIcon = new IconWrapper(arrowIcon, myOriginalUI);
|
||||
}
|
||||
super.update(g, c);
|
||||
}
|
||||
|
||||
@@ -17,19 +17,24 @@ package com.intellij.ui.plaf.gtk;
|
||||
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.swing.plaf.synth.SynthUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.MenuItemUI;
|
||||
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
import javax.swing.plaf.synth.SynthContext;
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
// todo[r.sh] get rid of SynthUI reflection after migration to JDK 7
|
||||
public class GtkPaintingUtil {
|
||||
private static final String V6_SYNTH_UI_CLASS = "sun.swing.plaf.synth.SynthUI";
|
||||
private static final String V7_SYNTH_UI_CLASS = "javax.swing.plaf.synth.SynthUI";
|
||||
|
||||
private GtkPaintingUtil() { }
|
||||
|
||||
public static Color getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem) {
|
||||
final SynthContext context = ((SynthUI)ui).getContext(menuItem);
|
||||
final SynthContext context = getSynthContext(ui, menuItem);
|
||||
return context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND);
|
||||
}
|
||||
|
||||
@@ -49,4 +54,27 @@ public class GtkPaintingUtil {
|
||||
g.setColor(fg);
|
||||
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, index, textRect.x, textRect.y + fm.getAscent());
|
||||
}
|
||||
|
||||
public static boolean isSynthUI(final MenuItemUI ui) {
|
||||
final Class<?>[] interfaces = ui.getClass().getInterfaces();
|
||||
for (int i = 0, length = interfaces.length; i < length; i++) {
|
||||
final Class<?> anInterface = interfaces[i];
|
||||
if (V6_SYNTH_UI_CLASS.equals(anInterface.getName()) || V7_SYNTH_UI_CLASS.equals(anInterface.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SynthContext getSynthContext(final MenuItemUI ui, final JComponent item) {
|
||||
try {
|
||||
final Method getContext = ui.getClass().getMethod("getContext", JComponent.class);
|
||||
getContext.setAccessible(true);
|
||||
return (SynthContext)getContext.invoke(ui, item);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,17 @@
|
||||
*/
|
||||
package com.intellij.ui.plaf.gtk;
|
||||
|
||||
import sun.swing.plaf.synth.SynthUI;
|
||||
|
||||
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 SynthUI myOriginalUI;
|
||||
private final MenuItemUI myOriginalUI;
|
||||
|
||||
public IconWrapper(final Icon icon, final SynthUI originalUI) {
|
||||
public IconWrapper(final Icon icon, final MenuItemUI originalUI) {
|
||||
myIcon = icon;
|
||||
myOriginalUI = originalUI;
|
||||
}
|
||||
@@ -37,7 +36,7 @@ public class IconWrapper implements Icon {
|
||||
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, myOriginalUI.getContext((JComponent)c), g, x, y, getIconWidth(), getIconHeight());
|
||||
paintIcon.invoke(myIcon, GtkPaintingUtil.getSynthContext(myOriginalUI, (JComponent)c), g, x, y, getIconWidth(), getIconHeight());
|
||||
return;
|
||||
}
|
||||
catch (Exception ignore) { }
|
||||
|
||||
Reference in New Issue
Block a user