View Javadoc

1   // ProgressDialog
2   // $Id: ProgressDialog.java,v 1.1 2003/12/09 10:21:45 oconnor_m Exp $
3   //
4   // Copyright (C) 2002-2003 Axel Wernicke <axel.wernicke@gmx.de>
5   //
6   // This program is free software; you can redistribute it and/or modify
7   // it under the terms of the GNU General Public License as published by
8   // the Free Software Foundation; either version 2 of the License, or
9   // (at your option) any later version.
10  //
11  // This program is distributed in the hope that it will be useful,
12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  // GNU General Public License for more details.
15  //
16  // You should have received a copy of the GNU General Public License
17  // along with this program; if not, write to the Free Software
18  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  
20  package com.finalist.jaggenerator;
21  
22  
23  /***
24   * ProgressDialog provides a progress bar within a dialog window and a cancel button to abort the action.
25   *
26   * @author  axel wernicke
27   */
28  public class ProgressDialog extends javax.swing.JDialog {
29     /*** The myPod action worker thre3ad this dialog is attached to */
30     private Thread worker = null;
31  
32     /***
33      * Creates new form ProgressDialog.  The dialogue will not be visible untl {@link #startThread} is called.
34      *
35      * @param parent frame for the dialog
36      * @param modal create dialog (a-) synchronously
37      */
38     public ProgressDialog(java.awt.Frame parent, boolean modal) {
39        super(parent, modal);
40     }
41  
42     /***
43      * Starts up the thread that does the actual work being monitored.
44      *
45      * @param worker thread the dialog is attached to
46      */
47     public void startThread(final Thread worker) {
48        this.worker = worker;
49        initComponents();
50        totalProgressBar.setIndeterminate(true);
51        pack();
52        setLocationRelativeTo(getParent());
53        worker.start();
54  //      //create a waiter thread: waits until task is finished, then closes dialogue.
55  //      new Thread("ProgressDialog.startThread") {
56  //         public void run() {
57  //            try {
58  //               worker.join();
59  //            } catch (InterruptedException e) {
60  //               //no action
61  //            }
62  //            setVisible(false);
63  //            dispose();
64  //            JagGenerator.logToConsole("2222222222222222222222222");
65  //
66  //         }
67  //      }.start();
68  
69        setVisible(true);
70        JagGenerator.logToConsole("33333333333333333333333");
71  
72  
73     }
74  
75     /*** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */
80     private void initComponents()//GEN-BEGIN:initComponents
81     {
82        java.awt.GridBagConstraints gridBagConstraints;
83  
84        statusLabel = new javax.swing.JLabel();
85        statusContentLabel = new javax.swing.JLabel();
86        totalProgressBar = new javax.swing.JProgressBar();
87        clipLabel = new javax.swing.JLabel();
88        clipContentLabel = new javax.swing.JLabel();
89        canelButton = new javax.swing.JButton();
90  
91        getContentPane().setLayout(new java.awt.GridBagLayout());
92  
93        setTitle("progress...");
94        setName("progressDialog");
95        setResizable(false);
96        addWindowListener(new java.awt.event.WindowAdapter() {
97           public void windowClosing(java.awt.event.WindowEvent evt) {
98              closeDialog(evt);
99           }
100       });
101 
102       statusLabel.setForeground(new java.awt.Color(102, 102, 153));
103       statusLabel.setText("status:");
104       gridBagConstraints = new java.awt.GridBagConstraints();
105       gridBagConstraints.gridx = 0;
106       gridBagConstraints.gridy = 0;
107       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
108       gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
109       getContentPane().add(statusLabel, gridBagConstraints);
110 
111       statusContentLabel.setFont(new java.awt.Font("Dialog", 1, 10));
112       statusContentLabel.setMaximumSize(new java.awt.Dimension(250, 14));
113       statusContentLabel.setMinimumSize(new java.awt.Dimension(200, 14));
114       statusContentLabel.setPreferredSize(new java.awt.Dimension(200, 14));
115       gridBagConstraints = new java.awt.GridBagConstraints();
116       gridBagConstraints.gridx = 1;
117       gridBagConstraints.gridy = 0;
118       gridBagConstraints.gridwidth = 2;
119       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
120       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
121       gridBagConstraints.weightx = 0.1;
122       gridBagConstraints.insets = new java.awt.Insets(12, 11, 0, 12);
123       getContentPane().add(statusContentLabel, gridBagConstraints);
124 
125       gridBagConstraints = new java.awt.GridBagConstraints();
126       gridBagConstraints.gridx = 0;
127       gridBagConstraints.gridy = 1;
128       gridBagConstraints.gridwidth = 3;
129       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130       gridBagConstraints.insets = new java.awt.Insets(11, 17, 0, 17);
131       getContentPane().add(totalProgressBar, gridBagConstraints);
132 
133       clipLabel.setForeground(new java.awt.Color(102, 102, 153));
134       clipLabel.setText("clip:");
135       gridBagConstraints = new java.awt.GridBagConstraints();
136       gridBagConstraints.gridx = 0;
137       gridBagConstraints.gridy = 2;
138       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
139       gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0);
140       getContentPane().add(clipLabel, gridBagConstraints);
141 
142       clipContentLabel.setFont(new java.awt.Font("Dialog", 1, 10));
143       clipContentLabel.setMaximumSize(new java.awt.Dimension(250, 14));
144       clipContentLabel.setMinimumSize(new java.awt.Dimension(250, 14));
145       clipContentLabel.setPreferredSize(new java.awt.Dimension(250, 14));
146       gridBagConstraints = new java.awt.GridBagConstraints();
147       gridBagConstraints.gridx = 1;
148       gridBagConstraints.gridy = 2;
149       gridBagConstraints.gridwidth = 2;
150       gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152       gridBagConstraints.insets = new java.awt.Insets(11, 11, 0, 12);
153       getContentPane().add(clipContentLabel, gridBagConstraints);
154 
155       canelButton.setText("cancel");
156       canelButton.addActionListener(new java.awt.event.ActionListener() {
157          public void actionPerformed(java.awt.event.ActionEvent evt) {
158             canelButtonActionPerformed(evt);
159          }
160       });
161 
162       gridBagConstraints = new java.awt.GridBagConstraints();
163       gridBagConstraints.gridx = 0;
164       gridBagConstraints.gridy = 6;
165       gridBagConstraints.gridwidth = 3;
166       gridBagConstraints.insets = new java.awt.Insets(17, 12, 12, 12);
167       getContentPane().add(canelButton, gridBagConstraints);
168 
169       pack();
170    }//GEN-END:initComponents
171 
172    /*** Cancels the action and closes the dialog
173     * @param evt that triggered the action
174     */
175    private void canelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_canelButtonActionPerformed
176    {//GEN-HEADEREND:event_canelButtonActionPerformed
177       if (worker != null) {
178          worker.interrupt();
179       } else {
180          setVisible(false);
181          dispose();
182       }
183 
184    }//GEN-LAST:event_canelButtonActionPerformed
185 
186    /*** Cancels the action and closes the dialog
187     * @param evt that triggered the action
188     */
189    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
190       if (worker != null) {
191          worker.interrupt();
192       } else {
193          setVisible(false);
194          dispose();
195       }
196 
197    }//GEN-LAST:event_closeDialog
198 
199    /*** Sets the status text
200     * @param text to set
201     */
202    public void setStatusText(String text) {
203       if (statusContentLabel != null) {
204          this.statusContentLabel.setText(text);
205       }
206    }
207 
208    /*** Sets the clip text
209     * @param text to set
210     */
211    public void setClipText(String text) {
212       this.clipContentLabel.setText(text);
213    }
214 
215    /*** Sets the minimum value of the progress bar
216     * @param value to set
217     */
218    public void setProgressMin(int value) {
219       this.totalProgressBar.setMinimum(value);
220    }
221 
222    /*** Sets the progress max value
223     * @param value to set
224     */
225    public void setProgressMax(int value) {
226       this.totalProgressBar.setMaximum(value);
227    }
228 
229    /*** Sets the progress bounds
230     * @param min value to set
231     * @param max value to set
232     */
233    public void setProgressBounds(int min, int max) {
234       this.totalProgressBar.setMinimum(min);
235       this.totalProgressBar.setMaximum(max);
236    }
237 
238 
239    /*** Sets the value of the progress bar
240     * @param value to set
241     */
242    public void setProgressValue(int value) {
243       this.totalProgressBar.setValue(value);
244    }
245 
246 
247    /*** Gets the value of the progress bar
248     * @return progress value
249     */
250    public int getProgressValue() {
251       return this.totalProgressBar.getValue();
252    }
253 
254 
255    /*** Sets the progress bars indeterminate status.
256     * @param value to set
257     */
258    public void setProgressIndeterminate(boolean value) {
259       this.totalProgressBar.setIndeterminate(value);
260    }
261 
262 
263    /*** Interrupts the worker thread (action) that dialog is attached to */
264    public void interrupt() {
265       this.worker.interrupt();
266    }
267 
268    // Variables declaration - do not modify//GEN-BEGIN:variables
269    private javax.swing.JButton canelButton;
270    private javax.swing.JLabel clipContentLabel;
271    private javax.swing.JLabel clipLabel;
272    private javax.swing.JLabel statusContentLabel;
273    private javax.swing.JLabel statusLabel;
274    private javax.swing.JProgressBar totalProgressBar;
275    // End of variables declaration//GEN-END:variables
276 
277 }