svn-gvsig-desktop / tmp / trunk / cliente / WorkSpace_WPSClient / extWPSCallejero / src / es / logex / gvsig / streetsmap / ui / PanelConnectionWPS.java @ 26601
History | View | Annotate | Download (13.4 KB)
1 |
package es.logex.gvsig.streetsmap.ui; |
---|---|
2 |
|
3 |
|
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.awt.Insets; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
|
10 |
import java.net.MalformedURLException; |
11 |
import java.net.URL; |
12 |
import java.util.ArrayList; |
13 |
import java.util.List; |
14 |
|
15 |
|
16 |
import javax.swing.BorderFactory; |
17 |
|
18 |
import javax.swing.DefaultComboBoxModel; |
19 |
import javax.swing.ImageIcon; |
20 |
import javax.swing.JButton; |
21 |
|
22 |
import javax.swing.JEditorPane; |
23 |
import javax.swing.JOptionPane; |
24 |
|
25 |
import javax.swing.WindowConstants; |
26 |
import javax.swing.border.LineBorder; |
27 |
import javax.swing.border.TitledBorder; |
28 |
import javax.swing.JFrame; |
29 |
import javax.swing.JLabel; |
30 |
import javax.swing.JPanel; |
31 |
|
32 |
import javax.swing.SwingConstants; |
33 |
|
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.andami.persistence.serverData.ServerDataPersistence; |
36 |
import com.iver.utiles.NotExistInXMLEntity; |
37 |
import com.iver.utiles.XMLEntity; |
38 |
import com.iver.utiles.swing.jcomboServer.JComboServer; |
39 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
40 |
|
41 |
import es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedListener; |
42 |
import es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedProducer; |
43 |
import es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedEvent; |
44 |
import es.logex.gvsig.wps.client.WPSClient; |
45 |
import es.logex.gvsig.wps.client.WPSProtocolHandler; |
46 |
|
47 |
/**
|
48 |
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI Builder, which is free for non-commercial use. If Jigloo is being used commercially (ie, by a corporation, company or business for any purpose whatever) then you should purchase a license for each developer using Jigloo. Please visit www.cloudgarden.com for details. Use of Jigloo implies acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
|
49 |
* @uml.dependency supplier="es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedEvent"
|
50 |
* @uml.dependency supplier="javax.swing.JPanel"
|
51 |
* @uml.dependency supplier="es.logex.gvsig.wps.client.WPSClient"
|
52 |
* @uml.dependency supplier="es.logex.gvsig.streetsmap.ui.events.ConnectionSucceedListener"
|
53 |
*/
|
54 |
public class PanelConnectionWPS extends javax.swing.JPanel implements ConnectionSucceedProducer { |
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = -7765843934771343314L; |
59 |
private JPanel panelConnectionCombo; |
60 |
private JPanel panelServerAbstract; |
61 |
private JButton btnConnect; |
62 |
private JComboServer cmbHost;
|
63 |
private JPanel panelHeader; |
64 |
private javax.swing.JEditorPane txtAbstract;
|
65 |
private JLabel lblIconSearch; |
66 |
private JLabel lblBuscar; |
67 |
private JPanel jPanel2; |
68 |
private List<ConnectionSucceedListener> connectRequestsListeners = new ArrayList<ConnectionSucceedListener>(); |
69 |
|
70 |
private final String bgColor0 = "\"#FEEDD6\""; // light salmon |
71 |
private final String bgColor1 = "\"#EAEAEA\""; // light grey |
72 |
|
73 |
private final String bgColor3 = "\"#FBFFE1\""; // light yellow |
74 |
private final String service_title = PluginServices.getText(this, "service_info"); |
75 |
private final String server = PluginServices.getText(this, "server"); |
76 |
private final String server_type = PluginServices.getText(this, "server_type"); |
77 |
private final String server_abstract = PluginServices.getText(this, "server_abstract"); |
78 |
private final String server_title = PluginServices.getText(this, "server_title"); |
79 |
/**
|
80 |
* Auto-generated main method to display this JPanel inside a new JFrame.
|
81 |
*/
|
82 |
public static void main(String[] args) { |
83 |
JFrame frame = new JFrame(); |
84 |
frame.getContentPane().add(new PanelConnectionWPS());
|
85 |
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
86 |
frame.pack(); |
87 |
frame.setVisible(true);
|
88 |
} |
89 |
|
90 |
public PanelConnectionWPS() {
|
91 |
super();
|
92 |
initGUI(); |
93 |
} |
94 |
|
95 |
private void initGUI() { |
96 |
try {
|
97 |
GridBagLayout thisLayout = new GridBagLayout(); |
98 |
this.setPreferredSize(new java.awt.Dimension(490, 300)); |
99 |
thisLayout.rowWeights = new double[] {0.0, 0.1, 0.1, 0.8, 0.0}; |
100 |
thisLayout.rowHeights = new int[] {7, 7, 7, 7, 7}; |
101 |
thisLayout.columnWeights = new double[] {0.0, 0.1, 0.0}; |
102 |
thisLayout.columnWidths = new int[] {7, 7, 7}; |
103 |
this.setLayout(thisLayout);
|
104 |
{ |
105 |
panelConnectionCombo = new JPanel(); |
106 |
GridBagLayout panelConnectionComboLayout = new GridBagLayout(); |
107 |
panelConnectionComboLayout.columnWidths = new int[] {7, 7}; |
108 |
panelConnectionComboLayout.rowHeights = new int[] {7}; |
109 |
panelConnectionComboLayout.columnWeights = new double[] {0.95, 0.1}; |
110 |
panelConnectionComboLayout.rowWeights = new double[] {0.1}; |
111 |
this.add(panelConnectionCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
112 |
panelConnectionCombo.setLayout(panelConnectionComboLayout); |
113 |
{ |
114 |
btnConnect = new JButton(); |
115 |
panelConnectionCombo.add(btnConnect, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0)); |
116 |
btnConnect.setText("Conectar");
|
117 |
btnConnect.addActionListener(new ActionListener() { |
118 |
public void actionPerformed(ActionEvent evt) { |
119 |
|
120 |
btnConnectActionPerformed(evt); |
121 |
} |
122 |
}); |
123 |
} |
124 |
{ |
125 |
|
126 |
cmbHost = new JComboServer();
|
127 |
cmbHost.setModel(new DefaultComboBoxModel()); |
128 |
cmbHost.setPreferredSize(new java.awt.Dimension(350, 20)); |
129 |
cmbHost.setBounds(11, 26, 454, 20); |
130 |
cmbHost.setEditable(true);
|
131 |
|
132 |
ServerDataPersistence persistence = new ServerDataPersistence(this,"WPS"); |
133 |
ServerData[] servers = persistence.getArrayOfServerData();
|
134 |
|
135 |
if (servers.length == 0){ |
136 |
PluginServices ps = PluginServices.getPluginServices(this);
|
137 |
XMLEntity xml = ps.getPersistentXML(); |
138 |
try {
|
139 |
String[] oldServers = xml.getStringArrayProperty("wps-servers"); |
140 |
servers = new ServerData[oldServers.length];
|
141 |
for (int i=0; i<oldServers.length; i++) { |
142 |
servers[i] = new ServerData(oldServers[i],"WPS"); |
143 |
} |
144 |
xml.remove("wps-servers");
|
145 |
ps.setPersistentXML(xml); |
146 |
} catch (NotExistInXMLEntity e) {
|
147 |
// Old servers doesn't exist
|
148 |
servers = new ServerData[1]; |
149 |
servers[0] = new ServerData("http://logexvirt2:9980/wps_ws_spring/StreetsMap/service.wps","WPS"); |
150 |
|
151 |
} |
152 |
|
153 |
for (int i=0 ; i<servers.length ; i++){ |
154 |
persistence.addServerData(servers[i]); |
155 |
} |
156 |
persistence.setPersistent(); |
157 |
} |
158 |
|
159 |
cmbHost.setServerList(servers); |
160 |
|
161 |
panelConnectionCombo.add(cmbHost, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
162 |
|
163 |
cmbHost.setEditable(true);
|
164 |
} |
165 |
} |
166 |
{ |
167 |
panelServerAbstract = new JPanel(); |
168 |
GridBagLayout panelServerAbstractLayout = new GridBagLayout(); |
169 |
panelServerAbstractLayout.columnWidths = new int[] {7}; |
170 |
panelServerAbstractLayout.rowHeights = new int[] {7}; |
171 |
panelServerAbstractLayout.columnWeights = new double[] {0.1}; |
172 |
panelServerAbstractLayout.rowWeights = new double[] {0.1}; |
173 |
this.add(panelServerAbstract, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
174 |
panelServerAbstract.setLayout(panelServerAbstractLayout); |
175 |
{ |
176 |
txtAbstract = new JEditorPane(); |
177 |
txtAbstract.setEditable(false);
|
178 |
panelServerAbstract.add(txtAbstract, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
179 |
txtAbstract.setBorder(BorderFactory.createTitledBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false), "Información servidor", TitledBorder.LEADING, TitledBorder.TOP)); |
180 |
txtAbstract.setEditable(false);
|
181 |
} |
182 |
} |
183 |
{ |
184 |
panelHeader = new JPanel(); |
185 |
|
186 |
this.add(panelHeader, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
187 |
GridBagLayout jPanel1Layout = new GridBagLayout(); |
188 |
jPanel1Layout.columnWidths = new int[] {7, 20}; |
189 |
jPanel1Layout.rowHeights = new int[] {7}; |
190 |
jPanel1Layout.columnWeights = new double[] {0.1, 0.1}; |
191 |
jPanel1Layout.rowWeights = new double[] {0.1}; |
192 |
panelHeader.setLayout(jPanel1Layout); |
193 |
panelHeader.setName("panelHeader");
|
194 |
{ |
195 |
jPanel2 = new JPanel(); |
196 |
panelHeader.add(jPanel2, new GridBagConstraints(-1, -2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
197 |
{ |
198 |
lblBuscar = new JLabel(); |
199 |
jPanel2.add(lblBuscar); |
200 |
lblBuscar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("es/logex/gvsig/streetsmap/ui/callejero50.gif"))); |
201 |
lblBuscar.setText("Callejeros WPS - Conexión");
|
202 |
lblBuscar.setHorizontalAlignment(SwingConstants.LEFT);
|
203 |
lblBuscar.setBackground(new java.awt.Color(255,165,0)); |
204 |
lblBuscar.setFont(new java.awt.Font("Dialog",1,16)); |
205 |
lblBuscar.setPreferredSize(new java.awt.Dimension(294,43)); |
206 |
lblBuscar.setOpaque(false);
|
207 |
} |
208 |
} |
209 |
{ |
210 |
lblIconSearch = new JLabel(); |
211 |
panelHeader.add(lblIconSearch, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); |
212 |
lblIconSearch.setIcon(new ImageIcon(getClass().getClassLoader().getResource("es/logex/gvsig/streetsmap/ui/search.gif"))); |
213 |
} |
214 |
} |
215 |
} catch (Exception e) { |
216 |
e.printStackTrace(); |
217 |
} |
218 |
} |
219 |
|
220 |
private void btnConnectActionPerformed(ActionEvent evt) { |
221 |
System.out.println("btnConnect.actionPerformed, event="+evt); |
222 |
try {
|
223 |
|
224 |
URL url = new URL((String)cmbHost.getModel().getSelectedItem().toString()); |
225 |
fireConnectRequest(url); |
226 |
} catch (MalformedURLException e) { |
227 |
JOptionPane.showMessageDialog(this, "Direccion_URL_Incorrecta", "Titulo_direccion_url_incorrecta", JOptionPane.CANCEL_OPTION); |
228 |
} |
229 |
} |
230 |
|
231 |
public void addConnectSucceedListener( |
232 |
ConnectionSucceedListener connectRequestListener) { |
233 |
connectRequestsListeners.add(connectRequestListener); |
234 |
|
235 |
} |
236 |
public void removeConnectSucceedListener( |
237 |
ConnectionSucceedListener connectRequestListener) { |
238 |
connectRequestsListeners.remove(connectRequestListener); |
239 |
|
240 |
} |
241 |
|
242 |
private void fireConnectRequest(URL url) |
243 |
{ |
244 |
WPSClient wpsClient = new WPSClient(url.toString());
|
245 |
try {
|
246 |
if(wpsClient.connect())
|
247 |
{ |
248 |
this.txtAbstract.setContentType("text/html"); |
249 |
this.txtAbstract.setText(formatWpsInfo(wpsClient.getWPSProtocolHandler()));
|
250 |
|
251 |
|
252 |
// Avisar a los clientes de que ha habido una conexion
|
253 |
ConnectionSucceedEvent connRequest = new ConnectionSucceedEvent(this,url,wpsClient); |
254 |
for(ConnectionSucceedListener connListener : connectRequestsListeners)
|
255 |
{ |
256 |
connListener.connectionSucceed(connRequest); |
257 |
} |
258 |
|
259 |
|
260 |
ServerDataPersistence persistence = new ServerDataPersistence(this,"WPS"); |
261 |
persistence.addServerData(new ServerData(url.toString(), "WPS")); |
262 |
} |
263 |
else
|
264 |
{ |
265 |
// No se ha podido abrir la conexion, recuperar los errores si los hubiese
|
266 |
// Y mostrarlos
|
267 |
String errorString = ""; |
268 |
String error = ""; |
269 |
|
270 |
while( wpsClient.getErrorsStack().isEmpty()== false) |
271 |
{ |
272 |
error = wpsClient.getErrorsStack().pop(); |
273 |
errorString = errorString.concat(error).concat(System.getProperty("line.separator")); |
274 |
} |
275 |
|
276 |
this.txtAbstract.setText(errorString);
|
277 |
} |
278 |
} catch (RuntimeException e) { |
279 |
e.printStackTrace(); |
280 |
} |
281 |
} |
282 |
|
283 |
private String formatWpsInfo(WPSProtocolHandler protocolHandler) { |
284 |
String font = "Arial"; |
285 |
String html =
|
286 |
"<html>" +
|
287 |
"<body>" +
|
288 |
"<table align=\"center\" width=\"437\" height=\"156\" border=\"0\" cellpadding=\"4\" cellspacing=\"4\">" +
|
289 |
" <tr valign=\"top\" bgcolor=\"#FFFFFF\">" +
|
290 |
" <td width=\"92\" height=\"18\" bgcolor="+bgColor3+" colspan=\"2\"><font face=\""+font+"\" size=\"4\"><b>"+service_title+"</font></b></td>" + |
291 |
" </tr>" +
|
292 |
" <tr valign=\"top\" bgcolor="+bgColor0+">" + |
293 |
" <td width=\"92\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""+font+"\" size=\"3\"><b>"+server+"</font></b></td>" + |
294 |
" <td width=\"268\"><font face=\""+font+"\" size=\"3\">"+protocolHandler.getHost()+"</font></td>" + |
295 |
" </tr>" +
|
296 |
" <tr valign=\"top\" bgcolor="+bgColor1+">" + |
297 |
" <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""+font+"\" size=\"3\"><b>"+server_type+"</b></font></td>" + |
298 |
" <td><font face=\""+font+"\" size=\"3\">"+ protocolHandler.getDiscoveryConnector().getServiceName() +"</font></td>" + |
299 |
" </tr>" +
|
300 |
" <tr valign=\"top\" bgcolor="+bgColor0+">" + |
301 |
" <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""+font+"\" size=\"3\"><b>"+server_title+"</b></font></td>" + |
302 |
" <td><font face=\""+font+"\" size=\"3\"><font face=\""+font+"\" size=\"3\">"+protocolHandler.getServiceIdentification().getOwsAbstract()+"</font></td>" + |
303 |
" </tr>" +
|
304 |
" <tr valign=\"top\" bgcolor="+bgColor1+">" + |
305 |
" <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""+font+"\" size=\"3\"><b>"+server_abstract+"</font></b></td>" + |
306 |
" <td><font face=\""+font+"\" size=\"3\">"+ protocolHandler.getServiceIdentification().getTitle() +"</font></td>" + |
307 |
" </tr>" +
|
308 |
|
309 |
" <tr>" +
|
310 |
" </tr>" +
|
311 |
"</table>" +
|
312 |
"</body>" +
|
313 |
"</html>";
|
314 |
return html;
|
315 |
} |
316 |
|
317 |
public void setAbstract(String abstractString) |
318 |
{ |
319 |
this.txtAbstract.setText(abstractString);
|
320 |
} |
321 |
|
322 |
|
323 |
} |