Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / AppSymbolPreferences.java @ 43983

History | View | Annotate | Download (8.09 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 {}  {{Task}}
49
*/
50
package org.gvsig.app.gui.preferencespage;
51

    
52
import java.awt.Color;
53
import java.awt.Font;
54
import java.io.File;
55
import org.apache.commons.io.FileUtils;
56
import org.apache.commons.io.FilenameUtils;
57

    
58
import org.gvsig.andami.PluginServices;
59
import org.gvsig.andami.PluginsLocator;
60
import org.gvsig.andami.PluginsManager;
61
import org.gvsig.app.extension.InitializeApplicationExtension;
62
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
63
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
64
import org.gvsig.tools.dynobject.DynObject;
65

    
66
/**
67
 * Default {@link SymbolPreferences} implementation based on object attributes.
68
 * 
69
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
70
 */
71
public class AppSymbolPreferences implements SymbolPreferences {
72
        private static final String SYMBOL_COLOR                   = "defaultSymbolColor";
73
        private static final String SYMBOL_FILL_COLOR              = "defaultSymbolFillColor";
74
        private static final String SYMBOL_FILL_COLOR_ALEATORY     = "defaultSymbolFillColorAleatory";
75
        private static final String SYMBOL_FONT                    = "defaultSymbolFont";
76
        private static final String SYMBOL_LIBRARY_PATH            = "symbolLibraryPath";
77
        
78
        private DynObject           values                         = null;
79
        
80
        private String symbolFileExtension = ".gvssym";
81
        private Color defaultSymbolColor;
82
        private Color defaultSymbolFillColor;
83
        private boolean defaultSymbolFillColorAleatory;
84
        private Font defaultSymbolFont;
85
        private String symbolLibraryPath;
86

    
87
        /**
88
         * The unit that will be used when creating new symbols with Cartographic
89
         * support.
90
         */
91
        private int defaultCartographicSupportMeasureUnit = -1;
92

    
93
        /**
94
         * The reference system that will be used when creating new symbols with
95
         * Cartographic support.
96
         */
97
        private int defaultCartographicSupportReferenceSystem = CartographicSupport.WORLD;
98

    
99
        public AppSymbolPreferences() {
100
                PluginsManager pluginsManager = (PluginsManager) PluginsLocator.getManager();
101
                PluginServices plugin = pluginsManager.getPlugin(InitializeApplicationExtension.class);
102
                values = plugin.getPluginProperties();
103
                initDefaults();
104
        }
105
        
106
        private void initDefaults() {
107
                resetDefaultSymbolColor();
108
                resetDefaultSymbolFillColor();
109
                resetDefaultSymbolFillColorAleatory();
110
                resetSymbolLibraryPath();
111
                resetDefaultSymbolFont();
112
                
113
                if(getDefaultSymbolFont() == null)
114
                        setDefaultSymbolFont(defaultSymbolFont);
115
                if(getDefaultSymbolColor() == null)
116
                        setDefaultSymbolColor(defaultSymbolColor);
117
                if(getDefaultSymbolFillColor() == null)
118
                        setDefaultSymbolFillColor(defaultSymbolFillColor);
119
                if(getSymbolLibraryPath() == null)
120
                        setSymbolLibraryPath(symbolLibraryPath);
121
                setSymbolFileExtension(symbolFileExtension);
122
                setDefaultCartographicSupportMeasureUnit(defaultCartographicSupportMeasureUnit);
123
                setDefaultCartographicSupportReferenceSystem(defaultCartographicSupportReferenceSystem);
124
        }
125

    
126
        public String getSymbolFileExtension() {
127
                return symbolFileExtension;
128
        }
129

    
130
        public void setSymbolFileExtension(String symbolFileExtension) {
131
                this.symbolFileExtension = symbolFileExtension;
132
        }
133
        
134
        public String getSymbolLibraryPath() {
135
                String spath = (String)values.getDynValue(SYMBOL_LIBRARY_PATH);
136
                if( spath==null ) {
137
                    return this.symbolLibraryPath;
138
                }
139
                File path = new File(spath);
140
                if( !path.exists() ) {
141
                    return this.symbolLibraryPath;
142
                }
143
                return spath;
144
        }
145

    
146
        public void setSymbolLibraryPath(String symbolLibraryPath) {
147
                values.setDynValue(SYMBOL_LIBRARY_PATH, symbolLibraryPath);
148
                PluginServices.getPluginServices(this).savePluginProperties();
149
        }
150

    
151
        public Color getDefaultSymbolColor() {
152
                return (Color)values.getDynValue(SYMBOL_COLOR);
153
        }
154

    
155
        public void setDefaultSymbolColor(Color symbolColor) {
156
                values.setDynValue(SYMBOL_COLOR, symbolColor);
157
                PluginServices.getPluginServices(this).savePluginProperties();
158
        }
159

    
160
        public Color getDefaultSymbolFillColor() {
161
                return (Color)values.getDynValue(SYMBOL_FILL_COLOR);
162
        }
163

    
164
        public void setDefaultSymbolFillColor(Color symbolFillColor) {
165
                values.setDynValue(SYMBOL_FILL_COLOR, symbolFillColor);
166
                PluginServices.getPluginServices(this).savePluginProperties();
167
        }
168

    
169
        public boolean isDefaultSymbolFillColorAleatory() {
170
                if(values.getDynValue(SYMBOL_FILL_COLOR_ALEATORY) == null) {
171
                        setDefaultSymbolFillColorAleatory(defaultSymbolFillColorAleatory);
172
                }
173
                return (Boolean)values.getDynValue(SYMBOL_FILL_COLOR_ALEATORY);
174
        }
175

    
176
        public void setDefaultSymbolFillColorAleatory(boolean defaultSymbolFillColorAleatory) {
177
                values.setDynValue(SYMBOL_FILL_COLOR_ALEATORY, defaultSymbolFillColorAleatory);
178
                PluginServices.getPluginServices(this).savePluginProperties();
179
        }
180

    
181
        public Font getDefaultSymbolFont() {
182
                return (Font)values.getDynValue(SYMBOL_FONT);
183
        }
184

    
185
        public void setDefaultSymbolFont(Font defaultSymbolFont) {
186
                values.setDynValue(SYMBOL_FONT, defaultSymbolFont);
187
                PluginServices.getPluginServices(this).savePluginProperties();
188
        }
189

    
190

    
191
        public int getDefaultCartographicSupportMeasureUnit() {
192
                return defaultCartographicSupportMeasureUnit;
193
        }
194

    
195
        public void setDefaultCartographicSupportMeasureUnit(
196
                        int defaultCartographicSupportMeasureUnit) {
197
                this.defaultCartographicSupportMeasureUnit =
198
                                defaultCartographicSupportMeasureUnit;
199
        }
200

    
201
        public int getDefaultCartographicSupportReferenceSystem() {
202
                return defaultCartographicSupportReferenceSystem;
203
        }
204

    
205
        public void setDefaultCartographicSupportReferenceSystem(
206
                        int defaultCartographicSupportReferenceSystem) {
207
                this.defaultCartographicSupportReferenceSystem =
208
                                defaultCartographicSupportReferenceSystem;
209
        }
210

    
211
        public void resetDefaultSymbolColor() {
212
                defaultSymbolColor = Color.DARK_GRAY;
213
        }
214

    
215
        public void resetDefaultSymbolFillColor() {
216
                defaultSymbolFillColor = new Color(60, 235, 235);
217
        }
218

    
219
        public void resetDefaultSymbolFillColorAleatory() {
220
                defaultSymbolFillColorAleatory = true;
221
        }
222

    
223
        public void resetDefaultSymbolFont() {
224
                defaultSymbolFont = new Font("SansSerif", Font.PLAIN, 14);
225
        }
226

    
227
        public void resetSymbolLibraryPath() {
228
                PluginsManager pluginsManager = (PluginsManager) PluginsLocator.getManager();
229
                PluginServices plugin = pluginsManager.getPlugin(InitializeApplicationExtension.class);
230
                
231
                symbolLibraryPath = new File(plugin.getPluginHomeFolder(),"Symbols").getAbsolutePath();
232
                
233
        }
234
}