Mouse Wheel Zoom On All Scrollable Windows
Plugin Writer, Consoles and the Hex-Viewer can now be zoomed in/out and support font control
This commit is contained in:
parent
30bf371101
commit
605721b378
3 changed files with 115 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
package the.bytecode.club.bytecodeviewer.gui.components;
|
||||
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.GlobalHotKeys;
|
||||
import the.bytecode.club.bytecodeviewer.resources.IconResources;
|
||||
import the.bytecode.club.bytecodeviewer.gui.components.listeners.PressKeyListener;
|
||||
|
@ -10,7 +11,9 @@ import the.bytecode.club.bytecodeviewer.util.JTextAreaUtils;
|
|||
|
||||
import javax.swing.*;
|
||||
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 *
|
||||
|
@ -78,6 +81,19 @@ public class SearchableJTextArea extends JTextArea
|
|||
|
||||
GlobalHotKeys.keyPressed(keyEvent);
|
||||
}));
|
||||
|
||||
final Font newFont = getFont().deriveFont((float) BytecodeViewer.viewer.getFontSize());
|
||||
|
||||
//set number-bar font
|
||||
setFont(newFont);
|
||||
|
||||
SwingUtilities.invokeLater(()-> {
|
||||
//attach CTRL + Mouse Wheel Zoom
|
||||
attachCtrlMouseWheelZoom();
|
||||
|
||||
//set text font
|
||||
setFont(newFont);
|
||||
});
|
||||
}
|
||||
|
||||
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
|
||||
|
@ -90,6 +106,41 @@ public class SearchableJTextArea extends JTextArea
|
|||
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));
|
||||
|
||||
e.consume();
|
||||
}
|
||||
else if(ogListener != null)
|
||||
{
|
||||
ogListener.mouseWheelMoved(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JScrollPane getScrollPane()
|
||||
{
|
||||
return scrollPane;
|
||||
|
|
|
@ -2,6 +2,7 @@ package the.bytecode.club.bytecodeviewer.gui.components;
|
|||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rtextarea.RTextScrollPane;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||
import the.bytecode.club.bytecodeviewer.GlobalHotKeys;
|
||||
import the.bytecode.club.bytecodeviewer.resources.IconResources;
|
||||
|
@ -58,15 +59,7 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
|||
|
||||
public SearchableRSyntaxTextArea()
|
||||
{
|
||||
if(Configuration.lafTheme == LAFTheme.DARK || Configuration.lafTheme == LAFTheme.SOLARIZED_DARK)
|
||||
{
|
||||
//this fixes the white border on the jScrollBar panes
|
||||
scrollPane.getHorizontalScrollBar().setBackground(darkScrollBackground);
|
||||
scrollPane.getHorizontalScrollBar().setForeground(darkScrollForeground);
|
||||
scrollPane.getVerticalScrollBar().setBackground(darkScrollBackground);
|
||||
scrollPane.getVerticalScrollBar().setForeground(darkScrollForeground);
|
||||
}
|
||||
else if(Configuration.lafTheme == LAFTheme.HIGH_CONTRAST_DARK)
|
||||
if(Configuration.lafTheme == LAFTheme.HIGH_CONTRAST_DARK)
|
||||
{
|
||||
//this fixes the white border on the jScrollBar panes
|
||||
scrollPane.getHorizontalScrollBar().setBackground(blackScrollBackground);
|
||||
|
@ -74,6 +67,14 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
|||
scrollPane.getVerticalScrollBar().setBackground(blackScrollBackground);
|
||||
scrollPane.getVerticalScrollBar().setForeground(blackScrollForeground);
|
||||
}
|
||||
else if(Configuration.lafTheme.isDark())
|
||||
{
|
||||
//this fixes the white border on the jScrollBar panes
|
||||
scrollPane.getHorizontalScrollBar().setBackground(darkScrollBackground);
|
||||
scrollPane.getHorizontalScrollBar().setForeground(darkScrollForeground);
|
||||
scrollPane.getVerticalScrollBar().setBackground(darkScrollBackground);
|
||||
scrollPane.getVerticalScrollBar().setForeground(darkScrollForeground);
|
||||
}
|
||||
|
||||
setAntiAliasingEnabled(true);
|
||||
|
||||
|
@ -113,8 +114,19 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
|
|||
GlobalHotKeys.keyPressed(keyEvent);
|
||||
}));
|
||||
|
||||
//attach CTRL + Mouse Wheel Zoom
|
||||
SwingUtilities.invokeLater(this::attachCtrlMouseWheelZoom);
|
||||
final Font newFont = getFont().deriveFont((float) BytecodeViewer.viewer.getFontSize());
|
||||
|
||||
//set number-bar font
|
||||
setFont(newFont);
|
||||
|
||||
SwingUtilities.invokeLater(()-> {
|
||||
//attach CTRL + Mouse Wheel Zoom
|
||||
attachCtrlMouseWheelZoom();
|
||||
|
||||
//set text font
|
||||
setFont(newFont);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
|
||||
|
|
|
@ -9,13 +9,7 @@ import java.awt.Font;
|
|||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
|
@ -82,6 +76,9 @@ public class JHexEditor extends JPanel implements FocusListener, AdjustmentListe
|
|||
|
||||
this.setLayout(new BorderLayout(1, 1));
|
||||
this.add(panel, BorderLayout.CENTER);
|
||||
|
||||
//attach CTRL + Mouse Wheel Zoom
|
||||
SwingUtilities.invokeLater(this::attachCtrlMouseWheelZoom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,6 +101,43 @@ public class JHexEditor extends JPanel implements FocusListener, AdjustmentListe
|
|||
super.paint(g);
|
||||
}
|
||||
|
||||
public void attachCtrlMouseWheelZoom()
|
||||
{
|
||||
//get the existing scroll event
|
||||
MouseWheelListener ogListener = getMouseWheelListeners().length > 0 ?
|
||||
getMouseWheelListeners()[0] : null;
|
||||
|
||||
//remove the existing event
|
||||
if(ogListener != null)
|
||||
removeMouseWheelListener(ogListener);
|
||||
|
||||
//add a new event
|
||||
addMouseWheelListener(e ->
|
||||
{
|
||||
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0)
|
||||
{
|
||||
int size = font.getSize();
|
||||
|
||||
Font newFont;
|
||||
if (e.getWheelRotation() > 0) //Up
|
||||
newFont = new Font(font.getName(), font.getStyle(), --size >= 2 ? --size : 2);
|
||||
else //Down
|
||||
newFont = new Font(font.getName(), font.getStyle(), ++size);
|
||||
|
||||
setFont(newFont);
|
||||
hex.setFont(newFont);
|
||||
ascii.setFont(newFont);
|
||||
font = newFont;
|
||||
|
||||
e.consume();
|
||||
}
|
||||
else if(ogListener != null)
|
||||
{
|
||||
ogListener.mouseWheelMoved(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected int getInicio() {
|
||||
return inicio;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue