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

Last change on this file since 8392 was 8390, checked in by Don-vip, 9 years ago

Sonar - various performance improvements

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