-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gui): on mouse hover highlight identifiers with enabled actions …
…(like 'find usage' or 'rename')
- Loading branch information
Showing
4 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package jadx.gui.ui.codearea; | ||
|
||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseMotionAdapter; | ||
|
||
import javax.swing.text.Highlighter; | ||
|
||
import org.fife.ui.rsyntaxtextarea.Token; | ||
import org.fife.ui.rsyntaxtextarea.TokenTypes; | ||
import org.fife.ui.rtextarea.SmartHighlightPainter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import jadx.gui.utils.JumpPosition; | ||
|
||
class MouseHoverHighlighter extends MouseMotionAdapter { | ||
private static final Logger LOG = LoggerFactory.getLogger(MouseHoverHighlighter.class); | ||
|
||
private final CodeArea codeArea; | ||
private final CodeLinkGenerator codeLinkGenerator; | ||
private final Highlighter.HighlightPainter highlighter; | ||
|
||
private boolean added; | ||
|
||
public MouseHoverHighlighter(CodeArea codeArea, CodeLinkGenerator codeLinkGenerator) { | ||
this.codeArea = codeArea; | ||
this.codeLinkGenerator = codeLinkGenerator; | ||
this.highlighter = new SmartHighlightPainter(codeArea.getMarkOccurrencesColor()); | ||
} | ||
|
||
@Override | ||
public void mouseMoved(MouseEvent e) { | ||
Highlighter highlighter = codeArea.getHighlighter(); | ||
if (added) { | ||
highlighter.removeAllHighlights(); | ||
added = false; | ||
} | ||
if (e.getModifiersEx() != 0) { | ||
return; | ||
} | ||
try { | ||
Token token = codeArea.viewToToken(e.getPoint()); | ||
if (token == null || token.getType() != TokenTypes.IDENTIFIER) { | ||
return; | ||
} | ||
JumpPosition jump = codeLinkGenerator.getJumpLinkAtOffset(codeArea, token.getOffset()); | ||
if (jump == null) { | ||
return; | ||
} | ||
highlighter.removeAllHighlights(); | ||
highlighter.addHighlight(token.getOffset(), token.getEndOffset(), this.highlighter); | ||
added = true; | ||
} catch (Exception exc) { | ||
LOG.error("Mouse hover highlight error", exc); | ||
} | ||
} | ||
} |