Statistics
| Revision:

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

History | View | Annotate | Download (4.31 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
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36
import com.iver.andami.PluginServices;
37
import com.iver.andami.preferences.AbstractPreferencePage;
38
import com.iver.andami.preferences.StoreException;
39
import com.iver.utiles.XMLEntity;
40

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

    
48
public class NormPreferences extends AbstractPreferencePage {
49

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

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

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

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

    
74
                icon = new ImageIcon(path);
75

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

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

    
97
        }
98

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

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

    
123
        /**
124
         * 
125
         */
126
        public void setChangesApplied() {
127
                setChanged(false);
128

    
129
        }
130

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

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

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

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

    
160
        /**
161
         * 
162
         */
163
        public void initializeDefaults() {
164

    
165
        }
166

    
167
        /**
168
         * 
169
         */
170
        public void initializeValues() {
171

    
172
        }
173

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

    
181
}