gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.app / org.gvsig.raster.wmts.app.wmtsclient / src / main / java / org / gvsig / raster / wmts / app / wmtsclient / gui / dialog / WMTSPropsDialog.java @ 948
History | View | Annotate | Download (9.64 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
package org.gvsig.raster.wmts.app.wmtsclient.gui.dialog; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.util.HashMap; |
29 |
|
30 |
import javax.swing.JOptionPane; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
36 |
import org.gvsig.app.gui.wizards.WizardListener; |
37 |
import org.gvsig.fmap.mapcontext.MapContext; |
38 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
41 |
import org.gvsig.fmap.mapcontrol.MapControl; |
42 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
43 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
44 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
45 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
46 |
import org.gvsig.raster.util.CancelTaskImpl; |
47 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.WMTSGUIInterface; |
48 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.WMTSParamsPanel; |
49 |
import org.gvsig.raster.wmts.app.wmtsclient.layer.FLyrWMTS; |
50 |
import org.gvsig.raster.wmts.io.WMTSServerExplorer; |
51 |
import org.gvsig.remoteclient.wmts.exception.WMTSException; |
52 |
|
53 |
|
54 |
/**
|
55 |
* The TOC WMTS properties panel container.
|
56 |
*
|
57 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
58 |
*/
|
59 |
public class WMTSPropsDialog extends JPanel implements IWindow, ButtonsPanelListener { |
60 |
private static final long serialVersionUID = 1L; |
61 |
private FLyrWMTS fLayer = null; |
62 |
private WindowInfo m_ViewInfo = null; |
63 |
private ButtonsPanel buttonsPanel = null; |
64 |
private WMTSGUIInterface wmtsGUIInterface = null; |
65 |
private WMTSServerExplorer explorer = null; |
66 |
|
67 |
public WMTSPropsDialog() {
|
68 |
initialize(null);
|
69 |
} |
70 |
|
71 |
public WMTSPropsDialog(FLayer layer) {
|
72 |
super();
|
73 |
if(layer instanceof FLyrWMTS) { |
74 |
fLayer = (FLyrWMTS)layer; |
75 |
initialize(fLayer); |
76 |
} |
77 |
} |
78 |
|
79 |
private void initialize(FLyrWMTS layer) { |
80 |
HashMap<String, Object> hash = layer != null ? layer.getProperties() : null; |
81 |
wmtsGUIInterface = getParamsPanel(hash); |
82 |
wmtsGUIInterface.addWizardListener(new WizardListener(){
|
83 |
@SuppressWarnings("deprecation") |
84 |
public void wizardStateChanged(boolean finishable) { |
85 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(finishable); |
86 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(finishable); |
87 |
} |
88 |
|
89 |
public void error(Exception e) { |
90 |
} |
91 |
|
92 |
}); |
93 |
setLayout(new BorderLayout()); |
94 |
this.add(wmtsGUIInterface.getComponent(), BorderLayout.CENTER); |
95 |
this.add(getButtonsPanel(), BorderLayout.SOUTH); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Gets the buttons panel
|
100 |
* @return
|
101 |
*/
|
102 |
public ButtonsPanel getButtonsPanel() {
|
103 |
if(buttonsPanel == null) { |
104 |
buttonsPanel = new ButtonsPanel();
|
105 |
buttonsPanel.addApply(); |
106 |
buttonsPanel.addAccept(); |
107 |
buttonsPanel.addClose(); |
108 |
buttonsPanel.addButtonPressedListener(this);
|
109 |
} |
110 |
return buttonsPanel;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* With getParamsPanel we have access to the map config TabbedPane.
|
115 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
116 |
* recovered) it is been automatically constructed by connecting to the server,
|
117 |
* reloading the necessary data, filling up the content and setting the selected
|
118 |
* values that were selected when the projet was saved.
|
119 |
*
|
120 |
*
|
121 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
122 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
123 |
* no path to the server.
|
124 |
*
|
125 |
*
|
126 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
127 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
128 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
129 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
130 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
131 |
* guarda el proyecto.
|
132 |
*
|
133 |
*
|
134 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
135 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
136 |
* hay conexi?n hasta el servidor.
|
137 |
*
|
138 |
*
|
139 |
* @return WMSParamsPanel
|
140 |
*/
|
141 |
public WMTSGUIInterface getParamsPanel(HashMap<String, Object> info) { |
142 |
if (info == null) { |
143 |
WMTSGUIInterface toc = new WMTSParamsPanel();
|
144 |
return toc;
|
145 |
} |
146 |
|
147 |
try {
|
148 |
if(explorer == null) { |
149 |
explorer = ((FLyrWMTS)fLayer).getExplorer(); |
150 |
|
151 |
try {
|
152 |
explorer.connect(new CancelTaskImpl());
|
153 |
} catch (WMTSException e) {
|
154 |
RasterToolsUtil.messageBoxError("The connection cannot be established", this, e); |
155 |
return null; |
156 |
} |
157 |
} |
158 |
} catch (Exception e) { |
159 |
explorer = null;
|
160 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
161 |
} |
162 |
|
163 |
try {
|
164 |
WMTSGUIInterface toc = new WMTSParamsPanel();
|
165 |
((WMTSParamsPanel)toc).setWizardData(explorer); |
166 |
toc.updateSelectedInfo(info); |
167 |
return toc;
|
168 |
} catch (Exception e) { |
169 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
170 |
} |
171 |
|
172 |
return null; |
173 |
} |
174 |
|
175 |
@SuppressWarnings("unused") |
176 |
private class CommandListener implements ActionListener { |
177 |
|
178 |
/**
|
179 |
* Creates a new ComandosListener object.
|
180 |
*
|
181 |
* @param lg DOCUMENT ME!
|
182 |
*/
|
183 |
public CommandListener(WMTSPropsDialog tp) {
|
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
188 |
*/
|
189 |
public void actionPerformed(ActionEvent e) { |
190 |
if (e.getActionCommand() == "CANCEL") { |
191 |
close(); |
192 |
} else {
|
193 |
MapControl mapCtrl = null;
|
194 |
|
195 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
196 |
for (int i = 0; i < w.length; i++) { |
197 |
if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) { |
198 |
MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext(); |
199 |
if(mapContext == fLayer.getMapContext())
|
200 |
mapCtrl = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl(); |
201 |
} |
202 |
} |
203 |
|
204 |
try {
|
205 |
FLayer[] layerList = wmtsGUIInterface.getLayers();
|
206 |
removeDuplicate(layerList, mapCtrl); |
207 |
for (int i = 0; i < layerList.length; i++) { |
208 |
mapCtrl.getMapContext().getLayers().addLayer(layerList[i]); |
209 |
} |
210 |
mapCtrl.getMapContext().invalidate(); |
211 |
} catch (LoadLayerException exc) {
|
212 |
exc.printStackTrace(); |
213 |
} |
214 |
} |
215 |
} |
216 |
} |
217 |
|
218 |
private void removeDuplicate(FLayer[] layerList, MapControl mapCtrl) { |
219 |
FLayers lyrs = mapCtrl.getMapContext().getLayers(); |
220 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
221 |
FLayer lyr = lyrs.getLayer(i); |
222 |
for (int j = 0; j < layerList.length; j++) { |
223 |
if(lyr.getName().compareTo(layerList[j].getName()) == 0) { |
224 |
lyrs.removeLayer(lyr); |
225 |
} |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
|
231 |
public WindowInfo getWindowInfo() {
|
232 |
if (m_ViewInfo == null) { |
233 |
m_ViewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
234 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMTS_layer")); |
235 |
m_ViewInfo.setWidth(500);
|
236 |
m_ViewInfo.setHeight(500);
|
237 |
} |
238 |
return m_ViewInfo;
|
239 |
} |
240 |
|
241 |
public void close() { |
242 |
PluginServices.getMDIManager().closeWindow(this);
|
243 |
} |
244 |
|
245 |
public Object getWindowProfile() { |
246 |
return WindowInfo.DIALOG_PROFILE;
|
247 |
} |
248 |
|
249 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
250 |
if( e.getButton() == ButtonsPanel.BUTTON_APPLY ||
|
251 |
e.getButton() == ButtonsPanel.BUTTON_ACCEPT) { |
252 |
MapControl mapCtrl = null;
|
253 |
|
254 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
255 |
for (int i = 0; i < w.length; i++) { |
256 |
if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) { |
257 |
MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext(); |
258 |
if(mapContext == fLayer.getMapContext())
|
259 |
mapCtrl = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl(); |
260 |
} |
261 |
} |
262 |
|
263 |
try {
|
264 |
FLayer[] layerList = wmtsGUIInterface.getLayers();
|
265 |
if(layerList.length > 0 && layerList[0] != null) { |
266 |
if(layerList[0] instanceof FLyrWMTS) { |
267 |
mapCtrl.getMapContext().getLayers().removeLayer(fLayer); |
268 |
mapCtrl.getMapContext().getLayers().addLayer(layerList[0]);
|
269 |
fLayer = (FLyrWMTS)layerList[0];
|
270 |
} |
271 |
} |
272 |
//removeDuplicate(layerList, mapCtrl);
|
273 |
mapCtrl.getMapContext().invalidate(); |
274 |
} catch (LoadLayerException exc) {
|
275 |
exc.printStackTrace(); |
276 |
} |
277 |
} |
278 |
|
279 |
if( e.getButton() == ButtonsPanel.BUTTON_CLOSE ||
|
280 |
e.getButton() == ButtonsPanel.BUTTON_ACCEPT) { |
281 |
close(); |
282 |
} |
283 |
} |
284 |
|
285 |
} // @jve:decl-index=0:visual-constraint="10,10"
|