svn-gvsig-desktop / branches / v10 / extensions / extNormalization / src / org / gvsig / normalization / preferences / NormPreferences.java @ 28183
History | View | Annotate | Download (4.15 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 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = 1L; |
55 |
|
56 |
private String normFolder = System.getProperty("user.home") |
57 |
+ File.separator + "gvSIG" + File.separator + "normalization" |
58 |
+ File.separator;
|
59 |
|
60 |
private ImageIcon icon; |
61 |
|
62 |
private String tag = "Normalization_pattern_folder"; |
63 |
|
64 |
private static final Logger log = PluginServices.getLogger(); |
65 |
|
66 |
static String id = NormPreferences.class.getName(); |
67 |
|
68 |
private PreferencesNormPanel panel;
|
69 |
|
70 |
private String pathFolder; |
71 |
|
72 |
/**
|
73 |
* Builder
|
74 |
*/
|
75 |
public NormPreferences() {
|
76 |
super();
|
77 |
PluginServices ps = PluginServices.getPluginServices(this);
|
78 |
|
79 |
String bDir = ps.getClassLoader().getBaseDir();
|
80 |
|
81 |
String path = bDir + File.separator + "images" + File.separator |
82 |
+ "preferences.png";
|
83 |
|
84 |
icon = new ImageIcon(path); |
85 |
|
86 |
/* PERSISTENCE */
|
87 |
XMLEntity xml = ps.getPersistentXML(); |
88 |
// TAG exists in the persistence
|
89 |
if (xml.contains(tag)) {
|
90 |
pathFolder = String.valueOf(xml.getStringProperty(tag));
|
91 |
log.debug("Getting the patterns folder from the persistence");
|
92 |
} |
93 |
// TAG don't exit in the persistence
|
94 |
else {
|
95 |
log.debug("There isn't a folder. Doing one new");
|
96 |
createNormFolder(); |
97 |
xml.putProperty(tag, normFolder); |
98 |
ps.setPersistentXML(xml); |
99 |
pathFolder = normFolder; |
100 |
log.debug("Putting the default folder path");
|
101 |
} |
102 |
|
103 |
/* Create Panel and add to gvSIG */
|
104 |
panel = new PreferencesNormPanel(pathFolder);
|
105 |
this.addComponent(panel);
|
106 |
|
107 |
} |
108 |
|
109 |
public void storeValues() throws StoreException { |
110 |
|
111 |
String txt = panel.getFolderPattern();
|
112 |
|
113 |
/* Overwrite the text in the persistence file */
|
114 |
if (txt.compareToIgnoreCase("") != 0) { |
115 |
|
116 |
PluginServices ps = PluginServices.getPluginServices(this);
|
117 |
XMLEntity xml = ps.getPersistentXML(); |
118 |
|
119 |
xml.putProperty(tag, txt); |
120 |
ps.setPersistentXML(xml); |
121 |
} |
122 |
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* This method creates a folder where you put the normalization pattern
|
127 |
*/
|
128 |
private void createNormFolder() { |
129 |
File normFol = new File(normFolder); |
130 |
if (!normFol.exists()) {
|
131 |
normFol.mkdir(); |
132 |
} |
133 |
} |
134 |
|
135 |
public void setChangesApplied() { |
136 |
setChanged(false);
|
137 |
|
138 |
} |
139 |
|
140 |
public String getID() { |
141 |
return id;
|
142 |
} |
143 |
|
144 |
public ImageIcon getIcon() { |
145 |
return icon;
|
146 |
} |
147 |
|
148 |
public JPanel getPanel() { |
149 |
return this; |
150 |
} |
151 |
|
152 |
public String getTitle() { |
153 |
String title = PluginServices.getText(this, "pref_normalization"); |
154 |
return title;
|
155 |
} |
156 |
|
157 |
public void initializeDefaults() { |
158 |
|
159 |
} |
160 |
|
161 |
public void initializeValues() { |
162 |
|
163 |
} |
164 |
|
165 |
public boolean isValueChanged() { |
166 |
return super.hasChanged(); |
167 |
} |
168 |
|
169 |
} |