svn-gvsig-desktop / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / Annotation_Extension.java @ 28605
History | View | Annotate | Download (6.28 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 |
package com.iver.cit.gvsig; |
42 |
|
43 |
import javax.swing.ImageIcon; |
44 |
|
45 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
46 |
import com.iver.andami.PluginServices; |
47 |
import com.iver.andami.messages.NotificationManager; |
48 |
import com.iver.andami.plugins.Extension; |
49 |
import com.iver.andami.preferences.IPreference; |
50 |
import com.iver.andami.preferences.IPreferenceExtension; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
56 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
57 |
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard; |
58 |
import com.iver.cit.gvsig.project.documents.gui.Annotation_ConfigureLabel; |
59 |
import com.iver.cit.gvsig.project.documents.gui.Annotation_Create; |
60 |
import com.iver.cit.gvsig.project.documents.gui.Annotation_FieldSelect; |
61 |
import com.iver.cit.gvsig.project.documents.gui.Annotation_Open; |
62 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
63 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.General; |
64 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.PanelLegendAnnotation; |
65 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ThemeManagerWindow; |
66 |
import com.iver.cit.gvsig.project.documents.view.legend.preferences.Annotation_Preferences; |
67 |
|
68 |
/**
|
69 |
* Extension to create an annotation layer.
|
70 |
*
|
71 |
* @author Vicente Caballero Navarro
|
72 |
*/
|
73 |
public class Annotation_Extension extends Extension implements |
74 |
IPreferenceExtension { |
75 |
private MapContext map = null; |
76 |
|
77 |
private Annotation_Preferences ap = new Annotation_Preferences(); |
78 |
|
79 |
/**
|
80 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
81 |
*/
|
82 |
public void initialize() { |
83 |
|
84 |
AddLayer.addWizard(Annotation_Open.class); |
85 |
|
86 |
ThemeManagerWindow.addPage(PanelLegendAnnotation.class); |
87 |
|
88 |
ThemeManagerWindow.setTabEnabledForLayer(General.class, Annotation_Layer.class, true);
|
89 |
ThemeManagerWindow.setTabEnabledForLayer(PanelLegendAnnotation.class, Annotation_Layer.class, true);
|
90 |
registerIcons(); |
91 |
} |
92 |
|
93 |
private void registerIcons(){ |
94 |
PluginServices.getIconTheme().registerDefault( |
95 |
"ext-annotation-pack-graphics",
|
96 |
this.getClass().getClassLoader().getResource("images/package_graphics.png") |
97 |
); |
98 |
|
99 |
PluginServices.getIconTheme().registerDefault( |
100 |
"annotation-properties",
|
101 |
Annotation_Preferences.class.getClassLoader().getResource("images/AnnotationProperties.png")
|
102 |
); |
103 |
|
104 |
PluginServices.getIconTheme().registerDefault( |
105 |
"annotation-modify",
|
106 |
this.getClass().getClassLoader().getResource("images/ModifyAnnotationCursor.png") |
107 |
); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
112 |
*/
|
113 |
public void execute(String actionCommand) { |
114 |
if ("ANNOTATIONLAYER".equals(actionCommand)) { |
115 |
ImageIcon Logo=PluginServices.getIconTheme().get("ext-annotation-pack-graphics"); |
116 |
|
117 |
SimpleWizard wizard = new SimpleWizard(Logo);
|
118 |
|
119 |
FLyrVect lv = (FLyrVect) map.getLayers().getActives()[0];
|
120 |
Annotation_Layer la=null;
|
121 |
try {
|
122 |
la = Annotation_Layer.createLayerFromVect(lv); |
123 |
} catch (ReadDriverException e) {
|
124 |
NotificationManager.addError(e); |
125 |
} |
126 |
la.setName(lv.getName()); |
127 |
|
128 |
Annotation_FieldSelect panel1 = new Annotation_FieldSelect(wizard
|
129 |
.getWizardComponents(), la); |
130 |
Annotation_ConfigureLabel panel2 = new Annotation_ConfigureLabel(
|
131 |
wizard.getWizardComponents(), la); |
132 |
|
133 |
wizard.getWizardComponents().addWizardPanel(panel1); |
134 |
wizard.getWizardComponents().addWizardPanel(panel2); |
135 |
|
136 |
wizard.getWizardComponents() |
137 |
.setFinishAction( |
138 |
new Annotation_Create(wizard.getWizardComponents(),
|
139 |
map, la)); |
140 |
|
141 |
wizard.getWindowInfo().setWidth(540);
|
142 |
wizard.getWindowInfo().setHeight(380);
|
143 |
wizard.getWindowInfo().setTitle( |
144 |
PluginServices.getText(this, "to_annotation")); |
145 |
|
146 |
PluginServices.getMDIManager().addWindow(wizard); |
147 |
|
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
153 |
*/
|
154 |
public boolean isEnabled() { |
155 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
156 |
|
157 |
if ((v != null) |
158 |
&& v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
|
159 |
com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) v; |
160 |
IProjectView model = vista.getModel(); |
161 |
map = model.getMapContext(); |
162 |
|
163 |
FLayer[] layers = map.getLayers().getActives();
|
164 |
|
165 |
if (layers.length == 1) { |
166 |
if (layers[0].isAvailable() && layers[0] instanceof FLyrVect) { |
167 |
FLyrVect lv = (FLyrVect) layers[0];
|
168 |
try {
|
169 |
SelectableDataSource sds = lv.getSource() |
170 |
.getRecordset(); |
171 |
|
172 |
if (sds.getFieldCount() > 0) { |
173 |
return true; |
174 |
} |
175 |
} catch (ReadDriverException e) {
|
176 |
return false; |
177 |
} |
178 |
} |
179 |
} |
180 |
} |
181 |
|
182 |
return false; |
183 |
} |
184 |
|
185 |
/**
|
186 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
187 |
*/
|
188 |
public boolean isVisible() { |
189 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
190 |
|
191 |
if (v == null) { |
192 |
return false; |
193 |
} else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
194 |
return true; |
195 |
} else {
|
196 |
return false; |
197 |
} |
198 |
} |
199 |
|
200 |
public IPreference[] getPreferencesPages() { |
201 |
return new IPreference[] {ap}; |
202 |
} |
203 |
} |