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 @ 852
History | View | Annotate | Download (6.93 KB)
1 |
/**
|
---|---|
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 |
import java.awt.EventQueue; |
27 |
import java.net.URL; |
28 |
|
29 |
import org.gvsig.proj.CoordinateReferenceSystem; |
30 |
import org.gvsig.proj.CoordinateReferenceSystemLocator; |
31 |
import org.gvsig.proj.CoordinateReferenceSystemManager; |
32 |
import org.gvsig.proj.CoordinateTransformation; |
33 |
import org.gvsig.proj.catalog.CRSCatalogLocator; |
34 |
import org.gvsig.proj.catalog.CRSCatalogManager; |
35 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
36 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingManager; |
37 |
import org.gvsig.proj.swing.CoordinateTransformationSelectorComponent; |
38 |
import org.gvsig.proj.swing.RecentHistory; |
39 |
import org.gvsig.proj.swing.impl.history.History; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
43 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
44 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
/**
|
49 |
* Default implementation of the {@link CoordinateReferenceSystemSwingManager}.
|
50 |
*
|
51 |
* @author gvSIG Team
|
52 |
* @version $Id$
|
53 |
*/
|
54 |
public class DefaultCoordinateReferenceSystemSwingManager implements |
55 |
CoordinateReferenceSystemSwingManager { |
56 |
private static Logger logger = LoggerFactory.getLogger(DefaultCoordinateReferenceSystemSwingManager.class); |
57 |
private I18nManager i18nmanager = null; |
58 |
private RecentHistory<CoordinateReferenceSystem> crsHistory;
|
59 |
private RecentHistory<CoordinateTransformation> transformationHistory;
|
60 |
private RecentHistory<String> crsTextFilterHistory; |
61 |
private RecentHistory<String> transformationTextFilterHistory; |
62 |
private volatile IconTheme iconTheme = null; |
63 |
private volatile boolean registeredIcons = false; |
64 |
|
65 |
public DefaultCoordinateReferenceSystemSwingManager() {
|
66 |
this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
67 |
//this.manager = CoordinateReferenceSystemLocator.getManager();
|
68 |
this.i18nmanager = ToolsLocator.getI18nManager();
|
69 |
crsHistory = new History<CoordinateReferenceSystem>();
|
70 |
transformationHistory = new History<CoordinateTransformation>();
|
71 |
crsTextFilterHistory = new History<String>(); |
72 |
transformationTextFilterHistory = new History<String>(); |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public CoordinateReferenceSystemManager getCRSManager() {
|
77 |
return CoordinateReferenceSystemLocator.getManager();
|
78 |
//return this.manager;
|
79 |
} |
80 |
|
81 |
public String getTranslation(String key) { |
82 |
return this.i18nmanager.getTranslation(key); |
83 |
} |
84 |
|
85 |
public WindowManager getWindowManager() {
|
86 |
return ToolsSwingLocator.getWindowManager();
|
87 |
} |
88 |
|
89 |
public CoordinateReferenceSystemSelectorComponent createCoordinateReferenceSystemSelectionComponent() {
|
90 |
/**
|
91 |
* Ensures the icons have been registered. We can't do it at manager initialization because the
|
92 |
* IconThemeManager may not be initialized at that point
|
93 |
*/
|
94 |
registerIcons(); |
95 |
return new CrsSelectorComponent(this); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public CoordinateTransformationSelectorComponent createCoordinateTransformSelectionComponent() {
|
100 |
/**
|
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 |
registerIcons(); |
105 |
return null; |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Ensures the icons have been registered.
|
110 |
*/
|
111 |
protected void registerIcons() { |
112 |
if (registeredIcons == false) { |
113 |
final IconTheme theme = getIconTheme();
|
114 |
synchronized (this) { |
115 |
if (registeredIcons == false) { |
116 |
doRegisterIcons(theme); |
117 |
registeredIcons = true;
|
118 |
} |
119 |
|
120 |
} |
121 |
} |
122 |
} |
123 |
|
124 |
protected void doRegisterIcons(IconTheme iconTheme) { |
125 |
String group = "swingproj"; |
126 |
registerIcon(group, "bullet_add", null, iconTheme); |
127 |
registerIcon(group, "bullet_remove", null, iconTheme); |
128 |
registerIcon(group, "bullet_share", null, iconTheme); |
129 |
registerIcon(group, "crs_add", null, iconTheme); |
130 |
registerIcon(group, "crs", null, iconTheme); |
131 |
registerIcon(group, "ct_add", null, iconTheme); |
132 |
registerIcon(group, "ct", null, iconTheme); |
133 |
registerIcon(group, "dropdown", null, iconTheme); |
134 |
registerIcon(group, "favourite_add", null, iconTheme); |
135 |
registerIcon(group, "favourite", null, iconTheme); |
136 |
registerIcon(group, "favourite_remove", null, iconTheme); |
137 |
registerIcon(group, "filter_alpha", null, iconTheme); |
138 |
registerIcon(group, "filter_spatial", null, iconTheme); |
139 |
registerIcon(group, "folder_closed", null, iconTheme); |
140 |
registerIcon(group, "folder_open", null, iconTheme); |
141 |
registerIcon(group, "recent", null, iconTheme); |
142 |
registerIcon(group, "recent_remove", null, iconTheme); |
143 |
registerIcon(group, "search", null, iconTheme); |
144 |
registerIcon(group, "search_remove", null, iconTheme); |
145 |
registerIcon(group, "unlock", null, iconTheme); |
146 |
registerIcon(group, "spinner", ".gif", iconTheme); |
147 |
} |
148 |
|
149 |
protected void registerIcon(String group, String name, String extension, IconTheme iconTheme) { |
150 |
if (extension==null) { |
151 |
extension = ".png";
|
152 |
} |
153 |
String resourceName = "images/" + group + "/" + name + extension; |
154 |
String provider = this.getClass().getName(); |
155 |
ClassLoader loader = this.getClass().getClassLoader(); |
156 |
URL resource = null; |
157 |
try {
|
158 |
resource = loader.getResource(resourceName); |
159 |
iconTheme.registerDefault(provider, group, name, null, resource);
|
160 |
} catch( Throwable e) { |
161 |
logger.info("Can't register icon '" + name + "'.",e); |
162 |
} |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public CRSCatalogManager getCatalogManager() {
|
167 |
return CRSCatalogLocator.getManager();
|
168 |
} |
169 |
|
170 |
@Override
|
171 |
public IconTheme getIconTheme() {
|
172 |
return iconTheme;
|
173 |
} |
174 |
|
175 |
@Override
|
176 |
public RecentHistory<CoordinateReferenceSystem> getCoordinateReferenceSystemHistory() {
|
177 |
return crsHistory;
|
178 |
} |
179 |
|
180 |
@Override
|
181 |
public RecentHistory<CoordinateTransformation> getTransformationHistory() {
|
182 |
return transformationHistory;
|
183 |
} |
184 |
|
185 |
@Override
|
186 |
public RecentHistory<String> getCoordinateReferenceSystemTextFilterHistory() { |
187 |
return crsTextFilterHistory;
|
188 |
} |
189 |
|
190 |
@Override
|
191 |
public RecentHistory<String> getTransformationTextFilterHistory() { |
192 |
return transformationTextFilterHistory;
|
193 |
} |
194 |
} |