Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.symbology.app / org.gvsig.symbology.app.importsymbols / src / main / java / org / gvsig / symbology / app / importsymbols / panel / SelectSymbolsFolderImportPanel.java @ 37414

History | View | Annotate | Download (4.25 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
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
}