1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.webstersmalley.watermarker;
18
19 import javax.swing.JFrame;
20 import javax.swing.JPanel;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import javax.swing.JProgressBar;
24 import javax.swing.JLabel;
25
26
27
28
29
30 public class ProgressBar {
31
32 private int jobCount;
33 private int currentJobIndex = 0;
34 private String currentJobName;
35
36 private JFrame jFrame = null;
37 private JPanel jContentPane = null;
38 private JProgressBar jProgressBar = null;
39 private JLabel jLabel = null;
40
41 public void setJobCount(int jobCount) {
42 this.jobCount = jobCount;
43 this.getJProgressBar().setMaximum(jobCount);
44 }
45
46 public void incrementJobCount(int increment) {
47 setJobCount(jobCount + increment);
48 }
49
50 public void setCurrentJobName(String currentJobName) {
51 this.currentJobName = currentJobName;
52 jLabel.setText(currentJobName);
53 }
54
55 public void postCompletion() {
56 currentJobName = "";
57 currentJobIndex++;
58 jProgressBar.setValue(currentJobIndex);
59 }
60
61
62
63
64
65
66 private JFrame getJFrame() {
67 if (jFrame == null) {
68 jFrame = new JFrame();
69 jFrame.setSize(new Dimension(491, 79));
70 jFrame.setTitle("Watermarker Progress");
71 jFrame.setContentPane(getJContentPane());
72 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
73 }
74 return jFrame;
75 }
76
77
78
79
80
81
82 private JPanel getJContentPane() {
83 if (jContentPane == null) {
84 jLabel = new JLabel();
85 jLabel.setText("C:\\download\\blah.jpg");
86 jContentPane = new JPanel();
87 jContentPane.setLayout(new BorderLayout());
88 jContentPane.add(getJProgressBar(), BorderLayout.CENTER);
89 jContentPane.add(jLabel, BorderLayout.SOUTH);
90 }
91 return jContentPane;
92 }
93
94
95
96
97
98
99 private JProgressBar getJProgressBar() {
100 if (jProgressBar == null) {
101 jProgressBar = new JProgressBar(0, jobCount);
102 jProgressBar.setStringPainted(true);
103 }
104 return jProgressBar;
105 }
106
107 public void show() {
108 this.getJFrame().setVisible(true);
109 }
110
111 public void close() {
112 this.getJFrame().setVisible(false);
113 }
114
115 public static void main(String[] args) {
116 new ProgressBar().show();
117
118 }
119 }