svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.plugin / org.gvsig.annotation.app / org.gvsig.annotation.app.mainplugin / src / main / java / org / gvsig / annotation / app / extension / AnnotationExtension.java @ 43830
History | View | Annotate | Download (5.49 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 org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.messages.NotificationManager; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.annotation.AnnotationCreationService; |
30 |
import org.gvsig.annotation.AnnotationLocator; |
31 |
import org.gvsig.annotation.AnnotationManager; |
32 |
import org.gvsig.annotation.swing.AnnotationSwingLocator; |
33 |
import org.gvsig.annotation.swing.AnnotationSwingManager; |
34 |
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel; |
35 |
import org.gvsig.app.ApplicationLocator; |
36 |
import org.gvsig.app.ApplicationManager; |
37 |
import org.gvsig.app.project.documents.view.ViewDocument; |
38 |
import org.gvsig.app.project.documents.view.ViewManager; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.mapcontext.MapContext; |
41 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
42 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
43 |
import org.gvsig.tools.ToolsLocator; |
44 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
45 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
46 |
import org.gvsig.tools.service.ServiceException; |
47 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
49 |
|
50 |
/**
|
51 |
* Andami extension to show Annotation in the application.
|
52 |
*
|
53 |
* @author gvSIG Team
|
54 |
* @version $Id$
|
55 |
*/
|
56 |
public class AnnotationExtension extends Extension { |
57 |
|
58 |
public static final String PERSIST_DEF_FONT_COLOR_KEY = "def_font_color"; |
59 |
public static final String PERSIST_DEF_TEXT_VALUE_KEY = "def_text_value"; |
60 |
public static final String PERSIST_DEF_FONT_TYPE_KEY = "def_font_type"; |
61 |
public static final String PERSIST_DEF_FONT_STYLE_KEY = "def_font_style"; |
62 |
public static final String PERSIST_DEF_FONT_HEIGHT_KEY = "def_font_height"; |
63 |
public static final String PERSIST_DEF_FONT_ROTATION_KEY = "def_font_rotation"; |
64 |
|
65 |
private AnnotationManager manager;
|
66 |
private AnnotationSwingManager swingManager;
|
67 |
|
68 |
public void initialize() { |
69 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
70 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
71 |
|
72 |
ep.append("AnnotationPreferencesPage", "", new AnnotationPreferencesPage()); |
73 |
|
74 |
IconThemeHelper.registerIcon("preferences", "annotation-preferences", this); |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void postInitialize() { |
79 |
super.postInitialize();
|
80 |
manager = AnnotationLocator.getManager(); |
81 |
// Asignamos el locator e iniciamos la instancia
|
82 |
swingManager = AnnotationSwingLocator.getSwingManager(); |
83 |
} |
84 |
|
85 |
private FLyrVect getCurrentLayer() {
|
86 |
return this.getCurrentLayer(null); |
87 |
} |
88 |
|
89 |
private FLyrVect getCurrentLayer(MapContext mapContext) {
|
90 |
FLyrVect layer = null;
|
91 |
|
92 |
if( mapContext == null ) { |
93 |
ApplicationManager application = ApplicationLocator.getManager(); |
94 |
|
95 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
96 |
if( view == null ) { |
97 |
return null; |
98 |
} |
99 |
mapContext = view.getMapContext(); |
100 |
} |
101 |
FLayer[] actives = mapContext.getLayers().getActives();
|
102 |
|
103 |
for (int i=0 ; i<actives.length ; i++){ |
104 |
if (actives[i] instanceof FLyrVect){ |
105 |
layer = (FLyrVect)actives[i]; |
106 |
break;
|
107 |
} |
108 |
} |
109 |
return layer;
|
110 |
} |
111 |
|
112 |
public void execute(String actionCommand) { |
113 |
ApplicationManager application = ApplicationLocator.getManager(); |
114 |
|
115 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
116 |
if( view == null ) { |
117 |
return;
|
118 |
} |
119 |
MapContext mapContext = view.getMapContext(); |
120 |
FLyrVect layer = getCurrentLayer(mapContext); |
121 |
if (layer == null){ |
122 |
return;
|
123 |
} |
124 |
showAnnotation(manager, layer.getFeatureStore(), mapContext); |
125 |
} |
126 |
|
127 |
public void showAnnotation(AnnotationManager manager, FeatureStore featureStore, MapContext mapContext) { |
128 |
try {
|
129 |
AnnotationCreationService service = |
130 |
(AnnotationCreationService) manager.getAnnotationCreationService(featureStore); |
131 |
service.setAnnotationCreationFinishAction(new AddLayerFinishAction(mapContext));
|
132 |
|
133 |
JAnnotationCreationServicePanel panel =swingManager.createAnnotation(service); |
134 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
135 |
windowManager.showWindow(panel, "Annotation", WindowManager.MODE.WINDOW);
|
136 |
|
137 |
} catch (ServiceException e) {
|
138 |
NotificationManager.addError(e); |
139 |
} |
140 |
} |
141 |
|
142 |
public boolean isEnabled() { |
143 |
FLayer layer = getCurrentLayer(); |
144 |
if( layer == null ) { |
145 |
return false; |
146 |
} |
147 |
return true; |
148 |
} |
149 |
|
150 |
public boolean isVisible() { |
151 |
ApplicationManager application = ApplicationLocator.getManager(); |
152 |
|
153 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
154 |
if( view == null ) { |
155 |
return false; |
156 |
} |
157 |
return true; |
158 |
} |
159 |
} |