diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java index 54c51792..972722b2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java @@ -15,7 +15,9 @@ import the.bytecode.club.bytecodeviewer.util.JTextAreaUtils; import javax.swing.*; import javax.swing.text.BadLocationException; import java.awt.*; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.awt.event.MouseWheelListener; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -110,6 +112,9 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea GlobalHotKeys.keyPressed(keyEvent); })); + + //attach CTRL + Mouse Wheel Zoom + SwingUtilities.invokeLater(this::attachCtrlMouseWheelZoom); } public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch) @@ -122,6 +127,39 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea JTextAreaUtils.highlight(this, pattern, caseSensitiveSearch); } + public void attachCtrlMouseWheelZoom() + { + //get the existing scroll event + MouseWheelListener ogListener = scrollPane.getMouseWheelListeners().length > 0 ? + scrollPane.getMouseWheelListeners()[0] : null; + + //remove the existing event + if(ogListener != null) + scrollPane.removeMouseWheelListener(ogListener); + + //add a new event + scrollPane.addMouseWheelListener(e -> + { + if (getText().isEmpty()) + return; + + if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) + { + Font font = getFont(); + int size = font.getSize(); + + if (e.getWheelRotation() > 0) //Up + setFont(new Font(font.getName(), font.getStyle(), --size >= 2 ? --size : 2)); + else //Down + setFont(new Font(font.getName(), font.getStyle(), ++size)); + } + else if(ogListener != null) + { + ogListener.mouseWheelMoved(e); + } + }); + } + public String getLineText(int line) { try { if (line < getLineCount()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index 722b4610..b7f8dfd0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -174,34 +174,6 @@ public class BytecodeViewPanelUpdater implements Runnable //this still freezes the swing UI synchronizePane(); - - //attach CTRL + Mouse Wheel Zoom - SwingUtilities.invokeLater(()-> - attachCtrlMouseWheelZoom(updateUpdaterTextArea.getScrollPane(), updateUpdaterTextArea)); - } - - public void attachCtrlMouseWheelZoom(RTextScrollPane scrollPane, RSyntaxTextArea panelArea) - { - if (scrollPane == null) - return; - - scrollPane.addMouseWheelListener(e -> - { - if (panelArea == null || panelArea.getText().isEmpty()) - return; - - if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) - { - Font font = panelArea.getFont(); - int size = font.getSize(); - - if (e.getWheelRotation() > 0) //Up - panelArea.setFont(new Font(font.getName(), font.getStyle(), --size >= 2 ? --size : 2)); - else //Down - panelArea.setFont(new Font(font.getName(), font.getStyle(), ++size)); - } - e.consume(); - }); } public final CaretListener caretListener = new CaretListener()