+ /**
+ * Init the dialog fields from the given source object
+ */
+ private void populateFields()
+ {
+ if (_originalSource == null)
+ {
+ clearAllFields();
+ return;
+ }
+ boolean sourceFound = false;
+ // See if it's a cloudmade source
+ try
+ {
+ CloudmadeMapSource cloudSource = (CloudmadeMapSource) _originalSource;
+ sourceFound = true;
+ _cNameField.setText(cloudSource.getName());
+ _cStyleField.setText(cloudSource.getStyle());
+ _cZoomCombo.setSelectedIndex(getZoomIndex(cloudSource.getMaxZoomLevel()));
+ _sourceTypeRadios[1].setSelected(true);
+ }
+ catch (ClassCastException cce) {} // ignore, sourceFound flag stays false
+
+ // See if it's an osm source
+ if (!sourceFound)
+ {
+ try
+ {
+ OsmMapSource osmSource = (OsmMapSource) _originalSource;
+ sourceFound = true;
+ _oNameField.setText(osmSource.getName());
+ _baseUrlField.setText(osmSource.getBaseUrl(0));
+ int baseType = getBaseType(osmSource.getFileExtension(0));
+ _baseTypeRadios[baseType].setSelected(true);
+ _topUrlField.setText(osmSource.getNumLayers()==0?"":osmSource.getBaseUrl(1));
+ int topType = getBaseType(osmSource.getFileExtension(1));
+ _topTypeRadios[topType].setSelected(true);
+ _oZoomCombo.setSelectedIndex(getZoomIndex(osmSource.getMaxZoomLevel()));
+ _sourceTypeRadios[0].setSelected(true);
+ }
+ catch (ClassCastException cce) {} // ignore, sourceFound flag stays false
+ }
+ for (int i=0; i<2; i++) {
+ _sourceTypeRadios[i].setEnabled(false);
+ }
+ onRadioClicked();
+ _okButton.setEnabled(false);
+ _addDialog.setVisible(true);
+ }
+
+
+ /**
+ * React to one of the type radio buttons being clicked
+ */
+ private void onRadioClicked()
+ {
+ CardLayout cl = (CardLayout) _cards.getLayout();
+ if (_sourceTypeRadios[0].isSelected()) {cl.first(_cards);}
+ else {cl.last(_cards);}
+ enableOK();
+ }