Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / DefaultCoordinateReferenceSystemSwingManager.java @ 866

History | View | Annotate | Download (8.82 KB)

1 7 cordinyana
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 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 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
 * 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
package org.gvsig.proj.swing.impl;
25
26 866 cmartinez
import java.util.LinkedHashSet;
27
import java.util.List;
28
import java.util.Set;
29
import java.util.concurrent.CopyOnWriteArrayList;
30 852 cmartinez
31
import org.gvsig.proj.CoordinateReferenceSystem;
32 24 cordinyana
import org.gvsig.proj.CoordinateReferenceSystemLocator;
33
import org.gvsig.proj.CoordinateReferenceSystemManager;
34 852 cmartinez
import org.gvsig.proj.CoordinateTransformation;
35 814 cmartinez
import org.gvsig.proj.catalog.CRSCatalogLocator;
36
import org.gvsig.proj.catalog.CRSCatalogManager;
37 866 cmartinez
import org.gvsig.proj.catalog.CRSDefinition;
38
import org.gvsig.proj.catalog.TransformationDefinition;
39 24 cordinyana
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent;
40
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingManager;
41 814 cmartinez
import org.gvsig.proj.swing.CoordinateTransformationSelectorComponent;
42 852 cmartinez
import org.gvsig.proj.swing.RecentHistory;
43
import org.gvsig.proj.swing.impl.history.History;
44 866 cmartinez
import org.gvsig.tools.dynobject.DynObject;
45 852 cmartinez
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47 7 cordinyana
48
/**
49 24 cordinyana
 * Default implementation of the {@link CoordinateReferenceSystemSwingManager}.
50 7 cordinyana
 *
51
 * @author gvSIG Team
52
 * @version $Id$
53
 */
54 24 cordinyana
public class DefaultCoordinateReferenceSystemSwingManager implements
55
    CoordinateReferenceSystemSwingManager {
56 852 cmartinez
        private static Logger logger = LoggerFactory.getLogger(DefaultCoordinateReferenceSystemSwingManager.class);
57 866 cmartinez
    private RecentHistory<CRSDefinition> crsHistory;
58
    private RecentHistory<TransformationDefinition> transformationHistory;
59 852 cmartinez
    private RecentHistory<String> crsTextFilterHistory;
60
    private RecentHistory<String> transformationTextFilterHistory;
61 866 cmartinez
    private LinkedHashSet<CRSDefinition> crsFavorites;
62
    private LinkedHashSet<TransformationDefinition> transformationFavorites;
63
    private DynObject preferences = null;
64
65
    private static final String CRS_HISTORY_FIELD = "crsHistory";
66
    private static final String CRS_HISTORY_SIZE_FIELD = "crsHistorySize";
67
    private static final String TRANSFORMATION_HISTORY_FIELD = "transformationHistory";
68
    private static final String TRANSFORMATION_HISTORY_SIZE_FIELD = "transformationHistorySize";
69
    private static final String CRS_TEXT_FILTER_HISTORY_FIELD = "crsTextFilterHistory";
70
    private static final String CRS_TEXT_FILTER_HISTORY_SIZE_FIELD = "crsTextFilterHistorySize";
71
    private static final String TRANSFORMATION_TEXT_FILTER_HISTORY_FIELD = "transformationTextFilterHistory";
72
    private static final String TRANSFORMATION_TEXT_FILTER_HISTORY_SIZE_FIELD = "transformationTextFilterHistorySize";
73
    private static final String CRS_FAVORITES_FIELD = "crsFavorites";
74
    private static final String TRANSFORMATION_FAVORITES_FIELD = "transformationFavorites";
75 7 cordinyana
76 24 cordinyana
    public DefaultCoordinateReferenceSystemSwingManager() {
77 866 cmartinez
        crsHistory = new History<CRSDefinition>();
78
        transformationHistory = new History<TransformationDefinition>();
79 852 cmartinez
        crsTextFilterHistory = new History<String>();
80
        transformationTextFilterHistory = new History<String>();
81 866 cmartinez
        crsFavorites = new LinkedHashSet<CRSDefinition>();
82
        transformationFavorites = new LinkedHashSet<TransformationDefinition>();
83 7 cordinyana
    }
84
85 852 cmartinez
    @Override
86
    public CoordinateReferenceSystemManager getCRSManager() {
87
            return CoordinateReferenceSystemLocator.getManager();
88 7 cordinyana
    }
89
90 24 cordinyana
    public CoordinateReferenceSystemSelectorComponent createCoordinateReferenceSystemSelectionComponent() {
91 852 cmartinez
            /**
92
             * Ensures the icons have been registered. We can't do it at manager initialization because the
93
             * IconThemeManager may not be initialized at that point
94
             */
95 859 cmartinez
        return new CrsSelectorController(this);
96 24 cordinyana
    }
97 814 cmartinez
98
        @Override
99
        public CoordinateTransformationSelectorComponent createCoordinateTransformSelectionComponent() {
100 852 cmartinez
            /**
101
             * Ensures the icons have been registered. We can't do it at manager initialization because the
102
             * IconThemeManager may not be initialized at that point
103
             */
104 866 cmartinez
                return new CtSelectorController(this);
105 814 cmartinez
        }
106
107
        @Override
108
        public CRSCatalogManager getCatalogManager() {
109
                return CRSCatalogLocator.getManager();
110
        }
111 852 cmartinez
112
        @Override
113 866 cmartinez
        public RecentHistory<CRSDefinition> getCoordinateReferenceSystemHistory() {
114 852 cmartinez
                return crsHistory;
115
        }
116
117
        @Override
118 866 cmartinez
        public RecentHistory<TransformationDefinition> getTransformationHistory() {
119 852 cmartinez
                return transformationHistory;
120
        }
121
122
        @Override
123
        public RecentHistory<String> getCoordinateReferenceSystemTextFilterHistory() {
124
                return crsTextFilterHistory;
125
        }
126
127
        @Override
128
        public RecentHistory<String> getTransformationTextFilterHistory() {
129
                return transformationTextFilterHistory;
130
        }
131 866 cmartinez
132
        @Override
133
        public Set<CRSDefinition> getCoordinateReferenceSystemFavorites() {
134
                return crsFavorites;
135
        }
136
137
        @Override
138
        public Set<TransformationDefinition> getTransformationFavorites() {
139
                return transformationFavorites;
140
        }
141
142
        @Override
143
        public DynObject getPreferences() {
144
                if (preferences != null) {
145
                        preferences.setDynValue(CRS_HISTORY_FIELD, crsHistory.toList());
146
                        preferences.setDynValue(CRS_HISTORY_SIZE_FIELD, (Integer) crsHistory.getMaxSize());
147
                        preferences.setDynValue(TRANSFORMATION_HISTORY_FIELD, transformationHistory.toList());
148
                        preferences.setDynValue(TRANSFORMATION_HISTORY_SIZE_FIELD, (Integer) transformationHistory.getMaxSize());
149
                        preferences.setDynValue(CRS_TEXT_FILTER_HISTORY_FIELD, crsTextFilterHistory.toList());
150
                        preferences.setDynValue(CRS_TEXT_FILTER_HISTORY_SIZE_FIELD, (Integer) crsTextFilterHistory.getMaxSize());
151
                        preferences.setDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_FIELD, transformationTextFilterHistory.toList());
152
                        preferences.setDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_SIZE_FIELD, (Integer) transformationTextFilterHistory.getMaxSize());
153
                        preferences.setDynValue(CRS_FAVORITES_FIELD, crsFavorites);
154
                        preferences.setDynValue(TRANSFORMATION_FAVORITES_FIELD, transformationFavorites);
155
                }
156
                return preferences;
157
        }
158
159
        @Override
160
        public void setPreferences(DynObject preferences) {
161
                this.preferences = preferences;
162
                Integer size;
163
                if (preferences.hasDynValue(CRS_HISTORY_FIELD)) {
164
                        List history = (List) preferences.getDynValue(CRS_HISTORY_FIELD);
165
                        if (preferences.hasDynValue(CRS_HISTORY_SIZE_FIELD)) {
166
                                size = (Integer) preferences.getDynValue(CRS_HISTORY_SIZE_FIELD);
167
                        }
168
                        else {
169
                                size = History.DEFAULT_MAX_SIZE;
170
                        }
171
                        crsHistory = new History<CRSDefinition>(history, size);
172
                }
173
174
                if (preferences.hasDynValue(TRANSFORMATION_HISTORY_FIELD)) {
175
                        List history = (List) preferences.getDynValue(TRANSFORMATION_HISTORY_FIELD);
176
                        if (preferences.hasDynValue(TRANSFORMATION_HISTORY_SIZE_FIELD)) {
177
                                size = (Integer) preferences.getDynValue(TRANSFORMATION_HISTORY_SIZE_FIELD);
178
                        }
179
                        else {
180
                                size = History.DEFAULT_MAX_SIZE;
181
                        }
182
                        transformationHistory = new History<TransformationDefinition>(history, size);
183
                }
184
185
186
                if (preferences.hasDynValue(CRS_TEXT_FILTER_HISTORY_FIELD)) {
187
                        List history = (List) preferences.getDynValue(CRS_TEXT_FILTER_HISTORY_FIELD);
188
                        if (preferences.hasDynValue(CRS_TEXT_FILTER_HISTORY_SIZE_FIELD)) {
189
                                size = (Integer) preferences.getDynValue(CRS_TEXT_FILTER_HISTORY_SIZE_FIELD);
190
                        }
191
                        else {
192
                                size = History.DEFAULT_MAX_SIZE;
193
                        }
194
                        crsTextFilterHistory = new History<String>(history, size);
195
                }
196
197
                if (preferences.hasDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_FIELD)) {
198
                        List history = (List) preferences.getDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_FIELD);
199
                        if (preferences.hasDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_SIZE_FIELD)) {
200
                                size = (Integer) preferences.getDynValue(TRANSFORMATION_TEXT_FILTER_HISTORY_SIZE_FIELD);
201
                        }
202
                        else {
203
                                size = History.DEFAULT_MAX_SIZE;
204
                        }
205
                        transformationTextFilterHistory = new History<String>(history, size);
206
                }
207
208
                if (preferences.hasDynValue(CRS_FAVORITES_FIELD)) {
209
                        List favorites = (List) preferences.getDynValue(CRS_FAVORITES_FIELD);
210
                        crsFavorites =  new LinkedHashSet<CRSDefinition>(favorites);
211
                }
212
213
                if (preferences.hasDynValue(TRANSFORMATION_FAVORITES_FIELD)) {
214
                        List favorites = (List) preferences.getDynValue(TRANSFORMATION_FAVORITES_FIELD);
215
                        transformationFavorites =  new LinkedHashSet<TransformationDefinition>(favorites);
216
                }
217
        }
218 7 cordinyana
}