Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2021 / extensions / org.gvsig.installer / org.gvsig.installer.main / src / main / java / org / gvsig / installer / main / utils / CreateBoundleFrame.java @ 34107

History | View | Annotate | Download (6.33 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.main.utils;
29

    
30
import java.awt.HeadlessException;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.WindowEvent;
34
import java.awt.event.WindowListener;
35
import java.io.File;
36
import java.io.FileOutputStream;
37
import java.util.ArrayList;
38
import java.util.List;
39

    
40
import javax.swing.JFrame;
41
import javax.swing.JOptionPane;
42

    
43
import org.gvsig.gui.beans.openfile.FileTextField;
44
import org.gvsig.installer.lib.impl.utils.Compress;
45

    
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
48
 */
49
public class CreateBoundleFrame extends JFrame implements WindowListener,
50
    ActionListener {
51

    
52
    /**
53
     * 
54
     */
55
    private static final long serialVersionUID = -2128261599641241144L;
56
    private javax.swing.JButton executeButton;
57
    private javax.swing.JLabel inputLabel;
58
    private FileTextField inputText;
59
    private javax.swing.JLabel jLabel2;
60
    private FileTextField outputText;
61

    
62
    public CreateBoundleFrame() throws HeadlessException {
63
        super();
64
        initializeComponents();
65
        this.addWindowListener(this);
66
        executeButton.addActionListener(this);
67
    }
68

    
69
    private void initializeComponents() {
70
        java.awt.GridBagConstraints gridBagConstraints;
71

    
72
        inputLabel = new javax.swing.JLabel();
73
        executeButton = new javax.swing.JButton();
74
        inputText = new FileTextField();
75
        outputText = new FileTextField();
76
        jLabel2 = new javax.swing.JLabel();
77

    
78
        setLayout(new java.awt.GridBagLayout());
79

    
80
        inputLabel.setText("Input directory");
81
        gridBagConstraints = new java.awt.GridBagConstraints();
82
        gridBagConstraints.gridx = 0;
83
        gridBagConstraints.gridy = 0;
84
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
85
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
86
        add(inputLabel, gridBagConstraints);
87

    
88
        executeButton.setText("Execute");
89
        gridBagConstraints = new java.awt.GridBagConstraints();
90
        gridBagConstraints.gridx = 1;
91
        gridBagConstraints.gridy = 2;
92
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
93
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
94
        add(executeButton, gridBagConstraints);
95

    
96
        gridBagConstraints = new java.awt.GridBagConstraints();
97
        gridBagConstraints.gridx = 1;
98
        gridBagConstraints.gridy = 0;
99
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100
        gridBagConstraints.ipadx = 67;
101
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
102
        gridBagConstraints.weightx = 1.0;
103
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
104
        add(inputText, gridBagConstraints);
105

    
106
        gridBagConstraints = new java.awt.GridBagConstraints();
107
        gridBagConstraints.gridx = 1;
108
        gridBagConstraints.gridy = 1;
109
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
110
        gridBagConstraints.ipadx = 67;
111
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
112
        gridBagConstraints.weightx = 1.0;
113
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
114
        add(outputText, gridBagConstraints);
115

    
116
        jLabel2.setText("Output");
117
        gridBagConstraints = new java.awt.GridBagConstraints();
118
        gridBagConstraints.gridx = 0;
119
        gridBagConstraints.gridy = 1;
120
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
121
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
122
        add(jLabel2, gridBagConstraints);
123

    
124
    }
125

    
126
    public void windowActivated(WindowEvent arg0) {
127
        // TODO Auto-generated method stub
128

    
129
    }
130

    
131
    public void windowClosed(WindowEvent arg0) {
132
        System.exit(0);
133

    
134
    }
135

    
136
    public void windowClosing(WindowEvent arg0) {
137
        // TODO Auto-generated method stub
138

    
139
    }
140

    
141
    public void windowDeactivated(WindowEvent arg0) {
142
        // TODO Auto-generated method stub
143

    
144
    }
145

    
146
    public void windowDeiconified(WindowEvent arg0) {
147
        // TODO Auto-generated method stub
148

    
149
    }
150

    
151
    public void windowIconified(WindowEvent arg0) {
152
        // TODO Auto-generated method stub
153

    
154
    }
155

    
156
    public void windowOpened(WindowEvent arg0) {
157
        // TODO Auto-generated method stub
158

    
159
    }
160

    
161
    public void actionPerformed(ActionEvent arg0) {
162
        File inputDirectory = inputText.getSelectedFile();
163
        File outputFile = outputText.getSelectedFile();
164

    
165
        if (!inputDirectory.exists()) {
166
            JOptionPane
167
                .showMessageDialog(this, "Input directory doesn't exist");
168
            return;
169
        }
170

    
171
        if (outputFile.exists()) {
172
            outputFile.delete();
173
        }
174

    
175
        Compress compress = new Compress();
176
        try {
177
            File[] files = inputDirectory.listFiles();
178
            List<File> filesArray = new ArrayList<File>();
179
            List<String> fileNamesArray = new ArrayList<String>();
180
            for (int i = 0; i < files.length; i++) {
181
                if (!files[i].getName().toUpperCase().equals(".SVN")) {
182
                    filesArray.add(files[i]);
183
                    fileNamesArray.add(files[i].getName());
184
                }
185
            }
186
            compress.compressPluginsAsPackageSet(filesArray, fileNamesArray,
187
                new FileOutputStream(outputFile));
188
        } catch (Exception e) {
189
            JOptionPane.showMessageDialog(this, e.toString());
190
        }
191
    }
192
}