svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / webmapcontext / ImportWebMapContextExtension.java @ 4894
History | View | Annotate | Download (5.07 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: ImportWebMapContextExtension.java 4894 2006-04-19 16:34:29Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2006-04-19 16:34:29 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2006/04/19 07:57:29 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1 2006/04/12 17:10:53 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.cit.gvsig.webmapcontext; |
58 |
|
59 |
import java.awt.Component; |
60 |
import java.awt.JobAttributes; |
61 |
import java.io.File; |
62 |
import java.text.DateFormat; |
63 |
import java.util.Date; |
64 |
|
65 |
import javax.swing.JFileChooser; |
66 |
import javax.swing.JOptionPane; |
67 |
import javax.swing.filechooser.FileFilter; |
68 |
|
69 |
import com.iver.andami.PluginServices; |
70 |
import com.iver.andami.plugins.Extension; |
71 |
import com.iver.andami.ui.mdiManager.View; |
72 |
import com.iver.cit.gvsig.ProjectExtension; |
73 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
74 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
75 |
import com.iver.cit.gvsig.gui.panels.WebMapContextFileChooserAccessory; |
76 |
import com.iver.cit.gvsig.project.Project; |
77 |
import com.iver.cit.gvsig.project.ProjectFactory; |
78 |
import com.iver.cit.gvsig.project.ProjectView; |
79 |
|
80 |
public class ImportWebMapContextExtension implements Extension { |
81 |
private static String mapContextFileExtension = ".cml"; |
82 |
|
83 |
public void inicializar() { |
84 |
|
85 |
} |
86 |
|
87 |
public void execute(String actionCommand) { |
88 |
if (actionCommand.equals("IMPORT")) { |
89 |
JFileChooser fc = new JFileChooser(); |
90 |
fc.setFileFilter(new FileFilter() { |
91 |
public boolean accept(File f) { |
92 |
return f.isDirectory() || f.getAbsolutePath().toLowerCase().endsWith(mapContextFileExtension);
|
93 |
} |
94 |
|
95 |
public String getDescription() { |
96 |
return PluginServices.getText(this, "ogc_mapcontext_file")+" (*.cml)"; |
97 |
} |
98 |
}); |
99 |
View v = PluginServices.getMDIManager().getActiveView();
|
100 |
|
101 |
// If the current active view is a gvSIG's view, we'll keep its name to
|
102 |
// show it at the JFileChooser's accessory.
|
103 |
String currentViewName;
|
104 |
if (v instanceof com.iver.cit.gvsig.gui.View) |
105 |
currentViewName = ((com.iver.cit.gvsig.gui.View) v).getModel().getName(); |
106 |
else
|
107 |
currentViewName = null;
|
108 |
|
109 |
// Create an accessory for the Web Map Context's file chooser.
|
110 |
WebMapContextFileChooserAccessory acc = new WebMapContextFileChooserAccessory(currentViewName);
|
111 |
|
112 |
// Add the accessory to the file chooser
|
113 |
fc.setAccessory(acc); |
114 |
|
115 |
// Nothing else than Web Map Context files allowed
|
116 |
fc.setAcceptAllFileFilterUsed(false);
|
117 |
|
118 |
if (fc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){ |
119 |
readMapContextFile(fc.getSelectedFile(), acc.getSelectedView()); |
120 |
} |
121 |
fc = null;
|
122 |
} |
123 |
} |
124 |
|
125 |
private void readMapContextFile(File wmcFile, ProjectView dstView) { |
126 |
try {
|
127 |
WebMapContext wmc = new WebMapContext(wmcFile);
|
128 |
|
129 |
if (dstView == null) { |
130 |
// Since the destination view is null, a new one will be added to
|
131 |
// the project.
|
132 |
dstView = ProjectFactory.createView(null);
|
133 |
dstView.setName(wmc.title); |
134 |
dstView.setComment("Created from WebMapContext file: "+wmcFile.getName());
|
135 |
|
136 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
137 |
Project theProject = pe.getProject(); |
138 |
theProject.addView(dstView); |
139 |
|
140 |
// show the view in a new window
|
141 |
com.iver.cit.gvsig.gui.View v = null;
|
142 |
v = new com.iver.cit.gvsig.gui.View();
|
143 |
v.setModel(dstView); |
144 |
PluginServices.getMDIManager().addView(v); |
145 |
} |
146 |
|
147 |
for (int i = 0; i < wmc.layerList.size(); i++) { |
148 |
// WMS layers
|
149 |
if (wmc.layerList.get(i) instanceof FLyrWMS) { |
150 |
FLyrWMS layer = (FLyrWMS) wmc.layerList.get(i); |
151 |
dstView.getMapContext().getLayers().addLayer(layer); |
152 |
} |
153 |
} |
154 |
} catch (UnsupportedVersionException e) {
|
155 |
JOptionPane.showMessageDialog(
|
156 |
(Component) PluginServices.getMainFrame(),
|
157 |
e.getMessage(), |
158 |
PluginServices.getText(this, "unsupported_version"), |
159 |
JOptionPane.ERROR_MESSAGE);
|
160 |
e.printStackTrace(); |
161 |
} |
162 |
|
163 |
} |
164 |
|
165 |
public boolean isEnabled() { |
166 |
return true; |
167 |
} |
168 |
|
169 |
public boolean isVisible() { |
170 |
return true; |
171 |
} |
172 |
|
173 |
} |