Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extNormalization / src / org / gvsig / normalization / preferences / NormPreferences.java @ 26207

History | View | Annotate | Download (4.04 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
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
44
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
45
 */
46

    
47
public class NormPreferences extends AbstractPreferencePage {
48

    
49
        /**
50
         * 
51
         */
52
        private static final long serialVersionUID = 1L;
53

    
54
        private String normFolder = System.getProperty("user.home")
55
                        + File.separator + "gvSIG" + File.separator + "normalization"
56
                        + File.separator;
57

    
58
        private ImageIcon icon;
59

    
60
        private String tag = "Normalization_pattern_folder";
61

    
62
        private static final Logger log = PluginServices.getLogger();
63

    
64
        static String id = NormPreferences.class.getName();
65

    
66
        private PreferencesNormPanel panel;
67

    
68
        private String pathFolder;
69

    
70
        /**
71
         * Builder
72
         */
73
        public NormPreferences() {
74
                super();
75

    
76
                icon = new ImageIcon(this.getClass().getClassLoader().getResource(
77
                                "images"+File.separator+"preferences.png"));
78

    
79
                /* PERSISTENCE */
80
                PluginServices ps = PluginServices.getPluginServices(this);
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
        @Override
104
        public void storeValues() throws StoreException {
105

    
106
                String txt = panel.getFolderPattern();
107

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

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

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

    
118
        }
119

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

    
130
        @Override
131
        public void setChangesApplied() {
132
                setChanged(false);
133

    
134
        }
135

    
136
        public String getID() {
137
                return id;
138
        }
139

    
140
        public ImageIcon getIcon() {
141
                return icon;
142
        }
143

    
144
        public JPanel getPanel() {
145
                return this;
146
        }
147

    
148
        public String getTitle() {
149
                return PluginServices.getText(this, "pref_normalization");
150
        }
151

    
152
        public void initializeDefaults() {
153

    
154
        }
155

    
156
        public void initializeValues() {
157

    
158
        }
159

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

    
164
}