Skip to content

Commit 388822a

Browse files
committed
Implement font increse/decrease with CTRL+MouseWheel
1 parent c07f8fc commit 388822a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

app/src/processing/app/EditorTab.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import java.awt.Font;
3131
import java.awt.event.ActionEvent;
3232
import java.awt.event.ActionListener;
33+
import java.awt.event.MouseWheelListener;
34+
import java.awt.event.MouseWheelEvent;
35+
3336
import java.io.IOException;
3437

3538
import javax.swing.Action;
@@ -64,7 +67,7 @@
6467
/**
6568
* Single tab, editing a single file, in the main window.
6669
*/
67-
public class EditorTab extends JPanel implements SketchFile.TextStorage {
70+
public class EditorTab extends JPanel implements SketchFile.TextStorage, MouseWheelListener {
6871
protected Editor editor;
6972
protected SketchTextArea textarea;
7073
protected RTextScrollPane scrollPane;
@@ -106,6 +109,7 @@ public EditorTab(Editor editor, SketchFile file, String contents)
106109
file.setStorage(this);
107110
applyPreferences();
108111
add(scrollPane, BorderLayout.CENTER);
112+
textarea.addMouseWheelListener(this);
109113
}
110114

111115
private RSyntaxDocument createDocument(String contents) {
@@ -178,6 +182,18 @@ private SketchTextArea createTextArea(RSyntaxDocument document)
178182
return textArea;
179183
}
180184

185+
public void mouseWheelMoved(MouseWheelEvent e) {
186+
if (e.isControlDown()) {
187+
if (e.getWheelRotation() < 0) {
188+
editor.base.handleFontSizeChange(1);
189+
} else {
190+
editor.base.handleFontSizeChange(-1);
191+
}
192+
} else {
193+
e.getComponent().getParent().dispatchEvent(e);
194+
}
195+
}
196+
181197
private void configurePopupMenu(final SketchTextArea textarea){
182198

183199
JPopupMenu menu = textarea.getPopupMenu();

0 commit comments

Comments
 (0)