1   /**
2    *    Copyright 2009 Webster Smalley
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
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   * @author Matthew Smalley
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;  //  @jve:decl-index=0:visual-constraint="81,25"
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  	 * This method initializes jFrame	
63  	 * 	
64  	 * @return javax.swing.JFrame	
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  	 * This method initializes jContentPane	
79  	 * 	
80  	 * @return javax.swing.JPanel	
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  	 * This method initializes jProgressBar	
96  	 * 	
97  	 * @return javax.swing.JProgressBar	
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 }