Skip to content

Commit

Permalink
provide proper arguments for created proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
denofevil committed Mar 21, 2017
1 parent 5f9a295 commit 668496e
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/main/java/com/chrisrm/idea/MTTabsPainterPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import com.intellij.util.messages.MessageBus;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;

/**
Expand Down Expand Up @@ -71,23 +69,23 @@ private void patchPainter(JBEditorTabs component) {
if (painter instanceof MTTabsPainter) return;

final MTTabsPainter tabsPainter = new MTTabsPainter(component);
final JBEditorTabsPainter proxy = (MTTabsPainter) Enhancer.create(MTTabsPainter.class, new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
final Object result = method.invoke(tabsPainter, objects);

if ("paintSelectionAndBorder".equals(method.getName())) {
final Graphics2D g2d = (Graphics2D) objects[0];
final Rectangle rect = (Rectangle) objects[1];
Enhancer e = new Enhancer();
e.setSuperclass(MTTabsPainter.class);
e.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
final Object result = method.invoke(tabsPainter, objects);

g2d.setColor(ColorUtil.fromHex("#" + properties.getProperty("material.tab.borderColor")));
g2d.fillRect(rect.x, rect.y + rect.height - 2, rect.width, 2);
}
if ("paintSelectionAndBorder".equals(method.getName())) {
final Graphics2D g2d = (Graphics2D) objects[0];
final Rectangle rect = (Rectangle) objects[1];

return result;
g2d.setColor(ColorUtil.fromHex("#" + properties.getProperty("material.tab.borderColor")));
g2d.fillRect(rect.x, rect.y + rect.height - 2, rect.width, 2);
}

return result;
});

final JBEditorTabsPainter proxy = (MTTabsPainter) e.create(new Class[] {JBEditorTabs.class}, new Object[] {component});
ReflectionUtil.setField(JBEditorTabs.class, component, JBEditorTabsPainter.class, "myDarkPainter", proxy);
}

Expand Down

1 comment on commit 668496e

@DotNetPart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.