Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.annotation.app / org.gvsig.annotation.app.mainplugin / src / main / java / org / gvsig / annotation / app / extension / AnnotationExtension.java @ 40561

History | View | Annotate | Download (5.83 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
package org.gvsig.annotation.app.extension;
25

    
26
import java.util.Locale;
27

    
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.messages.NotificationManager;
31
import org.gvsig.andami.plugins.Extension;
32
import org.gvsig.annotation.AnnotationCreationService;
33
import org.gvsig.annotation.AnnotationLocator;
34
import org.gvsig.annotation.AnnotationManager;
35
import org.gvsig.annotation.swing.AnnotationSwingLocator;
36
import org.gvsig.annotation.swing.AnnotationSwingManager;
37
import org.gvsig.annotation.swing.AnnotationWindowManager;
38
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel;
39
import org.gvsig.app.ApplicationLocator;
40
import org.gvsig.app.ApplicationManager;
41
import org.gvsig.app.project.documents.view.ViewDocument;
42
import org.gvsig.app.project.documents.view.ViewManager;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.mapcontext.MapContext;
45
import org.gvsig.fmap.mapcontext.layers.FLayer;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
47
import org.gvsig.i18n.Messages;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.extensionpoint.ExtensionPoint;
50
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
51
import org.gvsig.tools.service.ServiceException;
52

    
53
/**
54
 * Andami extension to show Annotation in the application.
55
 * 
56
 * @author gvSIG Team
57
 * @version $Id$
58
 */
59
public class AnnotationExtension extends Extension {
60

    
61
    public static final String PERSIST_DEF_FONT_COLOR_KEY = "def_font_color";
62
    public static final String PERSIST_DEF_TEXT_VALUE_KEY = "def_text_value";
63
    public static final String PERSIST_DEF_FONT_TYPE_KEY = "def_font_type";
64
    public static final String PERSIST_DEF_FONT_STYLE_KEY = "def_font_style";
65
    public static final String PERSIST_DEF_FONT_HEIGHT_KEY = "def_font_height";
66
    public static final String PERSIST_DEF_FONT_ROTATION_KEY = "def_font_rotation";
67
    
68
        private AnnotationManager manager;
69
        private AnnotationSwingManager swingManager;
70

    
71
        public void initialize() {
72
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
73
                ExtensionPoint ep = extensionPoints.add("AplicationPreferences", "");
74
                
75
                ep.append("AnnotationPreferencesPage", "", new AnnotationPreferencesPage());
76
                
77
                IconThemeHelper.registerIcon("preferences", "annotation-preferences", this);
78

    
79
                if (!Messages.hasLocales()) {
80
                    Messages.addLocale(Locale.getDefault());
81
                }
82
                Messages.addResourceFamily("org.gvsig.annotation.app.extension.i18n.text",
83
                    AnnotationExtension.class.getClassLoader(),
84
                    AnnotationExtension.class.getClass().getName());
85
        }
86

    
87
        @Override
88
        public void postInitialize() {
89
                super.postInitialize();
90
                manager = AnnotationLocator.getManager();
91
                // Asignamos el locator e iniciamos la instancia
92
                swingManager = AnnotationSwingLocator.getSwingManager();
93

    
94
                swingManager.registerWindowManager(new GvSIGAnnotationWindowManager());                
95
        
96
        }
97

    
98
        private FLyrVect getCurrentLayer() {
99
                return this.getCurrentLayer(null); 
100
        }
101
        
102
        private FLyrVect getCurrentLayer(MapContext mapContext) {
103
                FLyrVect layer = null; 
104
                
105
                if( mapContext == null ) {
106
                        ApplicationManager application = ApplicationLocator.getManager();
107

    
108
                        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
109
                        if( view == null ) {
110
                                return null;
111
                        }
112
                        mapContext = view.getMapContext();
113
                }
114
                FLayer[] actives = mapContext.getLayers().getActives();
115

    
116
                for (int i=0 ; i<actives.length ; i++){
117
                        if (actives[i] instanceof FLyrVect){
118
                                layer = (FLyrVect)actives[i];
119
                                break;
120
                        }
121
                }
122
                return layer;
123
        }
124
        
125
        public void execute(String actionCommand) {
126
                ApplicationManager application = ApplicationLocator.getManager();
127

    
128
                ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
129
                if( view == null ) {
130
                        return;
131
                }
132
                MapContext mapContext = view.getMapContext();
133
                FLyrVect layer = getCurrentLayer(mapContext);
134
                if (layer == null){
135
                        return;
136
                }                
137
                showAnnotation(manager, layer.getFeatureStore(), mapContext);
138
        }
139

    
140
        public void showAnnotation(AnnotationManager manager, FeatureStore featureStore, MapContext mapContext) {
141
                try {
142
                        AnnotationCreationService service =
143
                                (AnnotationCreationService) manager.getAnnotationCreationService(featureStore);
144
                        service.setAnnotationCreationFinishAction(new AddLayerFinishAction(mapContext));
145

    
146
                        JAnnotationCreationServicePanel panel =
147
                                swingManager.createAnnotation(service);
148
                        swingManager.getWindowManager().showWindow(panel, "Annotation",
149
                                        AnnotationWindowManager.MODE_WINDOW);
150

    
151
                } catch (ServiceException e) {
152
                        NotificationManager.addError(e);
153
                }
154
        }
155

    
156
        public boolean isEnabled() {
157
                FLayer layer = getCurrentLayer();
158
                if( layer == null ) {
159
                        return false;
160
                }
161
                return true;
162
        }
163

    
164
        public boolean isVisible() {
165
                ApplicationManager application = ApplicationLocator.getManager();
166

    
167
                ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
168
                if( view == null ) {
169
                        return false;
170
                }
171
                return true;
172
        }
173
}