JOptionPane.YES_NO_CANCEL_OPTION);
if (i == JOptionPane.YES_OPTION) {
if (original == null) {
original = new CapaInformacion();
}
original.setInfoAdicional(textfieldPie
.getText());
original.setNombre(textfieldCabecera
.getText());
original.setHabilitada(habilitado
.isSelected());
original.setOpcional(comboTipoCapa
.getSelectedIndex() != 0);
boolean transparente = true;
HashSet<Capa> capas = new HashSet<Capa>();
List<Capa> capasEnOrdenSeleccionado = new ArrayList<Capa>();
int indice = 0;
for (Object c : ((DefaultListModel) right
.getModel()).toArray()) {
if (c instanceof Capa) {
transparente = transparente
&& (transparentes != null
&& transparentes
.get(((Capa) c)
.getNombre()) != null && transparentes
.get(((Capa) c)
.getNombre()));
capas.add((Capa) c);
capasEnOrdenSeleccionado
.add((Capa) c);
((Capa) c)
.setCapaInformacion(original);
((Capa) c).setOrden(indice++);
// ((Capa)
// c).setNombre(c.toString());
}
}
original.setCapas(capas);
if (original.getId() == null) {
String url = nombre.getText();
if (url.indexOf("?") > -1) {
if (!url.endsWith("?")) {
url += "&";
}
} else {
url += "?";
}
url += "VERSION="
+ version
+ "&REQUEST=GetMap&FORMAT="
+ png
+ "&SERVICE="
+ service
+ "&WIDTH={2}&HEIGHT={3}&BBOX={1}&SRS={0}";
// if (transparente)
url += "&TRANSPARENT=TRUE";
url += "&LAYERS=";
String estilos = "";
final String coma = "%2C";
if (capasEnOrdenSeleccionado.size() > 0) {
for (Capa c : capasEnOrdenSeleccionado) {
url += c.getTitulo()
.replaceAll(" ", "+")
+ coma;
estilos += c.getEstilo() + coma;
}
estilos = estilos.substring(
0,
estilos.length()
- coma.length());
estilos = estilos.replaceAll(" ",
"+");
url = url.substring(0, url.length()
- coma.length());
}
url += "&STYLES=" + estilos;
original.setUrl_visible(original
.getUrl());
original.setUrl(url);
}
CapaInformacionAdmin.saveOrUpdate(original);
cambios = false;
layers.setTableData(getAll(new CapaInformacion()));
closeFrame();
} else if (i == JOptionPane.NO_OPTION) {
closeFrame();
}
} else {
closeFrame();
}
}
};
JFrame segunda = generateUrlDialog(label_cabecera,
label_pie, centered_label, tituloVentana,
left_items, right_items, left_label, right_label,
guardar,
LogicConstants.getIcon("tittleficha_icon_capa"),
cabecera, c.getHabilitada(), c.getOpcional(),
c.getUrl_visible());
segunda.setResizable(false);
if (c != null) {
textfieldCabecera.setText(c.getNombre());
textfieldPie.setText(c.getInfoAdicional());
nombre.setText(c.getUrl_visible());
nombre.setEditable(false);
if (c.getHabilitada() == null) {
c.setHabilitada(false);
}
habilitado.setSelected(c.getHabilitada());
if (c.isOpcional() != null && c.isOpcional()) {
comboTipoCapa.setSelectedIndex(1);
} else {
comboTipoCapa.setSelectedIndex(0);
}
}
if (c.getId() == null) {
habilitado.setSelected(true);
comboTipoCapa.setSelectedIndex(1);
}
habilitado.setEnabled(true);
if (c == null || c.getId() == null) {
textfieldCabecera.setEditable(true);
} else {
textfieldCabecera.setEditable(false);
}
cambios = false;
segunda.pack();
segunda.setLocationRelativeTo(null);
segunda.setVisible(true);
return segunda;
}
return null;
}
class SiguienteActionListener implements ActionListener {
private final JTextField url;
private final JDialog dialog;
private final JLabel icono;
private final JButton siguiente;
public SiguienteActionListener(JTextField url, JDialog dialog,
JLabel icono, JButton siguiente) {
this.url = url;
this.dialog = dialog;
this.icono = icono;
this.siguiente = siguiente;
}
@Override
public void actionPerformed(ActionEvent e) {
final CapaInformacion ci = new CapaInformacion();
ci.setUrl(url.getText());
ci.setCapas(new HashSet<Capa>());
SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
private List<Capa> res = new LinkedList<Capa>();
private String service = "WMS";
private String png = null;
private Map<String, Boolean> transparentes = new HashMap<String, Boolean>();
private ArrayList<String> errorStack = new ArrayList<String>();
private Boolean goOn = true;
@SuppressWarnings(value = "unchecked")
@Override
protected Object doInBackground() throws Exception {
try {
final String url2 = ci.getUrl();
WMSClient client = new WMSClient(url2);
client.connect(new ICancellable() {
@Override
public boolean isCanceled() {
return false;
}
@Override
public Object getID() {
return System.currentTimeMillis();
}
});
version = client.getVersion();
for (final String s : client.getLayerNames()) {
WMSLayer layer = client.getLayer(s);
// this.service =
// client.getServiceName();
final Vector allSrs = layer.getAllSrs();
boolean epsg = (allSrs != null) ? allSrs
.contains("EPSG:4326") : false;
final Vector formats = client.getFormats();
if (formats.contains("image/png")) {
png = "image/png";
} else if (formats.contains("IMAGE/PNG")) {
png = "IMAGE/PNG";
} else if (formats.contains("png")) {
png = "png";
} else if (formats.contains("PNG")) {
png = "PNG";
}
boolean image = png != null;
if (png == null) {
png = "IMAGE/PNG";
}
if (epsg && image) {
boolean hasTransparency = layer
.hasTransparency();
this.transparentes.put(s,
hasTransparency);
Capa capa = new Capa();
capa.setCapaInformacion(ci);
if (layer.getStyles().size() > 0) {
capa.setEstilo(((WMSStyle) layer
.getStyles().get(0))
.getName());
}
capa.setNombre(layer.getTitle());
capa.setTitulo(s);
res.add(capa);
if (!hasTransparency) {
errorStack
.add(i18n
.getString(
Locale.ROOT,
"admin.capas.nueva.error.capaNoTransparente",
layer.getTitle()));
}
} else {
String error = "";
// if (opaque)
// error += "<li>Es opaca</li>";
if (!image) {
error += i18n
.getString("admin.capas.nueva.error.formatoPNG");
}
if (!epsg) {
error += i18n
.getString("admin.capas.nueva.error.projeccion");
}
final String cadena = i18n
.getString(
Locale.ROOT,
"admin.capas.nueva.error.errorCapa",
new Object[] { s, error });
errorStack.add(cadena);
}
}
} catch (final Throwable t) {
log.error("Error al parsear el WMS", t);
goOn = false;
icono.setIcon(LogicConstants
.getIcon("48x48_transparente"));
JOptionPane
.showMessageDialog(
dialog,
i18n.getString("admin.capas.nueva.error.errorParseoWMS"));
siguiente.setEnabled(true);
}
return null;
}
@Override
protected void done() {
super.done();
if (goOn) {
dialog.dispose();
ci.setUrl_visible(ci.getUrl());
final JFrame frame = getDialog(ci,
res.toArray(new Capa[0]), service,
transparentes, png);
if (!errorStack.isEmpty()) {
String error = "<html>";