KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > xjlib > appkit > utils > XJDialogProgress


1 /*
2
3 [The "BSD licence"]
4 Copyright (c) 2005 Jean Bovet
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 */

31
32 package org.antlr.xjlib.appkit.utils;
33
34 import org.antlr.xjlib.appkit.frame.XJDialog;
35 import org.antlr.xjlib.appkit.frame.XJFrameInterface;
36
37 import javax.swing.*;
38 import java.awt.*;
39 import java.awt.event.ActionEvent JavaDoc;
40 import java.awt.event.ActionListener JavaDoc;
41
42 public class XJDialogProgress extends XJDialog {
43
44     protected XJDialogProgressDelegate delegate;
45
46     protected JLabel infoLabel;
47     protected JProgressBar progressBar;
48     protected JButton cancelButton;
49
50     public XJDialogProgress(XJFrameInterface owner, boolean modal) {
51         super(owner==null?null:owner.getJavaContainer(), modal);
52         init();
53     }
54
55     public XJDialogProgress(XJFrameInterface owner) {
56         super(owner==null?null:owner.getJavaContainer(), false);
57         init();
58     }
59
60     public XJDialogProgress(Container owner, boolean modal) {
61         super(owner, modal);
62         init();
63     }
64
65     public XJDialogProgress(Container owner) {
66         super(owner, false);
67         init();
68     }
69
70     public void init() {
71         setResizable(false);
72         setSize(400, 90);
73
74         initComponents();
75
76         cancelButton.addActionListener(new ActionListener JavaDoc() {
77             public void actionPerformed(ActionEvent JavaDoc event) {
78                 if(delegate != null) {
79                     setInfo("Cancelling...");
80                     delegate.dialogDidCancel();
81                 }
82             }
83         });
84     }
85
86     public void setCancellable(boolean flag) {
87         cancelButton.setEnabled(flag);
88     }
89
90     public void setIndeterminate(boolean flag) {
91         if(flag) {
92             setProgress(0);
93             setProgressMax(0);
94         }
95         progressBar.setIndeterminate(flag);
96     }
97     
98     public void setDelegate(XJDialogProgressDelegate delegate) {
99         this.delegate = delegate;
100     }
101
102     public void setInfo(String JavaDoc info) {
103         infoLabel.setText(info);
104     }
105
106     public void setProgress(float value) {
107         setProgress((int)value);
108     }
109
110     public void setProgress(int value) {
111         progressBar.setValue(value);
112     }
113
114     public void setProgressMax(int value) {
115         progressBar.setMaximum(value);
116     }
117
118     private void initComponents() {
119         Container contentPane = getContentPane();
120         contentPane.setLayout(new GridBagLayout());
121
122         infoLabel = new JLabel();
123         progressBar = new JProgressBar();
124         cancelButton = new JButton("Cancel");
125
126         setTitle("Operation in progress");
127
128         GridBagConstraints gbc = new GridBagConstraints();
129
130         gbc.gridx = 0;
131         gbc.gridy = 0;
132         gbc.gridwidth = 2;
133         gbc.anchor = GridBagConstraints.WEST;
134         gbc.fill = GridBagConstraints.HORIZONTAL;
135         gbc.weightx = 1;
136         gbc.insets = new Insets(20, 20, 0, 0);
137         contentPane.add(infoLabel, gbc);
138
139         gbc.gridx = 0;
140         gbc.gridy = 1;
141         gbc.gridwidth = 1;
142         gbc.insets = new Insets(0, 20, 20, 10);
143         contentPane.add(progressBar, gbc);
144
145         gbc.gridx = 1;
146         gbc.anchor = GridBagConstraints.CENTER;
147         gbc.fill = GridBagConstraints.NONE;
148         gbc.weightx = 0;
149         gbc.insets = new Insets(0, 0, 20, 20);
150         contentPane.add(cancelButton, gbc);
151     }
152
153 }
154
Popular Tags