Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.normalization.extension / src / org / gvsig / normalization / preferences / NormPreferences.java @ 32523

History | View | Annotate | Download (4.32 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.gvsig.andami.PluginServices;
36
import org.gvsig.andami.preferences.AbstractPreferencePage;
37
import org.gvsig.andami.preferences.StoreException;
38
import org.gvsig.utils.XMLEntity;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

    
42

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

    
50
public class NormPreferences extends AbstractPreferencePage {
51

    
52
        private static final long serialVersionUID = 1L;
53
        private String normFolder = System.getProperty("user.home")
54
                        + File.separator + "gvSIG" + File.separator + "normalization"
55
                        + File.separator;
56

    
57
        private ImageIcon icon;
58
        private String tag = "Normalization_pattern_folder";
59
        private static final Logger log = LoggerFactory
60
                        .getLogger(NormPreferences.class);
61
        static String id = NormPreferences.class.getName();
62
        private PreferencesNormPanel panel;
63
        private String pathFolder;
64

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

    
72
                String bDir = ps.getClassLoader().getBaseDir();
73
                String path = bDir + File.separator + "images" + File.separator
74
                                + "preferences.png";
75

    
76
                icon = new ImageIcon(path);
77

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

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

    
99
        }
100

    
101
        /**
102
         * 
103
         */
104
        public void storeValues() throws StoreException {
105
                String txt = panel.getFolderPattern();
106
                /* Overwrite the text in the persistence file */
107
                if (txt.compareToIgnoreCase("") != 0) {
108
                        PluginServices ps = PluginServices.getPluginServices(this);
109
                        XMLEntity xml = ps.getPersistentXML();
110
                        xml.putProperty(tag, txt);
111
                        ps.setPersistentXML(xml);
112
                }
113
        }
114

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

    
125
        /**
126
         * 
127
         */
128
        public void setChangesApplied() {
129
                setChanged(false);
130

    
131
        }
132

    
133
        /**
134
         * 
135
         */
136
        public String getID() {
137
                return id;
138
        }
139

    
140
        /**
141
         * 
142
         */
143
        public ImageIcon getIcon() {
144
                return icon;
145
        }
146

    
147
        /**
148
         * 
149
         */
150
        public JPanel getPanel() {
151
                return this;
152
        }
153

    
154
        /**
155
         * 
156
         */
157
        public String getTitle() {
158
                String title = PluginServices.getText(this, "pref_normalization");
159
                return title;
160
        }
161

    
162
        /**
163
         * 
164
         */
165
        public void initializeDefaults() {
166

    
167
        }
168

    
169
        /**
170
         * 
171
         */
172
        public void initializeValues() {
173

    
174
        }
175

    
176
        /**
177
         * 
178
         */
179
        public boolean isValueChanged() {
180
                return super.hasChanged();
181
        }
182

    
183
}