Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / progresspanel / ProgressPanel.java @ 10962

History | View | Annotate | Download (6.53 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.gui.beans.progresspanel;
20

    
21
import java.awt.Dimension;
22
import java.awt.FlowLayout;
23
import java.awt.Toolkit;
24

    
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28
import javax.swing.JProgressBar;
29
import javax.swing.JScrollPane;
30
import javax.swing.JTextPane;
31

    
32
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
33
/**
34
 * <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar
35
 * una barra de progreso con su ventana de registro.
36
 *
37
 * @version 20/03/2007
38
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
39
 */
40
public class ProgressPanel extends JFrame {
41
        private static final long serialVersionUID = -6930857769971064429L;
42
        private JPanel jPanel = null;
43
        private JLabel jLabel = null;
44
        private JLabel jLabel1 = null;
45
        private JPanel jPanel1 = null;
46
        private JPanel njp = null;
47
        private ButtonsPanel buttonsPanel = null;
48
        private JProgressBar jProgressBar = null;
49
        private JScrollPane jScrollPane = null;
50
        private JTextPane jTextPane = null;
51
        private LogControl text = new LogControl();
52

    
53
        /**
54
         * Constructor
55
         */
56
        public ProgressPanel() {
57
                initialize();
58
        }
59

    
60
        /**
61
         * This method initializes this
62
         * 
63
         */
64
        private void initialize() {
65
                njp = new JPanel();
66
                njp.setLayout(new java.awt.BorderLayout(5, 5));
67
                njp.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
68
                this.setContentPane(njp);
69
                this.setResizable(false);
70
                njp.add(getJPanel(), java.awt.BorderLayout.NORTH);
71
                njp.add(getJPanel1(), java.awt.BorderLayout.CENTER);
72
                njp.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
73
                showLog(false);
74
                setPercent(0);
75
                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
76
                this.setLocation(
77
                                (int) (d.getWidth() - this.getWidth()) >> 1,
78
                                (int) (d.getHeight() - this.getHeight()) >> 1);
79
                this.show();
80
        }
81

    
82
        /**
83
         * This method initializes jPanel        
84
         *         
85
         * @return javax.swing.JPanel        
86
         */
87
        private JPanel getJPanel() {
88
                if (jPanel == null) {
89
                        jLabel1 = new JLabel();
90
                        jLabel = new JLabel();
91
                        jLabel.setText("Espere...");
92
                        jPanel = new JPanel();
93
                        jPanel.setLayout(new java.awt.BorderLayout(5, 5));
94
                        jPanel.add(jLabel, java.awt.BorderLayout.WEST);
95
                        jPanel.add(jLabel1, java.awt.BorderLayout.EAST);
96
                }
97
                return jPanel;
98
        }
99

    
100
        /**
101
         * This method initializes jPanel1        
102
         *         
103
         * @return javax.swing.JPanel        
104
         */
105
        private JPanel getJPanel1() {
106
                if (jPanel1 == null) {
107
                        jPanel1 = new JPanel();
108
                        jPanel1.setLayout(new java.awt.BorderLayout(5, 5));
109
                        jPanel1.add(getJProgressBar(), java.awt.BorderLayout.NORTH);
110
                        jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
111
                }
112
                return jPanel1;
113
        }
114

    
115
        public void showLog(boolean visible) {
116
                
117
                buttonsPanel.getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible);
118
                buttonsPanel.getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible);
119
                jScrollPane.setVisible(visible);
120

    
121
                int width = (this.getWidth()<400?400:this.getWidth());
122
                int height = (visible?300:120);
123

    
124
                this.setIgnoreRepaint(true);
125
                this.setSize(width, height);
126
                this.setResizable(visible);
127
                this.setIgnoreRepaint(false);
128
                this.show();
129
        }
130

    
131
        public void showPause(boolean visible) {
132
                buttonsPanel.getButton(ButtonsPanel.BUTTON_RESTART).setVisible(!visible);
133
                buttonsPanel.getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(visible);
134
        }
135
        
136
        /**
137
         * This method initializes ButtonsPanel        
138
         *         
139
         * @return ButtonsPanel        
140
         */
141
        public ButtonsPanel getButtonsPanel() {
142
                if (buttonsPanel == null) {
143
                        buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_NONE);
144
                        buttonsPanel.addSeeDetails();
145
                        buttonsPanel.addHideDetails();
146
                        buttonsPanel.addPause();
147
                        buttonsPanel.addRestart();
148
                        showPause(true);
149
                        buttonsPanel.addCancel();
150
                        buttonsPanel.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER));
151
                        buttonsPanel.addActionListener(new java.awt.event.ActionListener() {
152
                                public void actionPerformed(java.awt.event.ActionEvent e) {
153
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_SEEDETAILS + "") == 0) {
154
                                                showLog(true);
155
                                        }
156
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_HIDEDETAILS + "") == 0) {
157
                                                showLog(false);
158
                                        }
159
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_PAUSE + "") == 0) {
160
                                                showPause(false);
161
                                        }
162
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_RESTART + "") == 0) {
163
                                                showPause(true);
164
                                        }
165
                                }
166
                        });
167
                }
168
                return buttonsPanel;
169
        }
170

    
171
        /**
172
         * This method initializes jProgressBar        
173
         *         
174
         * @return javax.swing.JProgressBar        
175
         */
176
        private JProgressBar getJProgressBar() {
177
                if (jProgressBar == null) {
178
                        jProgressBar = new JProgressBar();
179
                        jProgressBar.setValue(50);
180
                }
181
                return jProgressBar;
182
        }
183

    
184
        /**
185
         * This method initializes jScrollPane        
186
         *         
187
         * @return javax.swing.JScrollPane        
188
         */
189
        private JScrollPane getJScrollPane() {
190
                if (jScrollPane == null) {
191
                        jScrollPane = new JScrollPane();
192
                        jScrollPane.setViewportView(getJTextPane());
193
                        jScrollPane.setVisible(false);
194
                }
195
                return jScrollPane;
196
        }
197

    
198
        /**
199
         * This method initializes jTextPane        
200
         *         
201
         * @return javax.swing.JTextPane        
202
         */
203
        private JTextPane getJTextPane() {
204
                if (jTextPane == null) {
205
                        jTextPane = new JTextPane();
206
                        jTextPane.setEditable(false);
207
                }
208
                return jTextPane;
209
        }
210
        
211
        private void updateLog() {
212
                jTextPane.setText(text.getText());
213
                jTextPane.setCaretPosition(jTextPane.getText().length());
214
        }
215

    
216
        public void addLineLog(String line) {
217
                text.addLine(line);
218
                updateLog();
219
        }
220

    
221
        public void replaceLastLineLog(String line) {
222
                text.replaceLastLine(line);
223
                updateLog();
224
        }
225

    
226
        public void setLog(String value) {
227
                text.setText(value);
228
                updateLog();
229
        }
230

    
231
        public int getPercent() {
232
                return jProgressBar.getValue();
233
        }
234

    
235
        public void setPercent(int value) {
236
                jProgressBar.setValue(value);
237
                jLabel1.setText(value + "%");
238
        }
239
        
240
        public void setLabel(String value) {
241
                jLabel.setText(value);
242
        }
243
}