1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.imagery;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
11 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
12 | import org.openstreetmap.josm.data.imagery.WMTSTileSource;
|
---|
13 | import org.openstreetmap.josm.tools.GBC;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Panel for adding WMTS imagery sources
|
---|
17 | * @author Wiktor Niesiobędzki
|
---|
18 | *
|
---|
19 | */
|
---|
20 | public 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 | ret.setImageryType(ImageryType.WMTS);
|
---|
39 | try {
|
---|
40 | new WMTSTileSource(ret); // check if constructor throws an error
|
---|
41 | } catch (IOException e) {
|
---|
42 | throw new IllegalArgumentException(e); // if so, wrap exception, so proper message will be shown to the user
|
---|
43 | }
|
---|
44 | return ret;
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | protected boolean isImageryValid() {
|
---|
50 | return !getImageryName().isEmpty() && !getImageryRawUrl().isEmpty();
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|