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        try {
039            new WMTSTileSource(ret); // check if constructor throws an error
040        } catch (IOException e) {
041            throw new IllegalArgumentException(e); // if so, wrap exception, so proper message will be shown to the user
042        }
043        return ret;
044
045    }
046
047    @Override
048    protected boolean isImageryValid() {
049        return !getImageryName().isEmpty() && !getImageryRawUrl().isEmpty();
050    }
051
052}