Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / preferencespage / AppSymbolPreferences.java @ 38551

History | View | Annotate | Download (6.42 KB)

1 38442 nbrodin
/* 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
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.app.gui.preferencespage;
28
29
import java.awt.Color;
30
import java.awt.Font;
31 38451 nbrodin
import java.io.File;
32 38442 nbrodin
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.fmap.mapcontext.MapContextLocator;
35
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
37
import org.gvsig.tools.dynobject.DynObject;
38
39
/**
40
 * Default {@link SymbolPreferences} implementation based on object attributes.
41
 *
42
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
43
 */
44
public class AppSymbolPreferences implements SymbolPreferences {
45
        private static final String SYMBOL_COLOR                   = "defaultSymbolColor";
46
        private static final String SYMBOL_FILL_COLOR              = "defaultSymbolFillColor";
47
        private static final String SYMBOL_FILL_COLOR_ALEATORY     = "defaultSymbolFillColorAleatory";
48
        private static final String SYMBOL_FONT                    = "defaultSymbolFont";
49
        private static final String SYMBOL_LIBRARY_PATH            = "symbolLibraryPath";
50
51
        private DynObject           values                         = null;
52
53 38451 nbrodin
        private String symbolFileExtension = ".gvssym";
54
        private Color defaultSymbolColor;
55
        private Color defaultSymbolFillColor;
56
        private boolean defaultSymbolFillColorAleatory;
57
        private Font defaultSymbolFont;
58
        private String symbolLibraryPath;
59 38442 nbrodin
60
        /**
61
         * The unit that will be used when creating new symbols with Cartographic
62
         * support.
63
         */
64
        private int defaultCartographicSupportMeasureUnit = -1;
65
66
        /**
67
         * The reference system that will be used when creating new symbols with
68
         * Cartographic support.
69
         */
70
        private int defaultCartographicSupportReferenceSystem = CartographicSupport.WORLD;
71
72
        public AppSymbolPreferences() {
73
                values = PluginServices.getPluginServices(this).getPluginProperties();
74
                initDefaults();
75
        }
76
77
        private void initDefaults() {
78 38451 nbrodin
                resetDefaultSymbolColor();
79
                resetDefaultSymbolFillColor();
80
                resetDefaultSymbolFillColorAleatory();
81
                resetSymbolLibraryPath();
82
                resetDefaultSymbolFont();
83
84 38442 nbrodin
                if(getDefaultSymbolFont() == null)
85 38451 nbrodin
                        setDefaultSymbolFont(defaultSymbolFont);
86 38442 nbrodin
                if(getDefaultSymbolColor() == null)
87 38451 nbrodin
                        setDefaultSymbolColor(defaultSymbolColor);
88 38442 nbrodin
                if(getDefaultSymbolFillColor() == null)
89 38451 nbrodin
                        setDefaultSymbolFillColor(defaultSymbolFillColor);
90 38442 nbrodin
                if(getSymbolLibraryPath() == null)
91 38451 nbrodin
                        setSymbolLibraryPath(symbolLibraryPath);
92
                setSymbolFileExtension(symbolFileExtension);
93
                setDefaultCartographicSupportMeasureUnit(defaultCartographicSupportMeasureUnit);
94
                setDefaultCartographicSupportReferenceSystem(defaultCartographicSupportReferenceSystem);
95 38442 nbrodin
        }
96
97
        public String getSymbolFileExtension() {
98
                return symbolFileExtension;
99
        }
100
101
        public void setSymbolFileExtension(String symbolFileExtension) {
102
                this.symbolFileExtension = symbolFileExtension;
103
        }
104
105
        public String getSymbolLibraryPath() {
106
                return (String)values.getDynValue(SYMBOL_LIBRARY_PATH);
107
        }
108
109
        public void setSymbolLibraryPath(String symbolLibraryPath) {
110
                values.setDynValue(SYMBOL_LIBRARY_PATH, symbolLibraryPath);
111
                PluginServices.getPluginServices(this).savePluginProperties();
112
        }
113
114
        public Color getDefaultSymbolColor() {
115
                return (Color)values.getDynValue(SYMBOL_COLOR);
116
        }
117
118
        public void setDefaultSymbolColor(Color symbolColor) {
119
                values.setDynValue(SYMBOL_COLOR, symbolColor);
120
                PluginServices.getPluginServices(this).savePluginProperties();
121
        }
122
123
        public Color getDefaultSymbolFillColor() {
124
                return (Color)values.getDynValue(SYMBOL_FILL_COLOR);
125
        }
126
127
        public void setDefaultSymbolFillColor(Color symbolFillColor) {
128
                values.setDynValue(SYMBOL_FILL_COLOR, symbolFillColor);
129
                PluginServices.getPluginServices(this).savePluginProperties();
130
        }
131
132
        public boolean isDefaultSymbolFillColorAleatory() {
133
                if(values.getDynValue(SYMBOL_FILL_COLOR_ALEATORY) == null) {
134 38451 nbrodin
                        setDefaultSymbolFillColorAleatory(defaultSymbolFillColorAleatory);
135 38442 nbrodin
                }
136
                return (Boolean)values.getDynValue(SYMBOL_FILL_COLOR_ALEATORY);
137
        }
138
139
        public void setDefaultSymbolFillColorAleatory(boolean defaultSymbolFillColorAleatory) {
140
                values.setDynValue(SYMBOL_FILL_COLOR_ALEATORY, defaultSymbolFillColorAleatory);
141
                PluginServices.getPluginServices(this).savePluginProperties();
142
        }
143
144
        public Font getDefaultSymbolFont() {
145
                return (Font)values.getDynValue(SYMBOL_FONT);
146
        }
147
148
        public void setDefaultSymbolFont(Font defaultSymbolFont) {
149
                values.setDynValue(SYMBOL_FONT, defaultSymbolFont);
150
                PluginServices.getPluginServices(this).savePluginProperties();
151
        }
152
153
154
        public int getDefaultCartographicSupportMeasureUnit() {
155
                return defaultCartographicSupportMeasureUnit;
156
        }
157
158
        public void setDefaultCartographicSupportMeasureUnit(
159
                        int defaultCartographicSupportMeasureUnit) {
160
                this.defaultCartographicSupportMeasureUnit =
161
                                defaultCartographicSupportMeasureUnit;
162
        }
163
164
        public int getDefaultCartographicSupportReferenceSystem() {
165
                return defaultCartographicSupportReferenceSystem;
166
        }
167
168
        public void setDefaultCartographicSupportReferenceSystem(
169
                        int defaultCartographicSupportReferenceSystem) {
170
                this.defaultCartographicSupportReferenceSystem =
171
                                defaultCartographicSupportReferenceSystem;
172
        }
173
174
        public void resetDefaultSymbolColor() {
175 38451 nbrodin
                defaultSymbolColor = Color.GRAY;
176 38442 nbrodin
        }
177
178
        public void resetDefaultSymbolFillColor() {
179 38451 nbrodin
                defaultSymbolFillColor = new Color(60, 235, 235);
180 38442 nbrodin
        }
181
182
        public void resetDefaultSymbolFillColorAleatory() {
183 38551 jldominguez
                defaultSymbolFillColorAleatory = true;
184 38442 nbrodin
        }
185
186
        public void resetDefaultSymbolFont() {
187 38451 nbrodin
                defaultSymbolFont = new Font("Serif", Font.PLAIN, 8);
188 38442 nbrodin
        }
189
190
        public void resetSymbolLibraryPath() {
191 38451 nbrodin
                symbolLibraryPath =
192
                        System.getProperty("user.home") + File.separator + "gvSIG"
193
                                        + File.separator + "Symbols";
194 38442 nbrodin
        }
195
}