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 78ad25f  simplified about component, extraction to its own package
78ad25f is described below

commit 78ad25fbbe7898a5d98188d4744fedfc53cf091e
Author: Christian Grobmeier <[email protected]>
AuthorDate: Mon Dec 18 17:14:20 2023 +0100

    simplified about component, extraction to its own package
---
 .../{ => components/about}/ChainsawAbout.java      |  80 ++++++++-------------
 .../org/apache/log4j/chainsaw/logui/LogUI.java     |   3 +
 src/main/resources/pages/about.html                |  31 ++++++++
 src/main/resources/pages/img/logo.png              | Bin 0 -> 38280 bytes
 src/main/resources/pages/stylesheet.css            |  33 +++++++++
 5 files changed, 98 insertions(+), 49 deletions(-)

diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java 
b/src/main/java/org/apache/log4j/chainsaw/components/about/ChainsawAbout.java
similarity index 54%
rename from src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java
rename to 
src/main/java/org/apache/log4j/chainsaw/components/about/ChainsawAbout.java
index 06b1a93..50ae52e 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawAbout.java
+++ 
b/src/main/java/org/apache/log4j/chainsaw/components/about/ChainsawAbout.java
@@ -14,14 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.log4j.chainsaw;
+package org.apache.log4j.chainsaw.components.about;
 
+import org.apache.log4j.chainsaw.JTextComponentFormatter;
 import org.apache.log4j.chainsaw.help.HelpManager;
 
 import javax.swing.*;
 import javax.swing.event.HyperlinkEvent;
 import java.awt.*;
 import java.io.IOException;
+import java.net.URL;
 
 import org.apache.log4j.chainsaw.logui.LogUI;
 import org.apache.logging.log4j.LogManager;
@@ -33,20 +35,13 @@ import org.apache.logging.log4j.Logger;
  * @author Paul Smith &lt;[email protected]&gt;
  */
 public class ChainsawAbout extends JDialog {
-    private static final Logger LOG = LogManager.getLogger();
+    private static final Logger LOG = 
LogManager.getLogger(ChainsawAbout.class);
 
-    private final JEditorPane editPane = new JEditorPane("text/html", "");
-
-    private final JScrollPane scrollPane = new JScrollPane(editPane,
-        ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
-        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
-
-    private boolean sleep = false;
-
-    private final Object guard = new Object();
+    private final LogUI logUI;
 
     public ChainsawAbout(LogUI logUI) {
         super(logUI, "About Chainsaw v2", true);
+        this.logUI = logUI;
         setBackground(Color.white);
         getContentPane().setLayout(new BorderLayout());
 
@@ -54,18 +49,22 @@ public class ChainsawAbout extends JDialog {
         closeButton.addActionListener(e -> setVisible(false));
         closeButton.setDefaultCapable(true);
 
+        JEditorPane editPane = new JEditorPane("text/html", "");
         try {
-            String url = ChainsawAbout.class.getName().replace('.', '/') + 
".html";
-            
editPane.setPage(this.getClass().getClassLoader().getResource(url));
+            URL url = ClassLoader.getSystemResource("pages/about.html");
+            editPane.setPage(url);
         } catch (IOException e) {
-            throw new RuntimeException("Failed to find the About panel HTML", 
e);
+            throw new RuntimeException("Failed to find the about panel HTML", 
e);
         }
 
+        JScrollPane scrollPane = new JScrollPane(
+            editPane,
+            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+
         getContentPane().add(scrollPane, BorderLayout.CENTER);
         getContentPane().add(closeButton, BorderLayout.SOUTH);
 
-        JTextComponentFormatter.applySystemFontAndSize(editPane);
-
         editPane.setEditable(false);
         editPane.addHyperlinkListener(
             e -> {
@@ -74,44 +73,27 @@ public class ChainsawAbout extends JDialog {
                 }
             });
 
-        setSize(320, 240);
-        new Thread(new Scroller()).start();
+        calculateDimentions();
         scrollPane.getViewport().setViewPosition(new Point(0, 0));
-
         setLocationRelativeTo(logUI);
     }
 
-    private class Scroller implements Runnable {
-
-        public void run() {
-            while (true) {
-                try {
-                    if (sleep) {
-                        synchronized (guard) {
-                            guard.wait();
-                        }
-                        SwingUtilities.invokeLater(() -> 
scrollPane.getViewport().setViewPosition(
-                            new Point(0, 0)));
-                        continue;
-                    }
-                    SwingUtilities.invokeLater(() -> 
scrollPane.getViewport().setViewPosition(
-                        new Point(0, scrollPane.getViewport()
-                            .getViewPosition().y + 1)));
-                    Thread.sleep(100);
-                } catch (Exception e) {
-                    LOG.error("Error during scrolling", e);
-                }
-
-            }
+    /**
+     * Calculates the dimensions of the about panel based on the parents 
component (logUI).
+     * The default dimensions are 10% smaller than the parent component, 
except the height/width
+     * are 400 or below. In that case the same dimensions of the parent 
component are taken.
+     */
+    public void calculateDimentions() {
+        Dimension size = logUI.getSize();
+        double height = size.getHeight();
+        double width = size.getWidth();
+        if (height > 400) {
+            height = height - (height * 0.10);
         }
-    }
-
-    @Override
-    public void setVisible(boolean visible) {
-        super.setVisible(visible);
-        sleep = !visible;
-        synchronized (guard) {
-            guard.notifyAll();
+        if (width > 400) {
+            width = width - (width * 0.10);
         }
+        setSize((int)width, (int)height);
+
     }
 }
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 323b504..db1380e 100644
--- a/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/logui/LogUI.java
@@ -19,6 +19,7 @@ package org.apache.log4j.chainsaw.logui;
 
 import org.apache.commons.configuration2.AbstractConfiguration;
 import org.apache.log4j.chainsaw.*;
+import org.apache.log4j.chainsaw.components.about.ChainsawAbout;
 import org.apache.log4j.chainsaw.components.elements.SmallButton;
 import org.apache.log4j.chainsaw.components.logpanel.LogPanel;
 import org.apache.log4j.chainsaw.components.tabbedpane.ChainsawTabbedPane;
@@ -413,6 +414,8 @@ public class LogUI extends JFrame {
     public void showAboutBox() {
         if (aboutBox == null) {
             aboutBox = new ChainsawAbout(this);
+        } else {
+            aboutBox.calculateDimentions();
         }
 
         aboutBox.setVisible(true);
diff --git a/src/main/resources/pages/about.html 
b/src/main/resources/pages/about.html
new file mode 100644
index 0000000..b985288
--- /dev/null
+++ b/src/main/resources/pages/about.html
@@ -0,0 +1,31 @@
+<!--
+ 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.
+
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+  <link rel="stylesheet" href="stylesheet.css" type="text/css">
+</head>
+
+<body>
+  <img align="top" src="img/logo.png" border="0" alt="Log4j Logo">
+  <h1>Chainsaw v2</h1>
+  <p>Brought to you by the Apache Logging Services Project team.</p>
+  <p>Please send questions, bug reports and/or feature requests to 
<b>[email protected]</b></p>
+  <p>Website: <b>https://logging.apache.org</b></p>
+</body>
+</html>
diff --git a/src/main/resources/pages/img/logo.png 
b/src/main/resources/pages/img/logo.png
new file mode 100644
index 0000000..9ad3d2c
Binary files /dev/null and b/src/main/resources/pages/img/logo.png differ
diff --git a/src/main/resources/pages/stylesheet.css 
b/src/main/resources/pages/stylesheet.css
new file mode 100644
index 0000000..90dd5a5
--- /dev/null
+++ b/src/main/resources/pages/stylesheet.css
@@ -0,0 +1,33 @@
+/*
+ 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.
+
+*/
+
+ body {
+  font-size: 1.2em;
+  color: #000000;
+  font-family: Helvetica, Arial, sans-serif;
+}
+
+h1 {
+  font-size: 1.5em;
+  font-weight: bold;
+}
+
+h2 {
+  font-size: 1.3em;
+  font-weight: bold;
+}

Reply via email to