Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
107 additions
and 0 deletions.
- +3 −0 jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java
- +3 −0 jadx-gui/src/main/java/jadx/gui/ui/panel/HtmlPanel.java
- +3 −0 jadx-gui/src/main/java/jadx/gui/utils/FontUtils.java
- +20 −0 jadx-gui/src/main/java/jadx/gui/utils/ui/ActionHandler.java
- +78 −0 jadx-gui/src/main/java/jadx/gui/utils/ui/ZoomActions.java
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
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
| @@ -0,0 +1,20 @@ | ||
| package jadx.gui.utils.ui; | ||
|
|
||
| import java.awt.event.ActionEvent; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import javax.swing.AbstractAction; | ||
|
|
||
| public class ActionHandler extends AbstractAction { | ||
|
|
||
| private final Consumer<ActionEvent> consumer; | ||
|
|
||
| public ActionHandler(Consumer<ActionEvent> consumer) { | ||
| this.consumer = consumer; | ||
| } | ||
|
|
||
| @Override | ||
| public void actionPerformed(ActionEvent e) { | ||
| consumer.accept(e); | ||
| } | ||
| } |
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
| @@ -0,0 +1,78 @@ | ||
| package jadx.gui.utils.ui; | ||
|
|
||
| import java.awt.Container; | ||
| import java.awt.Font; | ||
| import java.awt.event.KeyEvent; | ||
|
|
||
| import javax.swing.ActionMap; | ||
| import javax.swing.InputMap; | ||
| import javax.swing.JComponent; | ||
| import javax.swing.KeyStroke; | ||
|
|
||
| import jadx.gui.settings.JadxSettings; | ||
| import jadx.gui.utils.UiUtils; | ||
|
|
||
| public class ZoomActions { | ||
| private final JComponent component; | ||
| private final JadxSettings settings; | ||
| private final Runnable update; | ||
|
|
||
| public static void register(JComponent component, JadxSettings settings, Runnable update) { | ||
| ZoomActions actions = new ZoomActions(component, settings, update); | ||
| actions.register(); | ||
| } | ||
|
|
||
| private ZoomActions(JComponent component, JadxSettings settings, Runnable update) { | ||
| this.component = component; | ||
| this.settings = settings; | ||
| this.update = update; | ||
| } | ||
|
|
||
| private void register() { | ||
| String zoomIn = "TextZoomIn"; | ||
| String zoomOut = "TextZoomOut"; | ||
| int ctrlButton = UiUtils.ctrlButton(); | ||
| InputMap inputMap = component.getInputMap(); | ||
| inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, ctrlButton), zoomIn); | ||
| inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ctrlButton), zoomIn); | ||
| inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, ctrlButton), zoomIn); | ||
| inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ctrlButton), zoomOut); | ||
| inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, ctrlButton), zoomOut); | ||
| ActionMap actionMap = component.getActionMap(); | ||
| actionMap.put(zoomIn, new ActionHandler(e -> textZoom(1))); | ||
| actionMap.put(zoomOut, new ActionHandler(e -> textZoom(-1))); | ||
|
|
||
| component.addMouseWheelListener(e -> { | ||
| if (e.getModifiersEx() == UiUtils.ctrlButton()) { | ||
| textZoom(e.getWheelRotation() < 0 ? 1 : -1); | ||
| e.consume(); | ||
| } else { | ||
| // pass event to parent component, needed for scroll in JScrollPane | ||
| Container parent = component.getParent(); | ||
| if (parent != null) { | ||
| parent.dispatchEvent(e); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void textZoom(int change) { | ||
| Font font = settings.getFont(); | ||
| if (component.getFont().equals(font)) { | ||
| settings.setFont(changeFontSize(font, change)); | ||
| } else { | ||
| settings.setSmaliFont(changeFontSize(settings.getSmaliFont(), change)); | ||
| } | ||
| settings.sync(); | ||
| update.run(); | ||
| } | ||
|
|
||
| private Font changeFontSize(Font font, int change) { | ||
| float newSize = font.getSize() + change; | ||
| if (newSize < 2) { | ||
| // ignore change | ||
| return font; | ||
| } | ||
| return font.deriveFont(newSize); | ||
| } | ||
| } |