1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.chainsaw;
19
20 import javax.swing.*;
21 import java.awt.*;
22 import java.lang.reflect.InvocationTargetException;
23
24
25
26
27
28
29
30
31 public class ProgressPanel extends JPanel {
32 private final JLabel messageLabel = new JLabel();
33 private final JProgressBar progressBar;
34
35 ProgressPanel(int min, int max, String msg) {
36 this.progressBar = new JProgressBar(min, max);
37 setBorder(BorderFactory.createLineBorder(Color.black, 1));
38 messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
39 messageLabel.setText(msg);
40 setLayout(new BorderLayout());
41
42 add(progressBar, BorderLayout.CENTER);
43 add(messageLabel, BorderLayout.SOUTH);
44 }
45
46 public void setMessage(final String string) {
47 SwingUtilities.invokeLater(
48 () -> messageLabel.setText(string));
49 }
50
51 public void setProgress(final int progress) {
52 try {
53 Runnable runnable = () -> progressBar.setValue(progress);
54 if (!SwingUtilities.isEventDispatchThread()) {
55 SwingUtilities.invokeAndWait(runnable);
56 } else {
57 runnable.run();
58 }
59 } catch (InterruptedException | InvocationTargetException e) {
60
61 e.printStackTrace();
62 }
63 }
64 }