001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.preferences.imagery;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.io.IOException;
007
008import javax.swing.JLabel;
009
010import org.openstreetmap.josm.data.imagery.ImageryInfo;
011import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
012import org.openstreetmap.josm.data.imagery.WMTSTileSource;
013import org.openstreetmap.josm.tools.GBC;
014
015/**
016 * Panel for adding WMTS imagery sources
017 * @author Wiktor Niesiobędzki
018 *
019 */
020public class AddWMTSLayerPanel extends AddImageryPanel {
021
022    /**
023     * default constructor
024     */
025    public AddWMTSLayerPanel() {
026        add(new JLabel(tr("1. Enter getCapabilities URL")), GBC.eol());
027        add(rawUrl, GBC.eop().fill());
028        rawUrl.setLineWrap(true);
029        rawUrl.setAlignmentY(TOP_ALIGNMENT);
030        add(new JLabel(tr("2. Enter name for this layer")), GBC.eol());
031        add(name, GBC.eol().fill(GBC.HORIZONTAL));
032        registerValidableComponent(rawUrl);
033    }
034
035    @Override
036    protected ImageryInfo getImageryInfo() {
037        ImageryInfo ret = new ImageryInfo(getImageryName(), "wmts:" + sanitize(getImageryRawUrl(), ImageryType.WMTS));
038        ret.setImageryType(ImageryType.WMTS);
039        try {
040            new WMTSTileSource(ret); // check if constructor throws an error
041        } catch (IOException e) {
042            throw new IllegalArgumentException(e); // if so, wrap exception, so proper message will be shown to the user
043        }
044        return ret;
045
046    }
047
048    @Override
049    protected boolean isImageryValid() {
050        return !getImageryName().isEmpty() && !getImageryRawUrl().isEmpty();
051    }
052
053}