Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.main / src / main / java / org / gvsig / installer / main / utils / CreateBoundleFrame.java @ 40560

History | View | Annotate | Download (5.74 KB)

1 40560 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40560 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 40435 jjdelcerro
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8 40560 jjdelcerro
 * as published by the Free Software Foundation; either version 3
9 40435 jjdelcerro
 * of the License, or (at your option) any later version.
10 40560 jjdelcerro
 *
11 40435 jjdelcerro
 * 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 40560 jjdelcerro
 *
16 40435 jjdelcerro
 * 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 40560 jjdelcerro
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 40435 jjdelcerro
 * MA  02110-1301, USA.
20 40560 jjdelcerro
 *
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 40435 jjdelcerro
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {Prodevelop}   {Task}
27
 */
28
29
package org.gvsig.installer.main.utils;
30
31
import java.awt.HeadlessException;
32
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
34
import java.awt.event.WindowEvent;
35
import java.awt.event.WindowListener;
36
import java.io.File;
37
import java.io.FileOutputStream;
38
import java.util.ArrayList;
39
import java.util.List;
40
41
import javax.swing.JFrame;
42
import javax.swing.JOptionPane;
43
44
import org.gvsig.gui.beans.openfile.FileTextField;
45
import org.gvsig.installer.lib.impl.utils.Compress;
46
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
49
 */
50
public class CreateBoundleFrame extends JFrame implements WindowListener,
51
                ActionListener {
52
53
        /**
54
     *
55
     */
56
        private static final long serialVersionUID = -2128261599641241144L;
57
        private javax.swing.JButton executeButton;
58
        private javax.swing.JLabel inputLabel;
59
        private FileTextField inputText;
60
        private javax.swing.JLabel jLabel2;
61
        private FileTextField outputText;
62
63
        public CreateBoundleFrame() throws HeadlessException {
64
                super();
65
                initializeComponents();
66
                this.addWindowListener(this);
67
                executeButton.addActionListener(this);
68
        }
69
70
        private void initializeComponents() {
71
                java.awt.GridBagConstraints gridBagConstraints;
72
73
                inputLabel = new javax.swing.JLabel();
74
                executeButton = new javax.swing.JButton();
75
                inputText = new FileTextField();
76
                outputText = new FileTextField();
77
                jLabel2 = new javax.swing.JLabel();
78
79
                setLayout(new java.awt.GridBagLayout());
80
81
                inputLabel.setText("Input directory");
82
                gridBagConstraints = new java.awt.GridBagConstraints();
83
                gridBagConstraints.gridx = 0;
84
                gridBagConstraints.gridy = 0;
85
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
86
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
87
                add(inputLabel, gridBagConstraints);
88
89
                executeButton.setText("Execute");
90
                gridBagConstraints = new java.awt.GridBagConstraints();
91
                gridBagConstraints.gridx = 1;
92
                gridBagConstraints.gridy = 2;
93
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
94
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
95
                add(executeButton, gridBagConstraints);
96
97
                gridBagConstraints = new java.awt.GridBagConstraints();
98
                gridBagConstraints.gridx = 1;
99
                gridBagConstraints.gridy = 0;
100
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
101
                gridBagConstraints.ipadx = 67;
102
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
103
                gridBagConstraints.weightx = 1.0;
104
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
105
                add(inputText, gridBagConstraints);
106
107
                gridBagConstraints = new java.awt.GridBagConstraints();
108
                gridBagConstraints.gridx = 1;
109
                gridBagConstraints.gridy = 1;
110
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
111
                gridBagConstraints.ipadx = 67;
112
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
113
                gridBagConstraints.weightx = 1.0;
114
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
115
                add(outputText, gridBagConstraints);
116
117
                jLabel2.setText("Output");
118
                gridBagConstraints = new java.awt.GridBagConstraints();
119
                gridBagConstraints.gridx = 0;
120
                gridBagConstraints.gridy = 1;
121
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
122
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
123
                add(jLabel2, gridBagConstraints);
124
125
        }
126
127
        public void windowActivated(WindowEvent arg0) {
128
                // TODO Auto-generated method stub
129
130
        }
131
132
        public void windowClosed(WindowEvent arg0) {
133
                System.exit(0);
134
135
        }
136
137
        public void windowClosing(WindowEvent arg0) {
138
                // TODO Auto-generated method stub
139
140
        }
141
142
        public void windowDeactivated(WindowEvent arg0) {
143
                // TODO Auto-generated method stub
144
145
        }
146
147
        public void windowDeiconified(WindowEvent arg0) {
148
                // TODO Auto-generated method stub
149
150
        }
151
152
        public void windowIconified(WindowEvent arg0) {
153
                // TODO Auto-generated method stub
154
155
        }
156
157
        public void windowOpened(WindowEvent arg0) {
158
                // TODO Auto-generated method stub
159
160
        }
161
162
        public void actionPerformed(ActionEvent arg0) {
163
                File inputDirectory = inputText.getSelectedFile();
164
                File outputFile = outputText.getSelectedFile();
165
166
                if (!inputDirectory.exists()) {
167
                        JOptionPane
168
                                        .showMessageDialog(this, "Input directory doesn't exist");
169
                        return;
170
                }
171
172
                if (outputFile.exists()) {
173
                        outputFile.delete();
174
                }
175
176
                Compress compress = new Compress();
177
                try {
178
                        File[] files = inputDirectory.listFiles();
179
                        List<File> filesArray = new ArrayList<File>();
180
                        List<String> fileNamesArray = new ArrayList<String>();
181
                        for (int i = 0; i < files.length; i++) {
182
                                if (!files[i].getName().toUpperCase().equals(".SVN")) {
183
                                        filesArray.add(files[i]);
184
                                        fileNamesArray.add(files[i].getName());
185
                                }
186
                        }
187
                        compress.compressPluginsAsPackageSet(filesArray, fileNamesArray,
188
                                        new FileOutputStream(outputFile));
189
                } catch (Exception e) {
190
                        JOptionPane.showMessageDialog(this, e.toString());
191
                }
192
        }
193
}