You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gr...@apache.org on 2023/12/15 15:38:07 UTC

(logging-chainsaw) branch master updated: extracted receivers panel to its own class

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 1dd66a2  extracted receivers panel to its own class
1dd66a2 is described below

commit 1dd66a2d70b3fa6295b9ac0c15a0e7a3b244519e
Author: Christian Grobmeier <cg...@grobmeier.de>
AuthorDate: Fri Dec 15 16:37:56 2023 +0100

    extracted receivers panel to its own class
---
 src/main/java/org/apache/log4j/chainsaw/LogUI.java | 52 ++++--------------
 .../apache/log4j/chainsaw/LogUiReceiversPanel.java | 61 ++++++++++++++++++++++
 2 files changed, 70 insertions(+), 43 deletions(-)

diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUI.java b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
index e8df0a0..550b96d 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
@@ -96,7 +96,7 @@ public class LogUI extends JFrame {
     public TutorialFrame tutorialFrame;
     private JSplitPane mainReceiverSplitPane;
     private final List<LogPanel> identifierPanels = new ArrayList<>();
-
+    private LogUiReceiversPanel logUiReceiversPanel;
 
     private JToolBar toolbar;
     private ChainsawToolBarAndMenus chainsawToolBarAndMenus;
@@ -165,7 +165,6 @@ public class LogUI extends JFrame {
 
         setupHelpSystem();
         statusBar = new ChainsawStatusBar(this);
-        setupReceiverPanel();
 
         this.chainsawToolBarAndMenus = new ChainsawToolBarAndMenus(this, configuration);
         toolbar = chainsawToolBarAndMenus.getToolbar();
@@ -371,14 +370,9 @@ public class LogUI extends JFrame {
         getContentPane().add(toolbar, BorderLayout.NORTH);
         getContentPane().add(statusBar, BorderLayout.SOUTH);
 
-        mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel);
-        mainReceiverSplitPane.setContinuousLayout(true);
-        dividerSize = mainReceiverSplitPane.getDividerSize();
-        mainReceiverSplitPane.setDividerLocation(-1);
-
-        getContentPane().add(mainReceiverSplitPane, BorderLayout.CENTER);
+        logUiReceiversPanel = new LogUiReceiversPanel(settingsManager, receivers, this, statusBar, panePanel);
+        getContentPane().add(logUiReceiversPanel.getMainReceiverSplitPane(), BorderLayout.CENTER);
 
-        mainReceiverSplitPane.setResizeWeight(1.0);
         addWindowListener(
             new WindowAdapter() {
                 public void windowClosing(WindowEvent event) {
@@ -485,9 +479,9 @@ public class LogUI extends JFrame {
         setVisible(true);
 
         if (configuration.getBoolean("showReceivers", false)) {
-            showReceiverPanel();
+            logUiReceiversPanel.showReceiverPanel();
         } else {
-            hideReceiverPanel();
+            logUiReceiversPanel.hideReceiverPanel();
         }
 
         /*
@@ -504,34 +498,6 @@ public class LogUI extends JFrame {
         chainsawToolBarAndMenus.stateChange();
     }
 
-    /**
-     * Display the log tree pane, using the last known divider location
-     */
-    private void showReceiverPanel() {
-        mainReceiverSplitPane.setDividerSize(dividerSize);
-        mainReceiverSplitPane.setDividerLocation(lastMainReceiverSplitLocation);
-        receiversPanel.setVisible(true);
-        mainReceiverSplitPane.repaint();
-    }
-
-    /**
-     * Hide the log tree pane, holding the current divider location for later use
-     */
-    private void hideReceiverPanel() {
-        //subtract one to make sizes match
-        int currentSize = mainReceiverSplitPane.getWidth() - mainReceiverSplitPane.getDividerSize();
-        if (mainReceiverSplitPane.getDividerLocation() > -1) {
-            if (!(((mainReceiverSplitPane.getDividerLocation() + 1) == currentSize)
-                || ((mainReceiverSplitPane.getDividerLocation() - 1) == 0))) {
-                lastMainReceiverSplitLocation = ((double) mainReceiverSplitPane
-                    .getDividerLocation() / currentSize);
-            }
-        }
-        mainReceiverSplitPane.setDividerSize(0);
-        receiversPanel.setVisible(false);
-        mainReceiverSplitPane.repaint();
-    }
-
     private void initPrefModelListeners() {
         int tooltipDisplayMillis = configuration.getInt("tooltipDisplayMillis", 4000);
 
@@ -552,18 +518,18 @@ public class LogUI extends JFrame {
                 if (evt.getPropertyName().equals("showReceivers")) {
                     boolean value = (Boolean) evt.getPropertyValue();
                     if (value) {
-                        showReceiverPanel();
+                        logUiReceiversPanel.showReceiverPanel();
                     } else {
-                        hideReceiverPanel();
+                        logUiReceiversPanel.hideReceiverPanel();
                     }
                 }
             });
         boolean showReceivers = configuration.getBoolean("showReceivers", false);
         setStatusBarVisible(showStatusBar);
         if (showReceivers) {
-            showReceiverPanel();
+            logUiReceiversPanel.showReceiverPanel();
         } else {
-            hideReceiverPanel();
+            logUiReceiversPanel.hideReceiverPanel();
         }
 
         configuration.addEventListener(ConfigurationEvent.SET_PROPERTY,
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUiReceiversPanel.java b/src/main/java/org/apache/log4j/chainsaw/LogUiReceiversPanel.java
new file mode 100644
index 0000000..82cd97c
--- /dev/null
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUiReceiversPanel.java
@@ -0,0 +1,61 @@
+package org.apache.log4j.chainsaw;
+
+import org.apache.log4j.chainsaw.prefs.SettingsManager;
+import org.apache.log4j.chainsaw.receiver.ChainsawReceiver;
+import org.apache.log4j.chainsaw.receivers.ReceiversPanel;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.List;
+
+public class LogUiReceiversPanel {
+
+    private ReceiversPanel receiversPanel;
+    private JSplitPane mainReceiverSplitPane;
+
+    private int dividerSize;
+    private static final double DEFAULT_MAIN_RECEIVER_SPLIT_LOCATION = 0.85d;
+    private double lastMainReceiverSplitLocation = DEFAULT_MAIN_RECEIVER_SPLIT_LOCATION;
+    public LogUiReceiversPanel(SettingsManager settingsManager, List<ChainsawReceiver> receivers, LogUI logUI, ChainsawStatusBar statusBar, JPanel panePanel) {
+        receiversPanel = new ReceiversPanel(settingsManager, receivers, logUI, statusBar);
+        mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel);
+        mainReceiverSplitPane.setContinuousLayout(true);
+        dividerSize = mainReceiverSplitPane.getDividerSize();
+        mainReceiverSplitPane.setDividerLocation(-1);
+
+        mainReceiverSplitPane.setResizeWeight(1.0);
+    }
+
+
+    public JSplitPane getMainReceiverSplitPane() {
+        return mainReceiverSplitPane;
+    }
+
+    /**
+     * Display the log tree pane, using the last known divider location
+     */
+    public void showReceiverPanel() {
+        mainReceiverSplitPane.setDividerSize(dividerSize);
+        mainReceiverSplitPane.setDividerLocation(lastMainReceiverSplitLocation);
+        receiversPanel.setVisible(true);
+        mainReceiverSplitPane.repaint();
+    }
+
+    /**
+     * Hide the log tree pane, holding the current divider location for later use
+     */
+    public void hideReceiverPanel() {
+        //subtract one to make sizes match
+        int currentSize = mainReceiverSplitPane.getWidth() - mainReceiverSplitPane.getDividerSize();
+        if (mainReceiverSplitPane.getDividerLocation() > -1) {
+            if (!(((mainReceiverSplitPane.getDividerLocation() + 1) == currentSize)
+                || ((mainReceiverSplitPane.getDividerLocation() - 1) == 0))) {
+                lastMainReceiverSplitLocation = ((double) mainReceiverSplitPane
+                    .getDividerLocation() / currentSize);
+            }
+        }
+        mainReceiverSplitPane.setDividerSize(0);
+        receiversPanel.setVisible(false);
+        mainReceiverSplitPane.repaint();
+    }
+}