source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddTMSLayerPanel.java@ 11308

Last change on this file since 11308 was 11308, checked in by Don-vip, 7 years ago

fix #14031 - change focus with TAB in "add imagery" dialogs

  • Property svn:eol-style set to native
File size: 3.4 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.awt.event.KeyAdapter;
7import java.awt.event.KeyEvent;
8import java.util.Arrays;
9
10import javax.swing.JLabel;
11
12import org.openstreetmap.josm.data.imagery.ImageryInfo;
13import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
14import org.openstreetmap.josm.gui.widgets.JosmTextArea;
15import org.openstreetmap.josm.gui.widgets.JosmTextField;
16import org.openstreetmap.josm.tools.GBC;
17import org.openstreetmap.josm.tools.Utils;
18
19/**
20 * An imagery panel used to add TMS imagery sources
21 */
22public class AddTMSLayerPanel extends AddImageryPanel {
23
24 private final JosmTextField tmsZoom = new JosmTextField();
25 private final JosmTextArea tmsUrl = new JosmTextArea(3, 40).transferFocusOnTab();
26 private final transient KeyAdapter keyAdapter = new KeyAdapter() {
27 @Override
28 public void keyReleased(KeyEvent e) {
29 tmsUrl.setText(buildTMSUrl());
30 }
31 };
32
33 /**
34 * Constructs a new {@code AddTMSLayerPanel}.
35 */
36 public AddTMSLayerPanel() {
37
38 add(new JLabel(tr("1. Enter URL")), GBC.eol());
39 add(new JLabel("<html>" + Utils.joinAsHtmlUnorderedList(Arrays.asList(
40 tr("{0} is replaced by tile zoom level, also supported:<br>" +
41 "offsets to the zoom level: {1} or {2}<br>" +
42 "reversed zoom level: {3}", "{zoom}", "{zoom+1}", "{zoom-1}", "{19-zoom}"),
43 tr("{0} is replaced by X-coordinate of the tile", "{x}"),
44 tr("{0} is replaced by Y-coordinate of the tile", "{y}"),
45 tr("{0} is replaced by {1} (Yahoo style Y coordinate)", "{!y}", "2<sup>zoom–1</sup> – 1 – Y"),
46 tr("{0} is replaced by {1} (OSGeo Tile Map Service Specification style Y coordinate)", "{-y}", "2<sup>zoom</sup> – 1 – Y"),
47 tr("{0} is replaced by a random selection from the given comma separated list, e.g. {1}", "{switch:...}", "{switch:a,b,c}")
48 )) + "</html>"), GBC.eol().fill());
49
50 add(rawUrl, GBC.eop().fill());
51 rawUrl.setLineWrap(true);
52 rawUrl.addKeyListener(keyAdapter);
53
54 add(new JLabel(tr("2. Enter maximum zoom (optional)")), GBC.eol());
55 tmsZoom.addKeyListener(keyAdapter);
56 add(tmsZoom, GBC.eop().fill());
57
58 add(new JLabel(tr("3. Verify generated TMS URL")), GBC.eol());
59 add(tmsUrl, GBC.eop().fill());
60 tmsUrl.setLineWrap(true);
61
62 add(new JLabel(tr("4. Enter name for this layer")), GBC.eol());
63 add(name, GBC.eop().fill());
64
65 registerValidableComponent(tmsUrl);
66 }
67
68 private String buildTMSUrl() {
69 StringBuilder a = new StringBuilder("tms");
70 String z = sanitize(tmsZoom.getText());
71 if (!z.isEmpty()) {
72 a.append('[').append(z).append(']');
73 }
74 a.append(':').append(sanitize(getImageryRawUrl(), ImageryType.TMS));
75 return a.toString();
76 }
77
78 @Override
79 public ImageryInfo getImageryInfo() {
80 ImageryInfo ret = new ImageryInfo(getImageryName(), getTmsUrl());
81 ret.setImageryType(ImageryType.TMS);
82 return ret;
83
84 }
85
86 protected final String getTmsUrl() {
87 return sanitize(tmsUrl.getText());
88 }
89
90 @Override
91 protected boolean isImageryValid() {
92 return !getImageryName().isEmpty() && !getTmsUrl().isEmpty();
93 }
94}
Note: See TracBrowser for help on using the repository browser.