From 04a7e7ff159f1e797a05308f0028a1b94f04f4ed Mon Sep 17 00:00:00 2001 From: Michael G Date: Sun, 18 Jun 2017 19:10:06 +1000 Subject: [PATCH 1/3] Add font size shortcuts (menu and keyboard) --- app/src/processing/app/Base.java | 11 +++++++++++ app/src/processing/app/Editor.java | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c930cc85f..8c772de8f 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1839,6 +1839,17 @@ public class Base { dialog.setVisible(true); } + /** + * Adjust font size + */ + public void handleFontSizeChange(int change) { + String pieces[] = PApplet.split(PreferencesData.get("editor.font"), ','); + int newSize = Integer.parseInt(pieces[2]) + change; + pieces[2] = String.valueOf(newSize); + PreferencesData.set("editor.font", PApplet.join(pieces, ',')); + this.getEditors().forEach(processing.app.Editor::applyPreferences); + } + // XXX: Remove this method and make librariesIndexer non-static static public LibraryList getLibraries() { return BaseNoGui.librariesIndexer.getInstalledLibraries(); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index e68ca4778..7064f2844 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1374,6 +1374,24 @@ public class Editor extends JFrame implements RunnerListener { menu.addSeparator(); + JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), '='); + increaseFontSizeItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + base.handleFontSizeChange(1); + } + }); + menu.add(increaseFontSizeItem); + + JMenuItem decreaseFontSizeItem = newJMenuItem(tr("Decrease Font Size"), '-'); + decreaseFontSizeItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + base.handleFontSizeChange(-1); + } + }); + menu.add(decreaseFontSizeItem); + + menu.addSeparator(); + JMenuItem findItem = newJMenuItem(tr("Find..."), 'F'); findItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { From c07f8fca54c06a910df45b390b4d3e69433d842c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 25 Jul 2017 14:57:21 +0200 Subject: [PATCH 2/3] Use CTRL+"+" as Increase Font shortcut --- app/src/processing/app/Editor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 7064f2844..4d2be279f 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1374,7 +1374,7 @@ public class Editor extends JFrame implements RunnerListener { menu.addSeparator(); - JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), '='); + JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), '+'); increaseFontSizeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { base.handleFontSizeChange(1); From 388822ad95dd91033f9194d9a770eb90710df6df Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 25 Jul 2017 14:58:10 +0200 Subject: [PATCH 3/3] Implement font increse/decrease with CTRL+MouseWheel --- app/src/processing/app/EditorTab.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index eab701d80..33dabdbbb 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -30,6 +30,9 @@ import java.awt.BorderLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseWheelListener; +import java.awt.event.MouseWheelEvent; + import java.io.IOException; import javax.swing.Action; @@ -64,7 +67,7 @@ import processing.app.tools.DiscourseFormat; /** * Single tab, editing a single file, in the main window. */ -public class EditorTab extends JPanel implements SketchFile.TextStorage { +public class EditorTab extends JPanel implements SketchFile.TextStorage, MouseWheelListener { protected Editor editor; protected SketchTextArea textarea; protected RTextScrollPane scrollPane; @@ -106,6 +109,7 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage { file.setStorage(this); applyPreferences(); add(scrollPane, BorderLayout.CENTER); + textarea.addMouseWheelListener(this); } private RSyntaxDocument createDocument(String contents) { @@ -178,6 +182,18 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage { return textArea; } + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.isControlDown()) { + if (e.getWheelRotation() < 0) { + editor.base.handleFontSizeChange(1); + } else { + editor.base.handleFontSizeChange(-1); + } + } else { + e.getComponent().getParent().dispatchEvent(e); + } + } + private void configurePopupMenu(final SketchTextArea textarea){ JPopupMenu menu = textarea.getPopupMenu();