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

grobmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-chainsaw.git


The following commit(s) were added to refs/heads/master by this push:
     new 2be895d   extracted log panel builder (ugly version)
2be895d is described below

commit 2be895d754c318d950e887c804f65a0dc52e8f7a
Author: Christian Grobmeier <[email protected]>
AuthorDate: Sun Dec 17 16:08:03 2023 +0100

     extracted log panel builder (ugly version)
---
 .../org/apache/log4j/chainsaw/logui/LogUI.java     |  85 +-----------
 .../log4j/chainsaw/logui/LogUIPanelBuilder.java    | 145 +++++++++++++++++++++
 2 files changed, 151 insertions(+), 79 deletions(-)

diff --git a/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java 
b/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java
index 964d480..840da2f 100644
--- a/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java
@@ -22,7 +22,6 @@ import 
org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.log4j.chainsaw.*;
 import org.apache.log4j.chainsaw.color.RuleColorizer;
 import org.apache.log4j.chainsaw.components.elements.SmallButton;
-import org.apache.log4j.chainsaw.components.elements.TabIconHandler;
 import org.apache.log4j.chainsaw.components.logpanel.LogPanel;
 import org.apache.log4j.chainsaw.components.tabbedpane.ChainsawTabbedPane;
 import org.apache.log4j.chainsaw.components.tutorial.TutorialFrame;
@@ -51,7 +50,6 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
@@ -114,6 +112,7 @@ public class LogUI extends JFrame {
     private AbstractConfiguration configuration;
 
     private ShutdownManager shutdownManager;
+    private LogUIPanelBuilder logUIPanelBuilder;
 
     /**
      * Constructor which builds up all the visual elements of the frame 
including
@@ -202,6 +201,8 @@ public class LogUI extends JFrame {
         preferencesFrame.getRootPane().
             getActionMap().put("ESCAPE", closeAction);
 
+        logUIPanelBuilder = new LogUIPanelBuilder(tabbedPane, 
identifierPanels, chainsawToolBarAndMenus, panelMap, settingsManager, 
statusBar, zeroConf);
+
         OSXIntegration.init(this);
 
     }
@@ -284,7 +285,7 @@ public class LogUI extends JFrame {
     }
 
     public void buildChainsawLogPanel() {
-        buildLogPanel(false, "Chainsaw", chainsawAppender.getReceiver());
+        logUIPanelBuilder.buildLogPanel(false, "Chainsaw", 
chainsawAppender.getReceiver());
     }
 
     /**
@@ -580,80 +581,6 @@ public class LogUI extends JFrame {
         return tabbedPane;
     }
 
-
-    private void buildLogPanel(boolean customExpression, final String ident, 
final ChainsawReceiver rx)
-        throws IllegalArgumentException {
-        final LogPanel thisPanel = new LogPanel(settingsManager, 
getStatusBar(), ident, allColorizers, globalRuleColorizer);
-
-        if (!customExpression && rx != null) {
-            thisPanel.setReceiver(rx);
-        }
-
-        /*
-         * Now add the panel as a batch listener so it can handle it's own
-         * batchs
-         */
-        if (!customExpression) {
-            identifierPanels.add(thisPanel);
-        }
-
-        TabIconHandler iconHandler = new TabIconHandler(ident, tabbedPane);
-        thisPanel.addEventCountListener(iconHandler);
-
-        tabbedPane.addChangeListener(iconHandler);
-
-        PropertyChangeListener toolbarMenuUpdateListener =
-            evt -> chainsawToolBarAndMenus.stateChange();
-
-        thisPanel.addPropertyChangeListener(toolbarMenuUpdateListener);
-        
thisPanel.addPreferencePropertyChangeListener(toolbarMenuUpdateListener);
-
-        thisPanel.addPropertyChangeListener(
-            "docked",
-            evt -> {
-                LogPanel logPanel = (LogPanel) evt.getSource();
-
-                if (logPanel.isDocked()) {
-                    panelMap.put(logPanel.getIdentifier(), logPanel);
-                    getTabbedPane().addANewTab(
-                        logPanel.getIdentifier(), logPanel, null,
-                        true);
-                    
getTabbedPane().setSelectedTab(getTabbedPane().indexOfTab(logPanel.getIdentifier()));
-                } else {
-                    getTabbedPane().remove(logPanel);
-                }
-            });
-
-        logger.debug("adding logpanel to tabbed pane: {}", ident);
-
-        //NOTE: tab addition is a very fragile process - if you modify this 
code,
-        //verify the frames in the individual log panels initialize to their
-        //correct sizes
-        getTabbedPane().add(ident, thisPanel);
-        panelMap.put(ident, thisPanel);
-
-        /*
-         * Let the new LogPanel receive this batch
-         */
-
-        SwingUtilities.invokeLater(
-            () -> {
-                getTabbedPane().addANewTab(
-                    ident,
-                    thisPanel,
-                    new ImageIcon(ChainsawIcons.ANIM_RADIO_TOWER),
-                    false);
-                thisPanel.layoutComponents();
-
-                getTabbedPane().addANewTab(ChainsawTabbedPane.ZEROCONF,
-                    zeroConf,
-                    null,
-                    false);
-            });
-
-        logger.debug("added tab {}", ident);
-    }
-
     public void createCustomExpressionLogPanel(String ident) {
         //collect events matching the rule from all of the tabs
         try {
@@ -666,7 +593,7 @@ public class LogUI extends JFrame {
                 }
             }
 
-            buildLogPanel(true, ident, null);
+            logUIPanelBuilder.buildLogPanel(true, ident, null);
         } catch (IllegalArgumentException iae) {
             statusBar.setMessage(
                 "Unable to add tab using expression: " + ident + ", reason: "
@@ -678,7 +605,7 @@ public class LogUI extends JFrame {
 
     public void addReceiver(ChainsawReceiver rx) {
         receivers.add(rx);
-        buildLogPanel(false, rx.getName(), rx);
+        logUIPanelBuilder.buildLogPanel(false, rx.getName(), rx);
 
         for (ReceiverEventListener listen : receiverListeners) {
             listen.receiverAdded(rx);
diff --git 
a/src/main/java/org/apache/log4j/chainsaw/logui/LogUIPanelBuilder.java 
b/src/main/java/org/apache/log4j/chainsaw/logui/LogUIPanelBuilder.java
new file mode 100644
index 0000000..09add8e
--- /dev/null
+++ b/src/main/java/org/apache/log4j/chainsaw/logui/LogUIPanelBuilder.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.chainsaw.logui;
+
+import org.apache.log4j.chainsaw.ChainsawConstants;
+import org.apache.log4j.chainsaw.ChainsawStatusBar;
+import org.apache.log4j.chainsaw.ChainsawToolBarAndMenus;
+import org.apache.log4j.chainsaw.color.RuleColorizer;
+import org.apache.log4j.chainsaw.components.elements.TabIconHandler;
+import org.apache.log4j.chainsaw.components.logpanel.LogPanel;
+import org.apache.log4j.chainsaw.components.tabbedpane.ChainsawTabbedPane;
+import org.apache.log4j.chainsaw.icons.ChainsawIcons;
+import org.apache.log4j.chainsaw.prefs.SettingsManager;
+import org.apache.log4j.chainsaw.receiver.ChainsawReceiver;
+import org.apache.log4j.chainsaw.zeroconf.ZeroConfPlugin;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import javax.swing.*;
+import java.awt.*;
+import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class LogUIPanelBuilder {
+    private static Logger logger = 
LogManager.getLogger(LogUIPanelBuilder.class);
+
+    ChainsawTabbedPane tabbedPane;
+    List<LogPanel> identifierPanels;
+    ChainsawToolBarAndMenus chainsawToolBarAndMenus;
+    private Map<String, Component> panelMap;
+
+    private SettingsManager settingsManager;
+    private ChainsawStatusBar chainsawStatusBar;
+    private ZeroConfPlugin zeroConfPlugin;
+
+    private Map<String, RuleColorizer> allColorizers = new HashMap<>();
+    private RuleColorizer globalRuleColorizer = new 
RuleColorizer(settingsManager, true);
+
+    public LogUIPanelBuilder(ChainsawTabbedPane tabbedPane, List<LogPanel> 
identifierPanels,
+                             ChainsawToolBarAndMenus chainsawToolBarAndMenus, 
Map<String, Component> panelMap,
+                             SettingsManager settingsManager, 
ChainsawStatusBar chainsawStatusBar, ZeroConfPlugin zeroConfPlugin) {
+        this.tabbedPane = tabbedPane;
+        this.identifierPanels = identifierPanels;
+        this.chainsawToolBarAndMenus = chainsawToolBarAndMenus;
+        this.panelMap = panelMap;
+        this.settingsManager = settingsManager;
+        this.chainsawStatusBar = chainsawStatusBar;
+        this.zeroConfPlugin = zeroConfPlugin;
+
+        RuleColorizer colorizer = new RuleColorizer(settingsManager);
+        allColorizers.put(ChainsawConstants.DEFAULT_COLOR_RULE_NAME, 
colorizer);
+        
globalRuleColorizer.setConfiguration(settingsManager.getGlobalConfiguration());
+        globalRuleColorizer.loadColorSettings();
+    }
+
+    void buildLogPanel(boolean customExpression, final String ident, final 
ChainsawReceiver rx)
+        throws IllegalArgumentException {
+        final LogPanel thisPanel = new LogPanel(settingsManager, 
chainsawStatusBar, ident, allColorizers, globalRuleColorizer);
+
+        if (!customExpression && rx != null) {
+            thisPanel.setReceiver(rx);
+        }
+
+        /*
+         * Now add the panel as a batch listener so it can handle it's own
+         * batchs
+         */
+        if (!customExpression) {
+            identifierPanels.add(thisPanel);
+        }
+
+        TabIconHandler iconHandler = new TabIconHandler(ident, tabbedPane);
+        thisPanel.addEventCountListener(iconHandler);
+
+        tabbedPane.addChangeListener(iconHandler);
+
+        PropertyChangeListener toolbarMenuUpdateListener =
+            evt -> chainsawToolBarAndMenus.stateChange();
+
+        thisPanel.addPropertyChangeListener(toolbarMenuUpdateListener);
+        
thisPanel.addPreferencePropertyChangeListener(toolbarMenuUpdateListener);
+
+        thisPanel.addPropertyChangeListener(
+            "docked",
+            evt -> {
+                LogPanel logPanel = (LogPanel) evt.getSource();
+
+                if (logPanel.isDocked()) {
+                    panelMap.put(logPanel.getIdentifier(), logPanel);
+                    tabbedPane.addANewTab(
+                        logPanel.getIdentifier(), logPanel, null,
+                        true);
+                    
tabbedPane.setSelectedTab(tabbedPane.indexOfTab(logPanel.getIdentifier()));
+                } else {
+                    tabbedPane.remove(logPanel);
+                }
+            });
+
+        logger.debug("adding logpanel to tabbed pane: {}", ident);
+
+        //NOTE: tab addition is a very fragile process - if you modify this 
code,
+        //verify the frames in the individual log panels initialize to their
+        //correct sizes
+        tabbedPane.add(ident, thisPanel);
+        panelMap.put(ident, thisPanel);
+
+        /*
+         * Let the new LogPanel receive this batch
+         */
+
+        SwingUtilities.invokeLater(
+            () -> {
+                tabbedPane.addANewTab(
+                    ident,
+                    thisPanel,
+                    new ImageIcon(ChainsawIcons.ANIM_RADIO_TOWER),
+                    false);
+                thisPanel.layoutComponents();
+
+                tabbedPane.addANewTab(ChainsawTabbedPane.ZEROCONF,
+                    zeroConfPlugin,
+                    null,
+                    false);
+            });
+
+        logger.debug("added tab {}", ident);
+    }
+}

Reply via email to