- Timestamp:
- 2014-01-03T02:17:12+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
r6340 r6602 30 30 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 31 31 import org.openstreetmap.josm.gui.oauth.TestAccessTokenTask; 32 import org.openstreetmap.josm.io.OsmApi; 32 33 import org.openstreetmap.josm.io.auth.CredentialsManager; 33 34 import org.openstreetmap.josm.tools.ImageProvider; … … 160 161 */ 161 162 public void initFromPreferences() { 163 setApiUrl(Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL).trim()); 162 164 refreshView(); 163 165 } -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java
r6582 r6602 34 34 import org.openstreetmap.josm.io.OsmApi; 35 35 import org.openstreetmap.josm.tools.ImageProvider; 36 import org.openstreetmap.josm.tools.Utils; 36 37 37 38 /** … … 52 53 /** indicates whether to use the default OSM URL or not */ 53 54 private JCheckBox cbUseDefaultServerUrl; 54 55 protected JPanel buildDefultServerUrlPanel() { 55 56 private ApiUrlPropagator propagator; 57 58 protected JPanel buildDefaultServerUrlPanel() { 56 59 JPanel pnl = new JPanel(new GridBagLayout()); 57 60 GridBagConstraints gc = new GridBagConstraints(); … … 84 87 gc.insets = new Insets(0,0,0,0); 85 88 gc.gridwidth = 4; 86 add(buildDef ultServerUrlPanel(), gc);89 add(buildDefaultServerUrlPanel(), gc); 87 90 88 91 … … 101 104 valOsmServerUrl = new ApiUrlValidator(tfOsmServerUrl); 102 105 valOsmServerUrl.validate(); 103 ApiUrlPropagatorpropagator = new ApiUrlPropagator();106 propagator = new ApiUrlPropagator(); 104 107 tfOsmServerUrl.addActionListener(propagator); 105 108 tfOsmServerUrl.addFocusListener(propagator); … … 131 134 if (url.trim().equals(OsmApi.DEFAULT_API_URL)) { 132 135 cbUseDefaultServerUrl.setSelected(true); 133 firePropertyChange(API_URL_PROP, null,OsmApi.DEFAULT_API_URL);136 propagator.propagate(OsmApi.DEFAULT_API_URL); 134 137 } else { 135 138 cbUseDefaultServerUrl.setSelected(false); 136 139 tfOsmServerUrl.setText(url); 137 firePropertyChange(API_URL_PROP, null,url);140 propagator.propagate(url); 138 141 } 139 142 } … … 143 146 */ 144 147 public void saveToPreferences() { 145 String old_url = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL); 148 String oldUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL); 149 String hmiUrl = getStrippedApiUrl(); 146 150 if (cbUseDefaultServerUrl.isSelected()) { 147 151 Main.pref.put("osm-server.url", null); 148 } else if ( tfOsmServerUrl.getText().trim().equals(OsmApi.DEFAULT_API_URL)) {152 } else if (hmiUrl.equals(OsmApi.DEFAULT_API_URL)) { 149 153 Main.pref.put("osm-server.url", null); 150 154 } else { 151 Main.pref.put("osm-server.url", tfOsmServerUrl.getText().trim());152 } 153 String new _url = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL);155 Main.pref.put("osm-server.url", hmiUrl); 156 } 157 String newUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL); 154 158 155 159 // When API URL changes, re-initialize API connection so we may adjust 156 160 // server-dependent settings. 157 if (!old _url.equals(new_url)) {161 if (!oldUrl.equals(newUrl)) { 158 162 try { 159 163 OsmApi.getOsmApi().initialize(null); … … 163 167 } 164 168 } 169 170 /** 171 * Returns the entered API URL, stripped of leading and trailing white characters. 172 * @return the entered API URL, stripped of leading and trailing white characters. 173 * May be an empty string if nothing has been entered. In this case, it means the user wants to use {@link OsmApi#DEFAULT_API_URL}. 174 * @see Utils#strip(String) 175 * @since 6602 176 */ 177 public final String getStrippedApiUrl() { 178 return Utils.strip(tfOsmServerUrl.getText()); 179 } 165 180 166 181 class ValidateApiUrlAction extends AbstractAction implements DocumentListener { … … 175 190 @Override 176 191 public void actionPerformed(ActionEvent arg0) { 177 final String url = tfOsmServerUrl.getText().trim();192 final String url = getStrippedApiUrl(); 178 193 final ApiUrlTestTask task = new ApiUrlTestTask(OsmApiUrlInputPanel.this, url); 179 194 Main.worker.submit(task); … … 204 219 205 220 protected void updateEnabledState() { 206 boolean enabled = 207 !tfOsmServerUrl.getText().trim().isEmpty() 208 && !tfOsmServerUrl.getText().trim().equals(lastTestedUrl); 221 String url = getStrippedApiUrl(); 222 boolean enabled = !url.isEmpty() && !url.equals(lastTestedUrl); 209 223 if (enabled) { 210 224 lblValid.setIcon(null); … … 281 295 case ItemEvent.SELECTED: 282 296 setApiUrlInputEnabled(false); 283 firePropertyChange(API_URL_PROP, null,OsmApi.DEFAULT_API_URL);297 propagator.propagate(OsmApi.DEFAULT_API_URL); 284 298 break; 285 299 case ItemEvent.DESELECTED: … … 287 301 valOsmServerUrl.validate(); 288 302 tfOsmServerUrl.requestFocusInWindow(); 289 firePropertyChange(API_URL_PROP, null, tfOsmServerUrl.getText());303 propagator.propagate(); 290 304 break; 291 305 } … … 295 309 class ApiUrlPropagator extends FocusAdapter implements ActionListener { 296 310 public void propagate() { 297 firePropertyChange(API_URL_PROP, null, tfOsmServerUrl.getText()); 311 propagate(getStrippedApiUrl()); 312 } 313 314 public void propagate(String url) { 315 firePropertyChange(API_URL_PROP, null, url); 298 316 } 299 317
Note:
See TracChangeset
for help on using the changeset viewer.