Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extJCRS / src / org / gvsig / crs / JCrsExtension.java @ 34007

History | View | Annotate | Download (4.77 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

    
41

    
42
package org.gvsig.crs;
43

    
44
import java.util.Arrays;
45
import java.util.Iterator;
46

    
47
import org.geotools.factory.FactoryRegistry;
48
import org.geotools.referencing.operation.MathTransformProvider;
49
import org.gvsig.about.AboutManager;
50
import org.gvsig.about.AboutParticipant;
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.plugins.Extension;
53
import org.gvsig.app.ApplicationLocator;
54
import org.gvsig.app.ApplicationManager;
55
import org.gvsig.app.extension.About;
56
import org.gvsig.app.gui.panels.CRSSelectPanel;
57
import org.gvsig.app.gui.panels.FPanelAbout;
58
import org.gvsig.app.project.ProjectPreferences;
59
import org.gvsig.crs.gui.panels.CrsUIFactory;
60
import org.gvsig.crs.gui.panels.ProjChooserPanel;
61
import org.gvsig.fmap.crs.CRSFactory;
62
import org.gvsig.utils.XMLEntity;
63

    
64

    
65
public class JCrsExtension extends Extension {
66

    
67
        private static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection";
68
        private static final String FACTORY_DEFAULT_PROJECTION = "EPSG:23030";
69

    
70
        public void initialize() {
71

    
72
                /*
73
                 * Se eliminan del registro de geotools las proyecciones que aporta libJCrs para asegurar que
74
                 * son estas ?ltimas las que se utilizan.
75
                 */
76
                final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class};
77
                FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories));
78
                Iterator providers = registry.getServiceProviders(MathTransformProvider.class);
79
                Iterator providers2 = null;
80
                MathTransformProvider provider = null;
81
                MathTransformProvider provider2 = null;
82

    
83
                while (providers.hasNext()){
84
                        provider = (MathTransformProvider) providers.next();
85
                        if(provider.nameMatches("IDR")){
86
                                providers2 = registry.getServiceProviders(MathTransformProvider.class);
87
                                while (providers2.hasNext()){
88
                                        provider2 = (MathTransformProvider) providers2.next();
89
                                        if(provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR")) {
90
                                                registry.deregisterServiceProvider(provider2, categories[0]);
91
                                        }
92
                                }
93
                        }
94
                }
95

    
96
                //TODO: Solo para depurar: BORRAR
97
                providers = registry.getServiceProviders(MathTransformProvider.class);
98
                while (providers.hasNext()) {
99
            provider = (MathTransformProvider) providers.next();
100
            System.out.println(provider.toString());
101
                }
102
                /*
103
                 *
104
                 */
105

    
106

    
107
                CRSFactory.cp = new CrsFactory();
108
                CRSSelectPanel.registerPanelClass(ProjChooserPanel.class);
109
                CRSSelectPanel.registerUIFactory(CrsUIFactory.class);
110
                //        Default Projection
111
                PluginServices ps = PluginServices.getPluginServices("org.gvsig.app");
112
                XMLEntity xml = ps.getPersistentXML();
113
                String projCode = null;
114
                if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
115
                        projCode = xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME);
116
                } else {
117
                        projCode = FACTORY_DEFAULT_PROJECTION;
118
                }
119
                ((ProjectPreferences) ApplicationLocator.getManager().getPreferences(
120
                                "project")).setDefaultProjection(CRSFactory.getCRS(projCode));
121

    
122
                addAboutInfo();
123
        }
124

    
125
        private void addAboutInfo() {
126
                ApplicationManager application = ApplicationLocator.getManager();
127
                
128
                AboutManager about = application.getAbout();
129

    
130
                about.addDeveloper(
131
                                "UCLM-IDR",
132
                                this.getClass().getClassLoader().getResource("about.html"),
133
                                1
134
                );
135
                
136
                AboutParticipant participant = about.getDeveloper("UCLM-IDR");
137
                participant.addContribution(
138
                        "jCRS",
139
                        "Extensi?n para el manejo de Sistemas de Referencia de Coordenadas", 
140
                        2006,1,1, 
141
                        2007,12,31
142
                );           
143
        }
144
        
145
        public void execute(String actionCommand) {
146

    
147

    
148
        }
149

    
150
        public boolean isEnabled() {
151

    
152
                return true;
153
        }
154

    
155
        public boolean isVisible() {
156

    
157
                return false;
158
        }
159

    
160
}