Statistics
| Revision:

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

History | View | Annotate | Download (5.78 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
/**
35
 * <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar
36
 * una barra de progreso con su ventana de registro.
37
 *
38
 * @version 20/03/2007
39
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
40
 */
41
public class ProgressPanel extends JFrame {
42
        private static final long serialVersionUID = -6930857769971064429L;
43
        private JPanel jPanel = null;
44
        private JLabel jLabel = null;
45
        private JLabel jLabel1 = null;
46
        private JPanel jPanel1 = null;
47
        private JPanel njp = null;
48
        private ButtonsPanel buttonsPanel = null;
49
        private JProgressBar jProgressBar = null;
50
        private JScrollPane jScrollPane = null;
51
        private JTextPane jTextPane = null;
52
        private String realText = "";
53

    
54
        /**
55
         * Constructor
56
         */
57
        public ProgressPanel() {
58
                // TODO Auto-generated constructor stub
59
                initialize();
60
        }
61

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

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

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

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

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

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

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

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

    
182
        /**
183
         * This method initializes jTextPane        
184
         *         
185
         * @return javax.swing.JTextPane        
186
         */
187
        private JTextPane getJTextPane() {
188
                if (jTextPane == null) {
189
                        jTextPane = new JTextPane();
190
                        jTextPane.setEditable(false);
191
                }
192
                return jTextPane;
193
        }
194
        
195
        public void addLineLog(String line) {
196
                realText = jTextPane.getText();
197
                jTextPane.setText(realText + line + "\n");
198
                
199
        }
200

    
201
        public void replaceLastLineLog(String line) {
202
                jTextPane.setText(realText + line + "\n");
203
        }
204
        
205
        public int getPercent() {
206
                return jProgressBar.getValue();
207
        }
208

    
209
        public void setPercent(int value) {
210
                jProgressBar.setValue(value);
211
                jLabel1.setText(value + "%");
212
        }
213
        
214
        public void setLabel(String value) {
215
                jLabel.setText(value);
216
        }
217
}