source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java@ 9778

Last change on this file since 9778 was 9682, checked in by wiktorn, 8 years ago

Check if the imagery is valid before returning the info object.

I decided for such solution, as WMTS is the only source, that needs such validation. Alternative approach is to change ImageryPreference.NewEntryAction.actionPerformed(...) so it would instantiate imagery layer using ImageryLayer.create(...) and then call getTileSource(...) on this object, but this would require making this method public.

Closes: #12450

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7
8import javax.swing.JLabel;
9
10import org.openstreetmap.josm.data.imagery.ImageryInfo;
11import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
12import org.openstreetmap.josm.data.imagery.WMTSTileSource;
13import org.openstreetmap.josm.tools.GBC;
14
15/**
16 * Panel for adding WMTS imagery sources
17 * @author Wiktor Niesiobędzki
18 *
19 */
20public class AddWMTSLayerPanel extends AddImageryPanel {
21
22 /**
23 * default constructor
24 */
25 public AddWMTSLayerPanel() {
26 add(new JLabel(tr("1. Enter getCapabilities URL")), GBC.eol());
27 add(rawUrl, GBC.eop().fill());
28 rawUrl.setLineWrap(true);
29 rawUrl.setAlignmentY(TOP_ALIGNMENT);
30 add(new JLabel(tr("2. Enter name for this layer")), GBC.eol());
31 add(name, GBC.eol().fill(GBC.HORIZONTAL));
32 registerValidableComponent(rawUrl);
33 }
34
35 @Override
36 protected ImageryInfo getImageryInfo() {
37 ImageryInfo ret = new ImageryInfo(getImageryName(), "wmts:" + sanitize(getImageryRawUrl(), ImageryType.WMTS));
38 try {
39 new WMTSTileSource(ret); // check if constructor throws an error
40 } catch (IOException e) {
41 throw new IllegalArgumentException(e); // if so, wrap exception, so proper message will be shown to the user
42 }
43 return ret;
44
45 }
46
47 @Override
48 protected boolean isImageryValid() {
49 return !getImageryName().isEmpty() && !getImageryRawUrl().isEmpty();
50 }
51
52}
Note: See TracBrowser for help on using the repository browser.