Statistics
| Revision:

root / trunk / extensions / extNormalization / src / org / gvsig / normalization / preferences / NormPreferences.java @ 33213

History | View | Annotate | Download (4.09 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
 * 2008 Prodevelop S.L. main developer
26
 */
27

    
28
package org.gvsig.normalization.preferences;
29

    
30
import java.io.File;
31

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

    
35
import org.apache.log4j.Logger;
36

    
37
import com.iver.andami.PluginServices;
38
import com.iver.andami.preferences.AbstractPreferencePage;
39
import com.iver.andami.preferences.StoreException;
40
import com.iver.utiles.XMLEntity;
41

    
42
/**
43
 * Preferences of the normalization extension
44
 * 
45
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
46
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
47
 */
48

    
49
public class NormPreferences extends AbstractPreferencePage {
50
        private static final long serialVersionUID = 1L;
51
        
52
        private String normFolder = com.iver.andami.Launcher.getAppHomeDir() + "normalization" + File.separator;
53

    
54
        private ImageIcon icon;
55

    
56
        private String tag = "Normalization_pattern_folder";
57

    
58
        private static final Logger log = PluginServices.getLogger();
59

    
60
        static String id = NormPreferences.class.getName();
61

    
62
        private PreferencesNormPanel panel;
63

    
64
        private String pathFolder;
65

    
66
        /**
67
         * Builder
68
         */
69
        public NormPreferences() {
70
                super();
71
                PluginServices ps = PluginServices.getPluginServices(this);
72

    
73
                String bDir = ps.getClassLoader().getBaseDir();
74

    
75
                String path = bDir + File.separator + "images" + File.separator
76
                                + "preferences.png";
77

    
78
                icon = new ImageIcon(path);
79

    
80
                /* PERSISTENCE */
81
                XMLEntity xml = ps.getPersistentXML();
82
                // TAG exists in the persistence
83
                if (xml.contains(tag)) {
84
                        pathFolder = String.valueOf(xml.getStringProperty(tag));
85
                        log.debug("Getting the patterns folder from the persistence");
86
                }
87
                // TAG don't exit in the persistence
88
                else {
89
                        log.debug("There isn't a folder. Doing one new");
90
                        createNormFolder();
91
                        xml.putProperty(tag, normFolder);
92
                        ps.setPersistentXML(xml);
93
                        pathFolder = normFolder;
94
                        log.debug("Putting the default folder path");
95
                }
96

    
97
                /* Create Panel and add to gvSIG */
98
                panel = new PreferencesNormPanel(pathFolder);
99
                this.addComponent(panel);
100

    
101
        }
102

    
103
        public void storeValues() throws StoreException {
104

    
105
                String txt = panel.getFolderPattern();
106

    
107
                /* Overwrite the text in the persistence file */
108
                if (txt.compareToIgnoreCase("") != 0) {
109

    
110
                        PluginServices ps = PluginServices.getPluginServices(this);
111
                        XMLEntity xml = ps.getPersistentXML();
112

    
113
                        xml.putProperty(tag, txt);
114
                        ps.setPersistentXML(xml);
115
                }
116

    
117
        }
118

    
119
        /**
120
         * This method creates a folder where you put the normalization pattern
121
         */
122
        private void createNormFolder() {
123
                File normFol = new File(normFolder);
124
                if (!normFol.exists()) {
125
                        normFol.mkdir();
126
                }
127
        }
128

    
129
        public void setChangesApplied() {
130
                setChanged(false);
131

    
132
        }
133

    
134
        public String getID() {
135
                return id;
136
        }
137

    
138
        public ImageIcon getIcon() {
139
                return icon;
140
        }
141

    
142
        public JPanel getPanel() {
143
                return this;
144
        }
145

    
146
        public String getTitle() {
147
                String title = PluginServices.getText(this, "pref_normalization");
148
                return title;
149
        }
150

    
151
        public void initializeDefaults() {
152

    
153
        }
154

    
155
        public void initializeValues() {
156

    
157
        }
158

    
159
        public boolean isValueChanged() {
160
                return super.hasChanged();
161
        }
162

    
163
}