Skip to content

Commit

Permalink
BackCompatibleUtils: get rid of old reflection code
Browse files Browse the repository at this point in the history
Focusing of the hyperlink works without this code in modern IDEs.
  • Loading branch information
ForNeVeR committed Dec 28, 2022
1 parent 1ece87c commit f3dc986
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

package com.microsoft.alm.plugin.idea.common.ui.controls;

import com.intellij.ui.JBColor;
import com.intellij.ui.components.labels.LinkLabel;
import com.intellij.ui.components.labels.LinkListener;
import com.microsoft.alm.plugin.idea.common.utils.BackCompatibleUtils;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -60,27 +56,6 @@ protected void processComponentKeyEvent(final KeyEvent e) {
}
}

/**
* We are overriding this method to force a repaint of the control when the focus changes.
*/
@Override
protected void processFocusEvent(final FocusEvent e) {
super.processFocusEvent(e);
super.repaint();
}

/**
* We are overriding this method to paint a focus rectangle around the control.
*/
@Override
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
if (hasFocus()) {
g.setColor(JBColor.black);
BackCompatibleUtils.paintFocusRing(g, 0, 0, getWidth(), getHeight());
}
}

private void notifyActionListeners() {
if (listeners == null || listeners.size() == 0 || !super.isEnabled()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

package com.microsoft.alm.plugin.idea.common.utils;

import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
import com.intellij.util.net.HttpConfigurable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

Expand Down Expand Up @@ -45,30 +42,4 @@ public static String getProxyLogin() {
}
}
}

/**
* Executing the DarculaUIUtil.paintFocusRing() method independent of the IDEA version we are on
*
* @param g
* @param x
* @param y
* @param width
* @param height
*/
public static void paintFocusRing(final Graphics g, final int x, final int y, final int width, final int height) {
try {
// trying to paint focus using the IDEA 2017 method
final Method paintFocusRingMethodNew = DarculaUIUtil.class.getDeclaredMethod("paintFocusRing", Graphics.class, Rectangle.class);
paintFocusRingMethodNew.invoke(null, g, new Rectangle(x, y, width, height));
} catch (Exception newImplementationException) {
try {
logger.warn("Failed to get DarculaUIUtil.paintFocusRing() new implementation so attempting old way", newImplementationException);
final Method paintFocusRingMethodOld = DarculaUIUtil.class.getDeclaredMethod("paintFocusRing", Graphics.class,
Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE);
paintFocusRingMethodOld.invoke(null, g, x, y, width, height);
} catch (Exception oldImplementationException) {
logger.warn("Failed to find DarculaUIUtil.paintFocusRing() method", oldImplementationException);
}
}
}
}

0 comments on commit f3dc986

Please sign in to comment.