Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / swing / threads / UndefinedProgressMonitor.java @ 40561

History | View | Annotate | Download (7.1 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
 *
26
 * $Id: UndefinedProgressMonitor.java 29631 2009-06-29 16:56:19Z jpiera $
27
 * $Log$
28
 * Revision 1.4  2006-11-06 07:29:59  jaume
29
 * organize imports
30
 *
31
 * Revision 1.3  2006/04/18 15:16:14  azabala
32
 * a?adida la posibilidad de personalizar el titulo del dialogo de proceso
33
 *
34
 * Revision 1.2  2006/03/20 16:04:21  azabala
35
 * *** empty log message ***
36
 *
37
 * Revision 1.1  2006/03/14 19:23:58  azabala
38
 * *** empty log message ***
39
 *
40
 *
41
 */
42
package org.gvsig.utils.swing.threads;
43

    
44
import java.awt.Frame;
45
import java.awt.GridBagConstraints;
46
import java.awt.GridBagLayout;
47

    
48
import javax.swing.JButton;
49
import javax.swing.JDialog;
50
import javax.swing.JLabel;
51
import javax.swing.JPanel;
52
import javax.swing.JProgressBar;
53

    
54
/**
55
 * Dialog that shows the evolution of the execution of a
56
 * ITask.
57
 * If this ITask is a defined task (we know the number of steps
58
 * it must do) it shows a progress bar.
59
 * 
60
 * If it doesnt, progress bar is filling and emptying
61
 * @author azabala
62
 *
63
 */
64
public class UndefinedProgressMonitor extends JDialog 
65
        implements IProgressMonitorIF{
66

    
67
        
68
        private static final long serialVersionUID = 8776505862813807891L;
69
        private JPanel jContentPane = null;
70
        private JLabel mainTitleLabel = null;
71
        private JLabel noteLabel = null;
72
        private JProgressBar jProgressBar = null;
73
        private JButton cancelButton = null;
74
        boolean canceled = false;
75
        private String title = "Processing...";
76

    
77
        /**
78
         * This is the default constructor
79
         */
80
        public UndefinedProgressMonitor() {
81
                super();
82
                initialize();
83
        }
84
        /**
85
         * Constructor which specify the dialog title 
86
         * (for example:processing, etc)
87
         * @param parent
88
         * @param title
89
         */
90
        public UndefinedProgressMonitor(Frame parent, String title){
91
                super(parent, false);
92
                this.title = title;
93
                initialize();
94
        }
95

    
96
        /**
97
         * This method initializes this
98
         * 
99
         * @return void
100
         * 
101
         * FIXME Internationalize this
102
         */
103
        private void initialize() {
104
                this.setSize(318, 181);
105
                this.setTitle(title);
106
                this.setContentPane(getJContentPane());
107
        }
108

    
109
        /**
110
         * This method initializes jContentPane
111
         * 
112
         * @return javax.swing.JPanel
113
         */
114
        private JPanel getJContentPane() {
115
                if (jContentPane == null) {
116
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
117
                        gridBagConstraints3.insets = new java.awt.Insets(6,97,18,125);
118
                        gridBagConstraints3.gridy = 3;
119
                        gridBagConstraints3.ipadx = 4;
120
                        gridBagConstraints3.ipady = -4;
121
                        gridBagConstraints3.gridx = 0;
122
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
123
                        gridBagConstraints2.insets = new java.awt.Insets(11,43,5,32);
124
                        gridBagConstraints2.gridy = 2;
125
                        gridBagConstraints2.ipadx = 109;
126
                        gridBagConstraints2.ipady = 4;
127
                        gridBagConstraints2.fill = java.awt.GridBagConstraints.NONE;
128
                        gridBagConstraints2.gridwidth = 2;
129
                        gridBagConstraints2.anchor = java.awt.GridBagConstraints.CENTER;
130
                        gridBagConstraints2.gridx = 0;
131
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
132
                        gridBagConstraints1.insets = new java.awt.Insets(9,43,8,32);
133
                        gridBagConstraints1.gridy = 1;
134
                        gridBagConstraints1.ipadx = 180;
135
                        gridBagConstraints1.ipady = 0;
136
                        gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
137
                        gridBagConstraints1.gridx = 0;
138
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
139
                        gridBagConstraints.insets = new java.awt.Insets(10,43,8,32);
140
                        gridBagConstraints.gridy = 0;
141
                        gridBagConstraints.ipadx = 148;
142
                        gridBagConstraints.ipady = 11;
143
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144
                        gridBagConstraints.gridx = 0;
145
                        noteLabel = new JLabel();
146
                        noteLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
147
                        noteLabel.setText("noteLabel");
148
                        mainTitleLabel = new JLabel();
149
                        mainTitleLabel.setText("mainTittleLabel");
150
                        mainTitleLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12));
151
                        jContentPane = new JPanel();
152
                        jContentPane.setLayout(new GridBagLayout());
153
                        jContentPane.add(mainTitleLabel, gridBagConstraints);
154
                        jContentPane.add(noteLabel, gridBagConstraints1);
155
                        jContentPane.add(getJProgressBar(), gridBagConstraints2);
156
                        jContentPane.add(getCancelButton(), gridBagConstraints3);
157
                }
158
                return jContentPane;
159
        }
160

    
161
        /**
162
         * This method initializes jProgressBar        
163
         *         
164
         * @return javax.swing.JProgressBar        
165
         */
166
        private JProgressBar getJProgressBar() {
167
                if (jProgressBar == null) {
168
                        jProgressBar = new JProgressBar();
169
                }
170
                return jProgressBar;
171
        }
172

    
173
        /**
174
         * This method initializes cancelButton        
175
         *         
176
         * @return javax.swing.JButton        
177
         */
178
        private JButton getCancelButton() {
179
                if (cancelButton == null) {
180
                        cancelButton = new JButton();
181
                        cancelButton.setText("cancelar");
182
                        cancelButton.addActionListener(new java.awt.event.ActionListener() {
183
                                public void actionPerformed(java.awt.event.ActionEvent e) {
184
                                        cancel();
185
                                }
186
                        });
187
                        cancelButton.addActionListener(new java.awt.event.ActionListener() {
188
                                public void actionPerformed(java.awt.event.ActionEvent e) {
189
                                        cancel();
190
                                }
191
                        });
192
                }
193
                return cancelButton;
194
        }
195

    
196
        public void setInitialStep(int step) {
197
                jProgressBar.setMinimum(step);
198
        }
199

    
200
        public void setLastStep(int step) {
201
                jProgressBar.setMaximum(step);
202
        }
203

    
204
        public void setCurrentStep(int step) {
205
                jProgressBar.setValue(step);
206
        }
207

    
208
        public int getInitialStep() {
209
                return jProgressBar.getMinimum();
210
        }
211

    
212
        public int getLastStep() {
213
                return jProgressBar.getMaximum();
214
        }
215

    
216
        public int getCurrentStep() {
217
                return jProgressBar.getValue();
218
        }
219

    
220
        public void setIndeterminated(boolean indeterminated) {
221
                jProgressBar.setIndeterminate(indeterminated);
222
        }
223

    
224
        public boolean isIndeterminated() {
225
                return jProgressBar.isIndeterminate();
226
        }
227

    
228
        public void setBarStringDrawed(boolean stringDrawed) {
229
                jProgressBar.setStringPainted(stringDrawed);
230
        }
231

    
232
        public void setBarString(String barString) {
233
                jProgressBar.setString(barString);
234
        }
235

    
236
        public void setMainTitleLabel(String text) {
237
                mainTitleLabel.setText(text);
238
        }
239

    
240
        public void setNote(String note) {
241
                noteLabel.setText(note);
242
        }
243

    
244
        public void cancel() {
245
                canceled = true;
246
        }
247

    
248
//        public void taskInBackground() {
249
//                //setModal(false);
250
//        }
251

    
252
        public boolean isCanceled() {
253
                return canceled == true;
254
        }
255

    
256
        public void close() {
257
                this.dispose();
258
        }
259

    
260
        public void open() {
261
                this.setVisible(true);
262
        }
263

    
264
}  //  @jve:decl-index=0:visual-constraint="30,10"