This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 32099f6  Trivial refactoring: extract common variable
32099f6 is described below

commit 32099f637913d0a6d92e2ed1025f88ca786910cf
Author: Daniel Sun <[email protected]>
AuthorDate: Sat Jun 12 22:26:25 2021 +0800

    Trivial refactoring: extract common variable
---
 .../src/main/groovy/groovy/console/ui/ConsoleTextEditor.java      | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
index ae846c1..a7f4561 100644
--- 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
+++ 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleTextEditor.java
@@ -140,12 +140,14 @@ public class ConsoleTextEditor extends JScrollPane {
 
     private TextUndoManager undoManager;
 
+    private final Preferences preferences;
+
     /**
      * Creates a new instance of ConsoleTextEditor
      */
     public ConsoleTextEditor() {
-        textEditor.setFont(new Font(defaultFamily, Font.PLAIN,
-                       
Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12)));
+        preferences = Preferences.userNodeForPackage(Console.class);
+        textEditor.setFont(new Font(defaultFamily, Font.PLAIN, 
preferences.getInt("fontSize", 12)));
 
         setViewportView(new JPanel(new BorderLayout()) {{
             add(numbersPanel, BorderLayout.WEST);
@@ -165,7 +167,6 @@ public class ConsoleTextEditor extends JScrollPane {
         // add a document listener, to hint whether the line number gutter has 
to be repainted
         // when the number of lines changes
         doc.addDocumentListener(new DocumentListener() {
-            private Preferences preferences;
             private int width;
 
             @Override
@@ -181,7 +182,6 @@ public class ConsoleTextEditor extends JScrollPane {
             @Override
             public void changedUpdate(DocumentEvent documentEvent) {
                 documentChangedSinceLastRepaint = true;
-                if (null == preferences) preferences = 
Preferences.userNodeForPackage(Console.class);
                 int width = 3 * preferences.getInt("fontSize", 12);
                 if (width != this.width) {
                     this.width = width;

Reply via email to