Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / progressPanel / ProgressPanel.java @ 10945

History | View | Annotate | Download (5.85 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
                buttonsPanel.getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible);
117
                buttonsPanel.getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible);
118
                jScrollPane.setVisible(visible);
119

    
120
                int width = 400;
121
                int height = (visible?300:120);
122

    
123
                this.setSize(width, height);
124
                this.show();
125
        }
126
        
127
        /**
128
         * This method initializes ButtonsPanel        
129
         *         
130
         * @return ButtonsPanel        
131
         */
132
        public ButtonsPanel getButtonsPanel() {
133
                if (buttonsPanel == null) {
134
                        buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_NONE);
135
                        buttonsPanel.addSeeDetails();
136
                        buttonsPanel.addHideDetails();
137
                        buttonsPanel.addCancel();
138
                        buttonsPanel.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER));
139
                        buttonsPanel.addActionListener(new java.awt.event.ActionListener() {
140
                                public void actionPerformed(java.awt.event.ActionEvent e) {
141
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_SEEDETAILS + "") == 0) {
142
                                                showLog(true);
143
                                        }
144
                                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_HIDEDETAILS + "") == 0) {
145
                                                showLog(false);
146
                                        }
147
                                }
148
                        });
149
                }
150
                return buttonsPanel;
151
        }
152

    
153
        /**
154
         * This method initializes jProgressBar        
155
         *         
156
         * @return javax.swing.JProgressBar        
157
         */
158
        private JProgressBar getJProgressBar() {
159
                if (jProgressBar == null) {
160
                        jProgressBar = new JProgressBar();
161
                        jProgressBar.setValue(50);
162
                }
163
                return jProgressBar;
164
        }
165

    
166
        /**
167
         * This method initializes jScrollPane        
168
         *         
169
         * @return javax.swing.JScrollPane        
170
         */
171
        private JScrollPane getJScrollPane() {
172
                if (jScrollPane == null) {
173
                        jScrollPane = new JScrollPane();
174
                        jScrollPane.setViewportView(getJTextPane());
175
                        jScrollPane.setVisible(false);
176
                }
177
                return jScrollPane;
178
        }
179

    
180
        /**
181
         * This method initializes jTextPane        
182
         *         
183
         * @return javax.swing.JTextPane        
184
         */
185
        private JTextPane getJTextPane() {
186
                if (jTextPane == null) {
187
                        jTextPane = new JTextPane();
188
                        jTextPane.setEditable(false);
189
                }
190
                return jTextPane;
191
        }
192
        
193
        private void updateLog() {
194
                jTextPane.setText(text.getText());
195
        }
196

    
197
        public void addLineLog(String line) {
198
                text.addLine(line);
199
                updateLog();
200
        }
201

    
202
        public void replaceLastLineLog(String line) {
203
                text.replaceLastLine(line);
204
                updateLog();
205
        }
206

    
207
        public void setLog(String value) {
208
                text.setText(value);
209
                updateLog();
210
        }
211

    
212
        public int getPercent() {
213
                return jProgressBar.getValue();
214
        }
215

    
216
        public void setPercent(int value) {
217
                jProgressBar.setValue(value);
218
                jLabel1.setText(value + "%");
219
        }
220
        
221
        public void setLabel(String value) {
222
                jLabel.setText(value);
223
        }
224
}