}
panel.add(new JLabel(tr("WMS URL or Image ID:")), GBC.eol());
panel.add(tfWmsUrl, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
ExtendedDialog diag = new ExtendedDialog(Main.parent,
tr("Add Rectified Image"),
new String[] {tr("Add Rectified Image"), tr("Cancel")});
diag.setContent(panel);
diag.setButtonIcons(new String[] {"OLmarker.png", "cancel.png"});
// This repeatedly shows the dialog in case there has been an error.
// The loop is break;-ed if the users cancels
outer: while(true) {
diag.showDialog();
int answer = diag.getValue();
// Break loop when the user cancels
if(answer != 1) {
break;
}
String text = tfWmsUrl.getText().trim();
// Loop all services until we find the selected one
for(RectifierService s : services) {
if(!s.isSelected()) {
continue;
}
// We've reached the custom WMS URL service
// Just set the URL and hope everything works out
if(s.wmsUrl.isEmpty()) {
addWMSLayer(s.name + " (" + text + ")", text);
break outer;
}
// First try to match if the entered string as an URL
Matcher m = s.urlRegEx.matcher(text);
if(m.find()) {
String id = m.group(1);
String newURL = s.wmsUrl.replaceAll("__s__", id);
String title = s.name + " (" + id + ")";
addWMSLayer(title, newURL);
break outer;
}
// If not, look if it's a valid ID for the selected service
if(s.idValidator.matcher(text).matches()) {
String newURL = s.wmsUrl.replaceAll("__s__", text);
String title = s.name + " (" + text + ")";
addWMSLayer(title, newURL);
break outer;
}
// We've found the selected service, but the entered string isn't suitable for
// it. So quit checking the other radio buttons
break;
}
// and display an error message. The while(true) ensures that the dialog pops up again
JOptionPane.showMessageDialog(Main.parent,
tr("Couldn''t match the entered link or id to the selected service. Please try again."),
tr("No valid WMS URL or id"),
JOptionPane.ERROR_MESSAGE);
diag.setVisible(true);
}
}