1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.chainsaw;
18
19 import org.apache.log4j.Logger;
20 import org.apache.log4j.chainsaw.help.HelpManager;
21
22 import javax.swing.*;
23 import javax.swing.event.HyperlinkEvent;
24 import java.awt.*;
25
26
27
28
29
30
31 class ChainsawAbout extends JDialog {
32 private static final Logger LOG = Logger.getLogger(ChainsawAbout.class);
33
34 private final JEditorPane editPane = new JEditorPane("text/html", "");
35
36 private final JScrollPane scrollPane = new JScrollPane(editPane,
37 ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
38 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
39
40 private final String url = ChainsawAbout.class.getName().replace('.', '/')
41 + ".html";
42
43 private boolean sleep = false;
44
45 private final Object guard = new Object();
46
47 ChainsawAbout(JFrame parent) {
48 super(parent, "About Chainsaw v2", true);
49
50 setBackground(Color.white);
51 getContentPane().setLayout(new BorderLayout());
52
53 JButton closeButton = new JButton(" Close ");
54 closeButton.addActionListener(e -> setVisible(false));
55 closeButton.setDefaultCapable(true);
56
57 try {
58 editPane.setPage(this.getClass().getClassLoader().getResource(url));
59 } catch (Exception e) {
60 throw new RuntimeException("Failed to find the About panel HTML", e);
61 }
62 getContentPane().add(scrollPane, BorderLayout.CENTER);
63 getContentPane().add(closeButton, BorderLayout.SOUTH);
64 JTextComponentFormatter.applySystemFontAndSize(editPane);
65
66 editPane.setEditable(false);
67 editPane.addHyperlinkListener(
68 e -> {
69 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
70 HelpManager.getInstance().setHelpURL(e.getURL());
71 }
72 });
73
74 setSize(320, 240);
75 new Thread(new Scroller()).start();
76 scrollPane.getViewport().setViewPosition(new Point(0, 0));
77
78 setLocationRelativeTo(parent);
79 }
80
81 private class Scroller implements Runnable {
82
83 public void run() {
84 while (true) {
85 try {
86 if (sleep) {
87 synchronized (guard) {
88 guard.wait();
89 }
90 SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition(
91 new Point(0, 0)));
92 continue;
93 }
94 SwingUtilities.invokeLater(() -> scrollPane.getViewport().setViewPosition(
95 new Point(0, scrollPane.getViewport()
96 .getViewPosition().y + 1)));
97 Thread.sleep(100);
98 } catch (Exception e) {
99 LOG.error("Error during scrolling", e);
100 }
101
102 }
103 }
104 }
105
106 public void setVisible(boolean visible) {
107 super.setVisible(visible);
108 sleep = !visible;
109 synchronized (guard) {
110 guard.notifyAll();
111 }
112 }
113 }