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("{0} Make sure OSM has the permission to use this service", "1.")), GBC.eol()); 027 add(new JLabel(tr("{0} Enter GetCapabilities URL", "2.")), GBC.eol()); 028 add(rawUrl, GBC.eop().fill()); 029 rawUrl.setLineWrap(true); 030 rawUrl.setAlignmentY(TOP_ALIGNMENT); 031 add(new JLabel(tr("{0} Enter name for this layer", "3.")), GBC.eol()); 032 add(name, GBC.eol().fill(GBC.HORIZONTAL)); 033 registerValidableComponent(rawUrl); 034 } 035 036 @Override 037 protected ImageryInfo getImageryInfo() { 038 ImageryInfo ret = new ImageryInfo(getImageryName(), "wmts:" + sanitize(getImageryRawUrl(), ImageryType.WMTS)); 039 ret.setImageryType(ImageryType.WMTS); 040 try { 041 new WMTSTileSource(ret); // check if constructor throws an error 042 } catch (IOException e) { 043 throw new IllegalArgumentException(e); // if so, wrap exception, so proper message will be shown to the user 044 } 045 return ret; 046 047 } 048 049 @Override 050 protected boolean isImageryValid() { 051 return !getImageryName().isEmpty() && !getImageryRawUrl().isEmpty(); 052 } 053 054}