Revision 38366

View differences:

tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue May 29 16:42:18 CEST 2012
3
buildNumber=2046
0 4

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue May 29 16:42:19 CEST 2012
3
buildNumber=2047
0 4

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/java/org/gvsig/symbology/app/importsymbols/panel/SelectSymbolsFolderImportPanel.java
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
package org.gvsig.symbology.app.importsymbols.panel;
23

  
24
import java.awt.event.ActionEvent;
25
import java.awt.event.MouseEvent;
26
import java.awt.event.MouseListener;
27
import java.io.File;
28
import java.util.ArrayList;
29

  
30
import javax.swing.JList;
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33
import javax.swing.ListSelectionModel;
34

  
35
import org.gvsig.andami.PluginsLocator;
36
import org.gvsig.andami.PluginsManager;
37

  
38
/**
39
 * @author gvSIG Team
40
 * @version $Id$
41
 * 
42
 */
43
public class SelectSymbolsFolderImportPanel extends JPanel {
44

  
45
    private static final long serialVersionUID = 948949741432221418L;
46

  
47
    private JList folderJList;
48
    private File symbolsDirectory = null;
49
    private ArrayList<String> folders = null;
50

  
51
    private ImportSymbolsPanel importSymbolsPanel;
52

  
53
    public SelectSymbolsFolderImportPanel(ImportSymbolsPanel importSymbolsPanel) {
54
        super();
55
        this.importSymbolsPanel = importSymbolsPanel;
56
        initComponents();
57
    }
58

  
59
    private void initComponents() {
60

  
61
        // JLabel symbolsFolderLabel =
62
        // new JLabel(getText("_select_folder_destination") + ":");
63

  
64
        PluginsManager pluginManager = PluginsLocator.getManager();
65
        symbolsDirectory =
66
            new File(pluginManager.getApplicationHomeFolder() + File.separator
67
                + "Symbols");
68

  
69
        String[] itemsArray = symbolsDirectory.list();
70
        folders = new ArrayList<String>();
71

  
72
        for (int i = 0; i < itemsArray.length; i++) {
73
            File f = new File(symbolsDirectory, itemsArray[i]);
74
            if (f.isDirectory()) {
75
                folders.add(itemsArray[i]);
76
            }
77
        }
78

  
79
        folderJList = new JList(folders.toArray());
80
        folderJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
81

  
82
        folderJList.addMouseListener(new MouseClickListener(this));
83

  
84
        // setLayout(new BorderLayout(2, 2));
85
        // setBounds(2, 2, 200, 200);
86

  
87
        // add(symbolsFolderLabel, BorderLayout.NORTH);
88

  
89
        JScrollPane scroller = new JScrollPane(folderJList);
90

  
91
        add(scroller);
92
    }
93

  
94
    public String getSelectedFolder() {
95
        String folderName = folders.get(folderJList.getSelectedIndex());
96
        // return new File(symbolsDirectory + "/" + folderName.toString());
97
        return folderName;
98
    }
99

  
100
    public void setSelectedFolder(File selectedFile) {
101
        folderJList.setSelectedValue(selectedFile, true);
102
    }
103

  
104
    public void actionPerformed(ActionEvent arg0) {
105
        // TODO Auto-generated method stub
106
    }
107

  
108
    private class MouseClickListener implements MouseListener {
109

  
110
        private SelectSymbolsFolderImportPanel parent;
111

  
112
        public MouseClickListener(SelectSymbolsFolderImportPanel parent) {
113
            this.parent = parent;
114
        }
115

  
116
        public void mouseReleased(MouseEvent e) {
117
            // do nothing
118
        }
119

  
120
        public void mousePressed(MouseEvent e) {
121
            // do nothing
122
        }
123

  
124
        public void mouseExited(MouseEvent e) {
125
            // do nothing
126
        }
127

  
128
        public void mouseEntered(MouseEvent e) {
129
            // do nothing
130
        }
131

  
132
        public void mouseClicked(MouseEvent e) {
133
            String selectedFile = this.parent.getSelectedFolder();
134
            this.parent.importSymbolsPanel.setTextFieldFolder(selectedFile);
135
            importSymbolsPanel.updatePanel();
136
        }
137
    }
138

  
139
    // private String getText(String string) {
140
    // return Messages.getText(string);
141
    // }
142

  
143
}
0 144

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/java/org/gvsig/symbology/app/importsymbols/panel/ImportSymbolsPanel.java
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
package org.gvsig.symbology.app.importsymbols.panel;
23

  
24
import java.awt.Dimension;
25
import java.awt.FlowLayout;
26
import java.awt.event.ActionEvent;
27
import java.beans.PropertyChangeListener;
28
import java.io.File;
29
import java.util.ArrayList;
30
import java.util.HashSet;
31
import java.util.Set;
32

  
33
import javax.swing.Action;
34
import javax.swing.JButton;
35
import javax.swing.JFileChooser;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
import javax.swing.JTextField;
39
import javax.swing.border.EmptyBorder;
40
import javax.swing.filechooser.FileFilter;
41

  
42
import org.gvsig.fmap.mapcontext.MapContextLocator;
43
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
44
import org.gvsig.symbology.app.importsymbols.wizard.ImportSymbolsWizard;
45
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
47

  
48
/**
49
 * @author gvSIG Team
50
 * @version $Id$
51
 * 
52
 */
53
public class ImportSymbolsPanel extends JPanel {
54

  
55
    private static final long serialVersionUID = 8666781163497235054L;
56

  
57
    private static final Set<String> imageExtensionsAllowed;
58
    static {
59
        imageExtensionsAllowed = new HashSet<String>();
60
        imageExtensionsAllowed.add("png");
61
        imageExtensionsAllowed.add("jpg");
62
        imageExtensionsAllowed.add("jpeg");
63
        imageExtensionsAllowed.add("gif");
64
        imageExtensionsAllowed.add("bmp");
65
        imageExtensionsAllowed.add("svg");
66
    }
67

  
68
    ImportSymbolsWizard wizard;
69

  
70
    private JButton botonImportar;
71
    private JButton botonCerrar;
72
    private JButton botonExaminar;
73
    private JLabel labelOrigen;
74
    private JLabel labelDestino;
75
    private JTextField textFieldOrigen;
76
    private JTextField textFieldDestino;
77
    private JFileChooser fc = null;
78

  
79
    private File destinationFolder;
80

  
81
    private SelectSymbolsFolderImportPanel symbolsPanel;
82

  
83
    public ImportSymbolsPanel(ImportSymbolsWizard wizard) {
84
        super();
85
        this.wizard = wizard;
86
        initComponents();
87
        createGUI();
88
    }
89

  
90
    private void initComponents() {
91

  
92
        // primer seleccio de carpeta origen
93
        labelOrigen =
94
            new JLabel("1) " + getText("_select_images_to_import") + ":");
95

  
96
        // despres seleccio carpeta desti
97
        labelDestino =
98
            new JLabel("2) " + getText("_select_destination_folder") + ":");
99

  
100
        textFieldOrigen = new JTextField(20);
101
        textFieldDestino = new JTextField(20);
102

  
103
        symbolsPanel = new SelectSymbolsFolderImportPanel(this);
104
    }
105

  
106
    private void createGUI() {
107

  
108
        // java.awt.FlowLayout flowLayout;
109
        // this.setLayout(new java.awt.FlowLayout());
110

  
111
        java.awt.GridBagConstraints gridBagConstraints;
112
        this.setLayout(new java.awt.GridBagLayout());
113

  
114
        // this.setSize(500,500);
115

  
116
        // Add an empty margin
117
        this.setBorder(new EmptyBorder(5, 5, 5, 5));
118

  
119
        this.setBounds(3, 3, 2000, 2000);
120

  
121
        UsabilitySwingManager usabilitymanager =
122
            ToolsSwingLocator.getUsabilitySwingManager();
123

  
124
        // JLabel layerText = new JLabel("_Select_a_layer:");
125
        // JLabel transformText = new JLabel("_Select_a_transform:");
126
        JPanel botones = new JPanel();
127

  
128
        gridBagConstraints = new java.awt.GridBagConstraints();
129
        // gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
131
        gridBagConstraints.gridwidth = 2;
132
        gridBagConstraints.gridx = 0;
133
        gridBagConstraints.gridy = 0;
134
        gridBagConstraints.weightx = 1.0;
135
        gridBagConstraints.weighty = 0.0;
136
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
137
        this.add(labelOrigen, gridBagConstraints);
138

  
139
        gridBagConstraints = new java.awt.GridBagConstraints();
140
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
141
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142
        gridBagConstraints.gridx = 0;
143
        gridBagConstraints.gridy = 1;
144
        gridBagConstraints.weightx = 1.0;
145
        gridBagConstraints.weighty = 0.0;
146
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
147
        this.add(textFieldOrigen, gridBagConstraints);
148

  
149
        gridBagConstraints = new java.awt.GridBagConstraints();
150
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151
        gridBagConstraints.gridx = 1;
152
        gridBagConstraints.gridy = 1;
153
        gridBagConstraints.weightx = 0.0;
154
        gridBagConstraints.weighty = 0.0;
155
        botonExaminar = usabilitymanager.createJButton(new ActionExamine());
156
        botonExaminar.setText("_examinar");
157
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
158
        this.add(botonExaminar, gridBagConstraints);
159

  
160
        gridBagConstraints = new java.awt.GridBagConstraints();
161
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
162
        gridBagConstraints.gridwidth = 2;
163
        gridBagConstraints.gridx = 0;
164
        gridBagConstraints.gridy = 2;
165
        gridBagConstraints.weightx = 1.0;
166
        gridBagConstraints.weighty = 0.0;
167
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
168
        this.add(labelDestino, gridBagConstraints);
169

  
170
        gridBagConstraints = new java.awt.GridBagConstraints();
171
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
173
        gridBagConstraints.gridwidth = 2;
174
        gridBagConstraints.gridx = 0;
175
        gridBagConstraints.gridy = 3;
176
        gridBagConstraints.weightx = 1.0;
177
        gridBagConstraints.weighty = 0.0;
178
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
179
        this.add(textFieldDestino, gridBagConstraints);
180

  
181
        gridBagConstraints = new java.awt.GridBagConstraints();
182
        // gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
183
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
184
        gridBagConstraints.gridwidth = 2;
185
        gridBagConstraints.gridx = 0;
186
        gridBagConstraints.gridy = 4;
187
        gridBagConstraints.weightx = 1.0;
188
        gridBagConstraints.weighty = 1.0;
189
        gridBagConstraints.insets = new java.awt.Insets(10, 2, 5, 2);
190
        this.add(symbolsPanel, gridBagConstraints);
191

  
192
        botones.setLayout(new FlowLayout(FlowLayout.RIGHT));
193
        botonImportar = usabilitymanager.createJButton(new ActionImport(this));
194
        botonImportar.setText("_Import_simbols");
195
        botonCerrar = usabilitymanager.createJButton(new ActionClose(this));
196
        botonCerrar.setText("_Cancel");
197
        botones.add(botonImportar);
198
        botones.add(botonCerrar);
199
        botonImportar.setEnabled(false);
200

  
201
        gridBagConstraints = new java.awt.GridBagConstraints();
202
        gridBagConstraints.gridx = 0;
203
        gridBagConstraints.gridy = 5;
204
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
205
        gridBagConstraints.gridwidth = 2;
206
        gridBagConstraints.weightx = 1.0;
207
        gridBagConstraints.weighty = 0.0;
208
        gridBagConstraints.insets = new java.awt.Insets(10, 2, 2, 2);
209
        this.add(botones, gridBagConstraints);
210

  
211
        botonImportar.setEnabled(false);
212

  
213
        updatePanel();
214
    }
215

  
216
    private void showFileChooser() {
217
        // Create a file chooser
218
        fc = new JFileChooser();
219
        // Component parent = null;
220

  
221
        // the fileChooser will only accept jpg, gif, png, jpeg, bmp and svg
222
        // image formats
223
        fc.setFileFilter(new FileFilter() {
224

  
225
            /*
226
             * Get the extension of a file.
227
             */
228
            public String getExtension(File f) {
229
                String ext = null;
230
                String s = f.getName();
231
                int i = s.lastIndexOf('.');
232

  
233
                if (i > 0 && i < s.length() - 1) {
234
                    ext = s.substring(i + 1).toLowerCase();
235
                }
236
                return ext;
237
            }
238

  
239
            @Override
240
            public String getDescription() {
241
                return "JPG, GIF, PNG, JPEG, BMP & SVG Images";
242
            }
243

  
244
            @Override
245
            public boolean accept(File f) {
246
                if (f.isDirectory()) {
247
                    return true;
248
                }
249

  
250
                String extension = getExtension(f);
251
                return extension != null
252
                    && imageExtensionsAllowed.contains(extension);
253
            }
254
        });
255

  
256
        fc.setMultiSelectionEnabled(true);
257

  
258
        // fc.showDialog(parent, getText("_Import_symbols"));
259
        fc.showDialog(getParent(), getText("_Select_symbols"));
260

  
261
    }
262

  
263
    public ArrayList<File> getSelectedImages() {
264
        ArrayList<File> selectedImagesList = new ArrayList<File>();
265

  
266
        // TODO: comprobar que passa quan no se selecciona cap arxiu
267
        for (int i = 0; i < fc.getSelectedFiles().length; i++) {
268
            selectedImagesList.add(fc.getSelectedFiles()[i]);
269
        }
270
        return selectedImagesList;
271
    }
272

  
273
    @Override
274
    public Dimension getPreferredSize() {
275
        return new Dimension(250, 300);
276
    }
277

  
278
    private class ActionExamine implements Action {
279

  
280
        public void addPropertyChangeListener(PropertyChangeListener arg0) {
281
        }
282

  
283
        public Object getValue(String arg0) {
284
            return null;
285
        }
286

  
287
        public boolean isEnabled() {
288
            return true;
289
        }
290

  
291
        public void putValue(String arg0, Object arg1) {
292
        }
293

  
294
        public void removePropertyChangeListener(PropertyChangeListener arg0) {
295
        }
296

  
297
        public void setEnabled(boolean arg0) {
298
        }
299

  
300
        public void actionPerformed(ActionEvent arg0) {
301
            showFileChooser();
302

  
303
            // set textFieldOrigen with the selected images
304
            ArrayList<File> selectedImagesList = getSelectedImages();
305

  
306
            // comprobar si s'ha seleccionat alguna imatge...
307
            // if (selectedImagesList != null) {
308
            String textOrigen = null;
309
            for (int i = 0; i < selectedImagesList.size(); i++) {
310
                if (textOrigen == null) {
311
                    textOrigen = selectedImagesList.get(i).getName();
312
                } else {
313
                    textOrigen += ", " + selectedImagesList.get(i).getName();
314
                }
315
            }
316
            // }
317
            textFieldOrigen.setText(textOrigen);
318
            updatePanel();
319
        }
320

  
321
    }
322

  
323
    private class ActionImport implements Action {
324

  
325
        private ImportSymbolsPanel parent;
326

  
327
        public ActionImport(ImportSymbolsPanel parent) {
328
            this.parent = parent;
329
        }
330

  
331
        public void addPropertyChangeListener(PropertyChangeListener listener) {
332
        }
333

  
334
        public Object getValue(String key) {
335
            return null;
336
        }
337

  
338
        public boolean isEnabled() {
339
            return true;
340
        }
341

  
342
        public void putValue(String key, Object value) {
343
        }
344

  
345
        public void removePropertyChangeListener(PropertyChangeListener listener) {
346
        }
347

  
348
        public void setEnabled(boolean b) {
349
        }
350

  
351
        public void actionPerformed(ActionEvent e) {
352
            updatePanel();
353
            wizard.addImages();
354
            this.parent.wizard.setVisible(false);
355
        }
356

  
357
    }
358

  
359
    private class ActionClose implements Action {
360

  
361
        private ImportSymbolsPanel parent;
362

  
363
        public ActionClose(ImportSymbolsPanel parent) {
364
            this.parent = parent;
365
        }
366

  
367
        public void addPropertyChangeListener(PropertyChangeListener listener) {
368
        }
369

  
370
        public Object getValue(String key) {
371
            return null;
372
        }
373

  
374
        public boolean isEnabled() {
375
            return true;
376
        }
377

  
378
        public void putValue(String key, Object value) {
379
        }
380

  
381
        public void removePropertyChangeListener(PropertyChangeListener listener) {
382
        }
383

  
384
        public void setEnabled(boolean b) {
385
        }
386

  
387
        public void actionPerformed(ActionEvent e) {
388
            this.parent.wizard.setVisible(false);
389
        }
390

  
391
    }
392

  
393
    public void updatePanel() {
394

  
395
        SymbolManager manager = MapContextLocator.getSymbolManager();
396
        File symbolsFolder =
397
            new File(manager.getSymbolPreferences().getSymbolLibraryPath());
398

  
399
        // update destination folder
400
        if (textFieldDestino.getText().equals("")) {
401
            destinationFolder = symbolsFolder;
402
        } else {
403
            destinationFolder =
404
                new File(symbolsFolder + "/" + textFieldDestino.getText());
405
        }
406

  
407
        if (fc != null) {
408
            if (fc.getSelectedFiles().length > 0) {
409
                botonImportar.setEnabled(true);
410
            } else {
411
                botonImportar.setEnabled(false);
412
            }
413
        } else {
414
            botonImportar.setEnabled(false);
415
        }
416

  
417
        textFieldOrigen.getText();
418

  
419
    }
420

  
421
    private String getText(String msg) {
422
        return msg;
423
    }
424

  
425
    public void setTextFieldFolder(String selectedFile) {
426
        textFieldDestino.setText(selectedFile);
427
    }
428

  
429
    public File getDestinationFolder() {
430
        return destinationFolder;
431
    }
432

  
433
}
0 434

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/java/org/gvsig/symbology/app/importsymbols/ImportSymbolsExtension.java
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
package org.gvsig.symbology.app.importsymbols;
24

  
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.andami.ui.ToolsWindowManager;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.symbology.app.importsymbols.wizard.ImportSymbolsWizard;
29
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
30

  
31
public class ImportSymbolsExtension extends Extension {
32

  
33
    public void initialize() {
34

  
35
    }
36

  
37
    @Override
38
    public void postInitialize() {
39

  
40
    }
41

  
42
    public boolean isEnabled() {
43
        return true;
44
    }
45

  
46
    public boolean isVisible() {
47
        return true;
48
    }
49

  
50
    public void execute(String actionCommand) {
51
        if (actionCommand.equalsIgnoreCase("Import_symbols")) {
52

  
53
            ImportSymbolsWizard wizard = new ImportSymbolsWizard();
54

  
55
            WindowManager windowManager = new ToolsWindowManager();
56
            windowManager.showWindow(wizard,
57
                Messages.getText("_Import_wizard"), WindowManager.MODE.DIALOG);
58

  
59
        }
60
    }
61

  
62
}
0 63

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/java/org/gvsig/symbology/app/importsymbols/wizard/ImportSymbolsWizard.java
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
package org.gvsig.symbology.app.importsymbols.wizard;
23

  
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.FileOutputStream;
27
import java.io.IOException;
28
import java.net.URL;
29
import java.text.MessageFormat;
30
import java.util.ArrayList;
31

  
32
import javax.swing.JOptionPane;
33
import javax.swing.JPanel;
34

  
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
import org.gvsig.fmap.mapcontext.MapContextLocator;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
40
import org.gvsig.symbology.SymbologyLocator;
41
import org.gvsig.symbology.SymbologyManager;
42
import org.gvsig.symbology.app.importsymbols.ImportSymbolsExtension;
43
import org.gvsig.symbology.app.importsymbols.panel.ImportSymbolsPanel;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.persistence.PersistenceManager;
47
import org.gvsig.tools.persistence.PersistentState;
48
import org.gvsig.tools.persistence.exception.PersistenceException;
49
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
50

  
51
/**
52
 * @author gvSIG Team
53
 * @version $Id$
54
 * 
55
 */
56
public class ImportSymbolsWizard extends JPanel {
57

  
58
    private static final long serialVersionUID = 3659310319939677441L;
59
    private static Logger LOG =
60
        LoggerFactory.getLogger(ImportSymbolsExtension.class);
61

  
62
    private ImportSymbolsPanel panel = null;
63

  
64
    public ImportSymbolsWizard() {
65
        super();
66
        panel = new ImportSymbolsPanel(this);
67
        this.add(panel);
68
    }
69

  
70
    public String getPanelTitle() {
71
        return getText("_Import_Symbols");
72
    }
73

  
74
    public JPanel getPanel() {
75
        return panel;
76
    }
77

  
78
    public void addImages() {
79
        ArrayList<File> selectedImageFiles = panel.getSelectedImages();
80

  
81
        for (int i = 0; i < selectedImageFiles.size(); i++) {
82
            try {
83
                addImageSymbol(selectedImageFiles.get(i));
84
            } catch (IOException e) {
85
                LOG
86
                    .error(
87
                        MessageFormat
88
                            .format(
89
                                getText("_An error_ocurred_creating_the_symbol_related_to_{0}"),
90
                                selectedImageFiles.get(i).getAbsolutePath()), e);
91

  
92
                // Error message, the symbol may not have been imported.
93
                JOptionPane
94
                    .showMessageDialog(
95
                        null,
96
                        MessageFormat
97
                            .format(
98
                                getText("_An_error_ocurred_creating_the_simbol_related_to_{0}"),
99
                                selectedImageFiles.get(i).getAbsolutePath()),
100
                        "_Import_symbols", JOptionPane.ERROR_MESSAGE);
101
            }
102
        }
103
        // Message that the import has finished, with or without errors.
104
        JOptionPane.showMessageDialog(null,
105
            getText("_Importing_symbols_has_finished."), "_Import_symbols",
106
            JOptionPane.INFORMATION_MESSAGE);
107
    }
108

  
109
    private void addImageSymbol(File image) throws IOException {
110

  
111
        int option;
112
        boolean sobreescribir = true;
113
        File selImage = getSelImage(image);
114

  
115
        // if home/gvSIG/Symbols does not exist, it is created.
116
        if (!getOutputFolderPath().exists()) {
117
            getOutputFolderPath().mkdir();
118
        }
119

  
120
        File imageOut = new File(getOutputFolderPath() + "/" + image.getName());
121
        File selImageOut =
122
            new File(getOutputFolderPath() + "/" + selImage.getName());
123

  
124
        // Overwrite or not
125
        if (imageOut.exists()) {
126
            Object[] options = { getText("_Overwrite"), getText("_Cancel") };
127

  
128
            option =
129
                JOptionPane
130
                    .showOptionDialog(
131
                        null,
132
                        MessageFormat
133
                            .format(
134
                                getText("The file_{0}_already_exists.\n\n_Do_you_want_to_overwrite_it?"),
135
                                imageOut.getPath()),
136
                        getText("_Import_symbols"), JOptionPane.DEFAULT_OPTION,
137
                        JOptionPane.INFORMATION_MESSAGE, null, options,
138
                        options[0]);
139

  
140
            if (option == 1) {
141
                sobreescribir = false;
142
            }
143
        }
144

  
145
        SymbologyManager manager = SymbologyLocator.getSymbologyManager();
146
        SymbolManager symbolManager = MapContextLocator.getSymbolManager();
147

  
148
        if (sobreescribir) {
149
            try {
150

  
151
                // Copies the image to the output folder
152
                copy(image, imageOut);
153

  
154
                URL imageURL = imageOut.toURI().toURL();
155
                URL selImageURL = null;
156

  
157
                // tries to copy the selection image
158
                if (selImage.exists()) {
159
                    copy(selImage, selImageOut);
160
                    selImageURL = selImageOut.toURI().toURL();
161
                }
162

  
163
                IPictureMarkerSymbol symbol =
164
                    manager.createPictureMarkerSymbol(imageURL, selImageURL);
165

  
166
                PersistenceManager persistenceManager =
167
                    ToolsLocator.getPersistenceManager();
168

  
169
                PersistentState state = persistenceManager.getState(symbol);
170

  
171
                // change file extension
172
                String outFileName =
173
                    deleteExtension(imageOut)
174
                        + symbolManager.getSymbolPreferences()
175
                            .getSymbolFileExtension();
176

  
177
                FileOutputStream out = new FileOutputStream(outFileName);
178
                persistenceManager.saveState(state, out);
179

  
180
            } catch (PersistenceValidateExceptions e) {
181
                IOException ioex = new IOException();
182
                ioex.initCause(e);
183
                throw ioex;
184
            } catch (PersistenceException e) {
185
                IOException ioex = new IOException();
186
                ioex.initCause(e);
187
                throw ioex;
188
            }
189
        } else {
190

  
191
        }
192
    }
193

  
194
    // gets the selection image (from filename.png it returns filenamesel.png,
195
    // for example)
196
    private File getSelImage(File imageIn) {
197

  
198
        String cadena = deleteExtension(imageIn);
199
        String extension =
200
            imageIn.getPath().substring(imageIn.getPath().lastIndexOf("."),
201
                imageIn.getPath().length());
202

  
203
        String selPath = cadena + "sel" + extension;
204
        File imageOut = new File(selPath);
205

  
206
        return imageOut;
207

  
208
    }
209

  
210
    // Copies File imageIn to imageOut
211
    private void copy(File imageIn, File imageOut) throws IOException {
212

  
213
        FileInputStream from = null;
214
        FileOutputStream to = null;
215

  
216
        from = new FileInputStream(imageIn.getPath());
217
        to = new FileOutputStream(imageOut.getPath());
218

  
219
        try {
220

  
221
            byte[] buffer = new byte[4096];
222
            int bytesRead;
223

  
224
            while ((bytesRead = from.read(buffer)) != -1) {
225
                to.write(buffer, 0, bytesRead); // write
226
            }
227

  
228
        } finally {
229
            if (from != null) {
230
                try {
231
                    from.close();
232
                } catch (IOException e) {
233
                    ;
234
                }
235
            }
236
            if (to != null) {
237
                try {
238
                    to.close();
239
                } catch (IOException e) {
240
                    ;
241
                }
242
            }
243
        }
244

  
245
    }
246

  
247
    private File getOutputFolderPath() {
248
        return panel.getDestinationFolder();
249
    }
250

  
251
    private String deleteExtension(File file) {
252
        String outFileName =
253
            file.getPath().substring(0, file.getPath().lastIndexOf("."));
254
        return outFileName;
255
    }
256

  
257
    private String getText(String msg) {
258
        return msg;
259
        // return Messages.getText(msg);
260
    }
261

  
262
}
0 263

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/resources/locale/text.properties
1
make_plugin_package=Crear paquete instalaci?n de plugin
2
make_plugin_package_description=Crea un paquete de instalaci?n de un plugin instalado
3
install_package=Instalar un nuevo paquete
4
install_package_description=instala un nuevo paquete (plugin, traducciones, tema, etc.) en gvSIG
5
install_package_extension_warning=Herramienta en desarrollo no exenta de fallos. ?Desea continuar?
6
select_an_option=Seleccione una opci?n
0 7

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/resources/locale/text_en.properties
1
make_plugin_package=Create plugin installation package
2
make_plugin_package_description=Create an installation package from an already installed plugin
3
install_package=Install a new package
4
install_package_description=Installs a new package (plugin, translations, theme, etc.) in gvSIG
5
install_package_extension_warning=Tool under development. It may contain errors. Continue anyway?
6
select_an_option=Select an Option
0 7

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/src/main/resources/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<libraries library-dir="lib"/>
4
	<depends plugin-name="org.gvsig.app"/>
5
	<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.symbology.app.importsymbols.ImportSymbolsExtension"
8
			description=""
9
			active="true">
10
			<menu text="tools/Symbols/Import symbols"
11
				  tooltip="Punctual symbol importer from images that exist in a folder"
12
				  action-command="Import_symbols" />			
13
		</extension>
14
	</extensions>
15
</plugin-config>
0 16

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.symbology.app.importsymbols</artifactId>
7
	<packaging>jar</packaging>
8
	<name>Tools: Import marker symbols tool</name>
9
        <description>Importador de simbolos puntuales a partir de las imagenes que existan en una carpeta</description>
10
	<parent>
11
		<groupId>org.gvsig</groupId>
12
		<artifactId>org.gvsig.symbology.app</artifactId>
13
		<version>2.0.0-SNAPSHOT</version>
14
	</parent>
15
	<profiles>
16
    	<profile>
17
    		<id>gvsig-install</id>
18
    		<activation>
19
    			<activeByDefault>true</activeByDefault>
20
    		</activation>
21
    		<properties>
22
				<!--  gvSIG installation folder -->
23
    			<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir>
24
    		</properties>
25
    	</profile>
26
   	</profiles>
27
	<dependencies>
28
		<dependency>
29
			<groupId>org.gvsig</groupId>
30
			<artifactId>org.gvsig.app</artifactId>
31
		        <scope>compile</scope>
32
		</dependency>
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.andami</artifactId>
36
            <scope>compile</scope>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
            <artifactId>org.gvsig.tools.lib</artifactId>
41
            <scope>compile</scope>
42
        </dependency>
43
        <dependency>
44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.tools.swing.api</artifactId>
46
            <scope>compile</scope>
47
        </dependency>
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
50
            <artifactId>org.gvsig.i18n</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
		<dependency>
54
			<groupId>org.gvsig</groupId>
55
			<artifactId>org.gvsig.symbology.lib.api</artifactId>
56
            <scope>compile</scope>
57
		</dependency>		
58

  
59
        <dependency>
60
            <groupId>org.slf4j</groupId>
61
            <artifactId>slf4j-api</artifactId>
62
            <scope>compile</scope>
63
        </dependency>       
64
        <dependency>
65
			<groupId>org.gvsig</groupId>
66
			<artifactId>org.gvsig.fmap.mapcontext</artifactId>
67
            <scope>compile</scope>
68
		</dependency>
69
	</dependencies>
70
    <properties>
71
    	<package.info.dependencies>required: org.gvsig.app -ge 2</package.info.dependencies>
72
    	<package.info.categories>Simbology,Import And Export</package.info.categories>
73
	</properties>
74
</project>
0 75

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.importsymbols/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
		<fileSet>
8
			<directory>src/main/resources/config</directory>
9
			<outputDirectory>${extension.install.dir.name}
10
			</outputDirectory>
11
		</fileSet>
12
		<fileSet>
13
			<directory>src/main/resources/images</directory>
14
			<outputDirectory>${extension.install.dir.name}/images
15
			</outputDirectory>
16
		</fileSet>
17
		<fileSet>
18
			<directory>src/main/resources/about</directory>
19
			<outputDirectory>${extension.install.dir.name}
20
			</outputDirectory>
21
		</fileSet>
22
		<fileSet>
23
			<directory>src/main/resources/locale</directory>
24
			<outputDirectory>${extension.install.dir.name}
25
			</outputDirectory>
26
		</fileSet>	
27
	</fileSets>
28
	<files>
29
		<file>
30
			<source>package.info</source>
31
			<outputDirectory>${extension.install.dir.name}
32
			</outputDirectory>
33
		</file>
34
	</files>
35
	<dependencySets>
36
		<dependencySet>
37
			<outputDirectory>${extension.install.dir.name}/${library-dir}
38
			</outputDirectory>
39
			<includes>
40
				<include>org.gvsig:org.gvsig.symbology.app.importsymbols:jar</include>		
41
			</includes>
42
		</dependencySet>		
43
	</dependencySets>
44
</assembly>
0 45

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Tue May 29 16:42:25 CEST 2012
3
buildNumber=2045
0 4

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.symbology.app.symbolinstaller.SymbolInstallerProviderLibrary
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/resources/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<libraries library-dir="lib"/>
4
	<depends plugin-name="org.gvsig.app"/>
5
	<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.symbology.app.symbolinstaller.execution.SymbolInstallerExtension"
8
			description=""
9
			active="true">
10
			<menu text="tools/Symbols/Create package"
11
				  tooltip="Create a symbols package from symbols that exist in a folder."
12
				  action-command="Create_Package" />
13
				  	
14
		</extension>
15
	</extensions>
16
</plugin-config>
0 17

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/java/org/gvsig/symbology/app/symbolinstaller/SymbolInstallerProviderLibrary.java
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
package org.gvsig.symbology.app.symbolinstaller;
24

  
25
import org.gvsig.installer.lib.api.InstallerLibrary;
26
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
27
import org.gvsig.symbology.app.symbolinstaller.execution.SymbolInstallerExecutionProviderFactory;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30
import org.gvsig.tools.service.spi.ProviderManager;
31

  
32
public class SymbolInstallerProviderLibrary extends AbstractLibrary {
33

  
34
    @Override
35
    public void doRegistration() {
36
        registerAsServiceOf(InstallerLibrary.class);
37
    }
38

  
39
    @Override
40
    protected void doInitialize() throws LibraryException {
41
    }
42

  
43
    @Override
44
    protected void doPostInitialize() throws LibraryException {
45
        ProviderManager providerManager =
46
            InstallerProviderLocator.getProviderManager();
47

  
48
        providerManager
49
            .addProviderFactory(new SymbolInstallerExecutionProviderFactory());
50
    }
51
}
0 52

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/java/org/gvsig/symbology/app/symbolinstaller/execution/SymbolInstallerExtension.java
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
package org.gvsig.symbology.app.symbolinstaller.execution;
24

  
25
import java.util.Locale;
26

  
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.andami.ui.ToolsWindowManager;
29
import org.gvsig.i18n.Messages;
30
import org.gvsig.symbology.app.symbolinstaller.creation.DefaultMakeSymbolPackageWizard;
31
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
32

  
33
public class SymbolInstallerExtension extends Extension {
34

  
35
    public void initialize() {
36
        if (!Messages.hasLocales()) {
37
            Messages.addLocale(Locale.getDefault());
38
        }
39
        Messages.addResourceFamily("org.gvsig.symbology.app.symbolinstaller.text",
40
            SymbolInstallerExtension.class.getClassLoader(),
41
            SymbolInstallerExtension.class.getClass().getName());
42
    }
43

  
44
    @Override
45
    public void postInitialize() {
46
    }
47

  
48
    public boolean isEnabled() {
49
        return true;
50
    }
51

  
52
    public boolean isVisible() {
53
        return true;
54
    }
55

  
56
    public void execute(String actionCommand) {
57
        if (actionCommand.equals("Create_Package")) {
58
            DefaultMakeSymbolPackageWizard wizard =
59
                new DefaultMakeSymbolPackageWizard();
60

  
61
            WindowManager windowManager = new ToolsWindowManager();
62
            windowManager.showWindow(wizard, Messages.getText("_Symbols_wizard"),
63
                WindowManager.MODE.DIALOG);
64
        }
65
    }
66
}
0 67

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/java/org/gvsig/symbology/app/symbolinstaller/execution/SymbolInstallerExecutionProvider.java
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
package org.gvsig.symbology.app.symbolinstaller.execution;
24

  
25
import java.io.File;
26
import java.io.IOException;
27
import java.io.InputStream;
28

  
29
import org.gvsig.andami.PluginsLocator;
30
import org.gvsig.andami.PluginsManager;
31
import org.gvsig.installer.lib.api.PackageInfo;
32
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
33
import org.gvsig.installer.lib.spi.InstallPackageProviderServices;
34
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
35
import org.gvsig.installer.lib.spi.InstallerProviderManager;
36
import org.gvsig.installer.lib.spi.execution.InstallPackageProvider;
37
import org.gvsig.tools.service.spi.AbstractProvider;
38
import org.gvsig.tools.service.spi.ProviderServices;
39

  
40
public class SymbolInstallerExecutionProvider extends AbstractProvider
41
    implements InstallPackageProvider {
42

  
43
    public SymbolInstallerExecutionProvider(ProviderServices providerServices) {
44
        super(providerServices);
45
    }
46

  
47
    public class InstallerSymbolsDirectoryNotFoundException extends
48
        InstallPackageServiceException {
49

  
50
        private static final long serialVersionUID = 4416143986837955880L;
51
        private static final String message = "Symbols directory not found";
52
        private static final String KEY = "symbols_directory_not_found";
53

  
54
        public InstallerSymbolsDirectoryNotFoundException() {
55
            super(message, KEY, serialVersionUID);
56
        }
57
    }
58

  
59
    public void install(File applicationDirectory, InputStream inputStream,
60
        PackageInfo packageInfo) throws InstallPackageServiceException {
61

  
62
        PluginsManager pluginManager = PluginsLocator.getManager();
63

  
64
        File symbolsDirectory =
65
            new File(pluginManager.getApplicationHomeFolder() + File.separator
66
                + "Symbols");
67

  
68
        try {
69
            if (!symbolsDirectory.exists()) {
70
                throw new InstallerSymbolsDirectoryNotFoundException();
71
            }
72
            InstallerProviderManager installerProviderManager =
73
                InstallerProviderLocator.getProviderManager();
74
            InstallPackageProviderServices installerProviderServices =
75
                installerProviderManager.createInstallerProviderServices();
76

  
77
            installerProviderServices.decompress(inputStream, symbolsDirectory);
78

  
79
        } catch (Exception e) {
80
            throw new InstallPackageServiceException(e);
81
        }
82
    }
83

  
84
    public void installLater(File applicationDirectory,
85
        InputStream inputStream, PackageInfo packageInfo)
86
        throws InstallPackageServiceException, IOException {
87
        // TODO Auto-generated method stub
88

  
89
    }
90
}
0 91

  
tags/v2_0_0_Build_2047/extensions/org.gvsig.symbology.app/org.gvsig.symbology.app/org.gvsig.symbology.app.symbolinstaller/src/main/java/org/gvsig/symbology/app/symbolinstaller/execution/SymbolInstallerExecutionProviderFactory.java
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
package org.gvsig.symbology.app.symbolinstaller.execution;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff