Better CTRL + Mouse Wheel Zoom
This adds mouse wheel zoom functionality onto all of the searchable text panes. This also fixes a scrolling bug.
This commit is contained in:
parent
1805df4c97
commit
18c0607c8e
2 changed files with 38 additions and 28 deletions
|
@ -15,7 +15,9 @@ import the.bytecode.club.bytecodeviewer.util.JTextAreaUtils;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseWheelListener;
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
||||||
|
@ -110,6 +112,9 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
||||||
|
|
||||||
GlobalHotKeys.keyPressed(keyEvent);
|
GlobalHotKeys.keyPressed(keyEvent);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
//attach CTRL + Mouse Wheel Zoom
|
||||||
|
SwingUtilities.invokeLater(this::attachCtrlMouseWheelZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
|
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
|
||||||
|
@ -122,6 +127,39 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
||||||
JTextAreaUtils.highlight(this, pattern, caseSensitiveSearch);
|
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) {
|
public String getLineText(int line) {
|
||||||
try {
|
try {
|
||||||
if (line < getLineCount()) {
|
if (line < getLineCount()) {
|
||||||
|
|
|
@ -174,34 +174,6 @@ public class BytecodeViewPanelUpdater implements Runnable
|
||||||
|
|
||||||
//this still freezes the swing UI
|
//this still freezes the swing UI
|
||||||
synchronizePane();
|
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()
|
public final CaretListener caretListener = new CaretListener()
|
||||||
|
|
Loading…
Reference in a new issue