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