root / branches / v2_0_0_prep / extensions / org.gvsig.annotation / src / main / java / org / gvsig / annotation / AnnotationCreateExtension.java @ 31277
History | View | Annotate | Download (6.41 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
package org.gvsig.annotation; |
43 |
|
44 |
import java.io.File; |
45 |
|
46 |
import javax.swing.ImageIcon; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.plugins.Extension; |
50 |
import org.gvsig.andami.preferences.IPreference; |
51 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
52 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
53 |
import org.gvsig.annotation.create.AnnotationConfigureLabelsPanel; |
54 |
import org.gvsig.annotation.create.AnnotationCreateAction; |
55 |
import org.gvsig.annotation.create.AnnotationFieldSelectPanel; |
56 |
import org.gvsig.app.gui.simpleWizard.SimpleWizard; |
57 |
import org.gvsig.app.project.documents.view.IProjectView; |
58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
60 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
62 |
import org.gvsig.tools.ToolsLocator; |
63 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
64 |
|
65 |
/**
|
66 |
* Extension to export one vector layer to a new annotation layer.
|
67 |
* This anotation layer will be saved as Shapefile.
|
68 |
*
|
69 |
* @author Vicente Caballero Navarro
|
70 |
* Migrated to gvSIG 2.0 by Carlos S?nchez Peri??n
|
71 |
*/
|
72 |
public class AnnotationCreateExtension extends Extension implements IPreferenceExtension |
73 |
{ |
74 |
private static final String ANNOTATION = "Anotation layer"; |
75 |
|
76 |
private org.gvsig.fmap.mapcontext.MapContext map = null; |
77 |
|
78 |
/**
|
79 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
80 |
*/
|
81 |
public void initialize() { |
82 |
ExtensionPointManager extensionPointManager = ToolsLocator.getExtensionPointManager(); |
83 |
extensionPointManager.add(ANNOTATION, "Set a new shapefile as annotation layer");
|
84 |
registerIcons(); |
85 |
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Register the extension icons on gvSIG
|
90 |
*/
|
91 |
public void registerIcons(){ |
92 |
PluginServices.getIconTheme().registerDefault( |
93 |
"annotation",
|
94 |
this.getClass().getClassLoader().getResource("images/Annotation.png") |
95 |
); |
96 |
PluginServices.getIconTheme().registerDefault( |
97 |
"annotation-properties",
|
98 |
this.getClass().getClassLoader().getResource("images/AnnotationProperties.png") |
99 |
); |
100 |
PluginServices.getIconTheme().registerDefault( |
101 |
"logo-gva",
|
102 |
this.getClass().getClassLoader().getResource("images/logo_horiz_bicolor_gva.png") |
103 |
); |
104 |
PluginServices.getIconTheme().registerDefault( |
105 |
"annotation-cursor",
|
106 |
this.getClass().getClassLoader().getResource("images/ModifyAnnotationCursor.png") |
107 |
); |
108 |
PluginServices.getIconTheme().registerDefault( |
109 |
"annotation-logo",
|
110 |
this.getClass().getClassLoader().getResource("images/logo-gvSIG-Annotation.png") |
111 |
); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
116 |
*/
|
117 |
public void execute(String actionCommand) { |
118 |
if ("ANNOTATIONLAYER".equals(actionCommand)) { |
119 |
ImageIcon Logo = new ImageIcon(this.getClass().getClassLoader().getResource("images"+File.separatorChar+"logo-gvSIG-Annotation.png")); |
120 |
SimpleWizard wizard = new SimpleWizard(Logo);
|
121 |
|
122 |
//Only export the first layer selected into an annotation layer
|
123 |
FLyrVect lv = (FLyrVect) map.getLayers().getActives()[0];
|
124 |
|
125 |
//Creates two panels:
|
126 |
//One to select the annotation tag and orientation from one of the shapefile field.
|
127 |
//Secondly the other panel allow configure the mapping with labels
|
128 |
AnnotationFieldSelectPanel panel1 = new AnnotationFieldSelectPanel(wizard.getWizardComponents(), lv);
|
129 |
AnnotationConfigureLabelsPanel panel2 = new AnnotationConfigureLabelsPanel(wizard.getWizardComponents(), lv);
|
130 |
|
131 |
wizard.getWizardComponents().addWizardPanel(panel1); |
132 |
wizard.getWizardComponents().addWizardPanel(panel2); |
133 |
|
134 |
wizard.getWizardComponents().setFinishAction(new AnnotationCreateAction(wizard.getWizardComponents(), lv));
|
135 |
|
136 |
wizard.getWindowInfo().setWidth(540);
|
137 |
wizard.getWindowInfo().setHeight(380);
|
138 |
wizard.getWindowInfo().setTitle(PluginServices.getText(this, "to_annotation")); |
139 |
|
140 |
PluginServices.getMDIManager().addWindow(wizard); |
141 |
} |
142 |
} |
143 |
|
144 |
/**
|
145 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
146 |
*/
|
147 |
public boolean isEnabled() { |
148 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
149 |
|
150 |
if ((v != null) && v instanceof org.gvsig.app.project.documents.view.gui.View) { |
151 |
org.gvsig.app.project.documents.view.gui.View vista = (org.gvsig.app.project.documents.view.gui.View) v; |
152 |
IProjectView model = vista.getModel(); |
153 |
map = model.getMapContext(); |
154 |
|
155 |
FLayer[] layers = map.getLayers().getActives();
|
156 |
|
157 |
if (layers.length == 1) { |
158 |
if (layers[0].isAvailable() && layers[0] instanceof FLyrVect) { |
159 |
FLyrVect lv = (FLyrVect) layers[0];
|
160 |
try {
|
161 |
FeatureStore store = lv.getFeatureStore(); |
162 |
if (store.getFeatureSet().getSize() > 0){ |
163 |
return true; |
164 |
} |
165 |
} catch (DataException e) {
|
166 |
return false; |
167 |
} |
168 |
} |
169 |
} |
170 |
} |
171 |
return false; |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
176 |
*/
|
177 |
public boolean isVisible() { |
178 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
179 |
|
180 |
if (v == null) { |
181 |
return false; |
182 |
} else if (v instanceof org.gvsig.app.project.documents.view.gui.View) { |
183 |
return true; |
184 |
} else {
|
185 |
return false; |
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* @see com.iver.andami.preferences.IPreferenceExtension#getPreferencesPages()
|
191 |
*/
|
192 |
public IPreference[] getPreferencesPages() { |
193 |
//IPreference[] preferences=new IPreference[1];
|
194 |
//preferences[0]=(IPreference) preferences;
|
195 |
//return preferences;
|
196 |
return null; |
197 |
} |
198 |
} |