- Timestamp:
- 2013-02-19T22:38:52+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddImageryPanel.java
r5617 r5731 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.gui.preferences.imagery; 2 3 4 import java.awt.GridBagLayout; 3 5 import java.awt.LayoutManager; 6 import java.util.ArrayList; 7 import java.util.Collection; 8 9 import javax.swing.AbstractButton; 4 10 import javax.swing.JPanel; 11 import javax.swing.JTextArea; 12 import javax.swing.JTextField; 13 import javax.swing.event.ChangeEvent; 14 import javax.swing.event.ChangeListener; 15 import javax.swing.event.DocumentEvent; 16 import javax.swing.event.DocumentListener; 17 import javax.swing.text.JTextComponent; 18 5 19 import org.openstreetmap.josm.data.imagery.ImageryInfo; 6 20 21 /** 22 * An abstract imagery panel used to add WMS/TMS imagery sources. See implementations. 23 * @see AddTMSLayerPanel 24 * @see AddWMSLayerPanel 25 * @since 5617 26 */ 7 27 public abstract class AddImageryPanel extends JPanel { 8 protected AddImageryPanel() { 28 29 protected final JTextArea rawUrl = new JTextArea(3, 40); 30 protected final JTextField name = new JTextField(); 31 32 protected final Collection<ContentValidationListener> listeners = new ArrayList<ContentValidationListener>(); 33 34 /** 35 * A listener notified when the validation status of this panel change. 36 */ 37 public interface ContentValidationListener { 38 /** 39 * Called when the validation status of this panel changed 40 * @param isValid true if the conditions required to close this panel are met 41 */ 42 public void contentChanged(boolean isValid); 9 43 } 10 44 11 protected AddImageryPanel( boolean isDoubleBuffered) {12 super(isDoubleBuffered);45 protected AddImageryPanel() { 46 this(new GridBagLayout()); 13 47 } 14 48 15 49 protected AddImageryPanel(LayoutManager layout) { 16 50 super(layout); 51 registerValidableComponent(name); 17 52 } 18 53 19 protected AddImageryPanel(LayoutManager layout, boolean isDoubleBuffered) { 20 super(layout, isDoubleBuffered); 54 protected final void registerValidableComponent(AbstractButton component) { 55 component.addChangeListener(new ChangeListener() { 56 @Override public void stateChanged(ChangeEvent e) { notifyListeners(); } 57 }); 21 58 } 22 59 23 abstract ImageryInfo getImageryInfo(); 60 protected final void registerValidableComponent(JTextComponent component) { 61 component.getDocument().addDocumentListener(new DocumentListener() { 62 @Override public void removeUpdate(DocumentEvent e) { notifyListeners(); } 63 @Override public void insertUpdate(DocumentEvent e) { notifyListeners(); } 64 @Override public void changedUpdate(DocumentEvent e) { notifyListeners(); } 65 }); 66 } 67 68 protected abstract ImageryInfo getImageryInfo(); 69 70 protected static String sanitize(String s) { 71 return s.replaceAll("[\r\n]+", "").trim(); 72 } 73 74 protected final String getImageryName() { 75 return sanitize(name.getText()); 76 } 77 78 protected final String getImageryRawUrl() { 79 return sanitize(rawUrl.getText()); 80 } 81 82 protected abstract boolean isImageryValid(); 83 84 /** 85 * Registers a new ContentValidationListener 86 * @param l The new ContentValidationListener that will be notified of validation status changes 87 */ 88 public final void addContentValidationListener(ContentValidationListener l) { 89 if (l != null) { 90 listeners.add(l); 91 } 92 } 93 94 private final void notifyListeners() { 95 for (ContentValidationListener l : listeners) { 96 l.contentChanged(isImageryValid()); 97 } 98 } 24 99 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddTMSLayerPanel.java
r5617 r5731 5 5 6 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout;8 7 import java.awt.event.KeyAdapter; 9 8 import java.awt.event.KeyEvent; 10 9 import java.util.Arrays; 10 11 11 import javax.swing.JLabel; 12 12 import javax.swing.JTextArea; 13 13 import javax.swing.JTextField; 14 14 import javax.swing.text.View; 15 15 16 import org.openstreetmap.josm.data.imagery.ImageryInfo; 16 17 import org.openstreetmap.josm.tools.GBC; … … 19 20 public class AddTMSLayerPanel extends AddImageryPanel { 20 21 21 private final JTextArea rawUrl = new JTextArea(3, 40);22 22 private final JTextField tmsZoom = new JTextField(); 23 23 private final JTextArea tmsUrl = new JTextArea(3, 40); 24 private final JTextField name = new JTextField();25 24 private final KeyAdapter keyAdapter = new KeyAdapter() { 26 25 @Override … … 31 30 32 31 public AddTMSLayerPanel() { 33 super(new GridBagLayout());34 32 35 33 add(new JLabel(tr("1. Enter URL")), GBC.eol()); … … 60 58 add(name, GBC.eop().fill()); 61 59 62 } 63 64 private String sanitize(String s) { 65 return s.replaceAll("[\r\n]+", "").trim(); 60 registerValidableComponent(tmsUrl); 66 61 } 67 62 … … 73 68 } 74 69 a.append(":"); 75 a.append( sanitize(rawUrl.getText()));70 a.append(getImageryRawUrl()); 76 71 return a.toString(); 77 72 } … … 79 74 @Override 80 75 public ImageryInfo getImageryInfo() { 81 return new ImageryInfo( name.getText(), tmsUrl.getText());76 return new ImageryInfo(getImageryName(), getTmsUrl()); 82 77 } 83 78 … … 91 86 (int) Math.ceil(view.getPreferredSpan(View.Y_AXIS))); 92 87 } 88 89 protected final String getTmsUrl() { 90 return sanitize(tmsUrl.getText()); 91 } 92 93 protected boolean isImageryValid() { 94 return !getImageryName().isEmpty() && !getTmsUrl().isEmpty(); 95 } 93 96 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java
r5650 r5731 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension;7 import java.awt.GridBagLayout;8 6 import java.awt.event.ActionEvent; 9 7 import java.awt.event.ActionListener; … … 14 12 import java.io.IOException; 15 13 import java.net.MalformedURLException; 14 16 15 import javax.swing.JButton; 17 16 import javax.swing.JCheckBox; … … 20 19 import javax.swing.JScrollPane; 21 20 import javax.swing.JTextArea; 22 import javax.swing.JTextField; 21 23 22 import org.openstreetmap.josm.data.imagery.ImageryInfo; 24 23 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; … … 30 29 31 30 private final WMSImagery wms = new WMSImagery(); 32 private final JTextArea rawUrl = new JTextArea(3, 40);33 31 private final JCheckBox endpoint = new JCheckBox(tr("Store WMS endpoint only, select layers at usage")); 34 32 private final WMSLayerTree tree = new WMSLayerTree(); 33 private final JLabel wmsInstruction; 35 34 private final JTextArea wmsUrl = new JTextArea(3, 40); 36 private final J TextField name = new JTextField();35 private final JButton showBounds = new JButton(tr("Show bounds")); 37 36 38 37 public AddWMSLayerPanel() { 39 super(new GridBagLayout());40 38 41 39 add(new JLabel(tr("1. Enter service URL")), GBC.eol()); … … 48 46 add(endpoint, GBC.eol().fill()); 49 47 add(new JScrollPane(tree.getLayerTree()), GBC.eol().fill().weight(1, 100)); 50 final JButton showBounds = new JButton(tr("Show bounds")); 48 51 49 showBounds.setEnabled(false); 52 50 add(new JScrollPane(showBounds), GBC.eop().fill()); 53 51 54 add( new JLabel(tr("3. Verify generated WMS URL")), GBC.eol());52 add(wmsInstruction = new JLabel(tr("3. Verify generated WMS URL")), GBC.eol()); 55 53 add(wmsUrl, GBC.eop().fill()); 56 54 wmsUrl.setLineWrap(true); … … 85 83 tree.getLayerTree().setEnabled(!endpoint.isSelected()); 86 84 showBounds.setEnabled(!endpoint.isSelected()); 85 wmsInstruction.setEnabled(!endpoint.isSelected()); 87 86 wmsUrl.setEnabled(!endpoint.isSelected()); 87 if (endpoint.isSelected()) { 88 name.setText(wms.getServiceUrl().getHost()); 89 } else { 90 onLayerSelectionChanged(); 91 } 88 92 } 89 93 }); … … 91 95 tree.getLayerTree().addPropertyChangeListener("selectedLayers", new PropertyChangeListener() { 92 96 @Override 93 public void propertyChange(PropertyChangeEvent evt) { 94 if (wms.getServiceUrl() != null) { 95 wmsUrl.setText(wms.buildGetMapUrl(tree.getSelectedLayers())); 96 name.setText(wms.getServiceUrl().getHost() + ": " + Utils.join(", ", tree.getSelectedLayers())); 97 } 98 showBounds.setEnabled(tree.getSelectedLayers().size() == 1); 97 public void propertyChange(PropertyChangeEvent evt) { 98 onLayerSelectionChanged(); 99 99 } 100 100 }); … … 113 113 } 114 114 }); 115 115 116 registerValidableComponent(endpoint); 117 registerValidableComponent(rawUrl); 118 registerValidableComponent(wmsUrl); 119 } 120 121 protected final void onLayerSelectionChanged() { 122 if (wms.getServiceUrl() != null) { 123 wmsUrl.setText(wms.buildGetMapUrl(tree.getSelectedLayers())); 124 name.setText(wms.getServiceUrl().getHost() + ": " + Utils.join(", ", tree.getSelectedLayers())); 125 } 126 showBounds.setEnabled(tree.getSelectedLayers().size() == 1); 116 127 } 117 128 … … 120 131 final ImageryInfo info; 121 132 if (endpoint.isSelected()) { 122 info = new ImageryInfo( name.getText(), rawUrl.getText());133 info = new ImageryInfo(getImageryName(), getImageryRawUrl()); 123 134 info.setImageryType(ImageryInfo.ImageryType.WMS_ENDPOINT); 124 135 } else { 125 info = wms.toImageryInfo( name.getText(), tree.getSelectedLayers());126 info.setUrl( wmsUrl.getText());136 info = wms.toImageryInfo(getImageryName(), tree.getSelectedLayers()); 137 info.setUrl(getWmsUrl()); 127 138 } 128 139 return info; 129 140 } 141 142 protected final String getWmsUrl() { 143 return sanitize(wmsUrl.getText()); 144 } 145 146 protected boolean isImageryValid() { 147 if (getImageryName().isEmpty()) { 148 return false; 149 } 150 if (endpoint.isSelected()) { 151 return !getImageryRawUrl().isEmpty(); 152 } else { 153 return !getWmsUrl().isEmpty(); 154 } 155 } 130 156 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r5729 r5731 62 62 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 63 63 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 64 import org.openstreetmap.josm.gui.util.GuiHelper;65 64 import org.openstreetmap.josm.tools.GBC; 66 65 import org.openstreetmap.josm.tools.ImageProvider; … … 437 436 throw new IllegalStateException("Type " + type + " not supported"); 438 437 } 439 GuiHelper.prepareResizeableOptionPane(p, new Dimension(250, 350));440 int answer = JOptionPane.showConfirmDialog(441 gui, p, tr("Add Imagery URL"),442 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);443 if (a nswer == JOptionPane.OK_OPTION) {438 439 final AddImageryDialog addDialog = new AddImageryDialog(gui, p); 440 addDialog.showDialog(); 441 442 if (addDialog.getValue() == 1) { 444 443 try { 445 444 activeModel.addRow(p.getImageryInfo()); … … 456 455 } 457 456 } 458 457 459 458 private class RemoveEntryAction extends AbstractAction implements ListSelectionListener { 460 459 -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r5617 r5731 16 16 import java.util.Set; 17 17 import java.util.regex.Pattern; 18 18 19 import javax.xml.parsers.DocumentBuilder; 19 20 import javax.xml.parsers.DocumentBuilderFactory; 20 import javax.xml.parsers.ParserConfigurationException; 21 21 22 import org.openstreetmap.josm.data.Bounds; 22 23 import org.openstreetmap.josm.data.imagery.ImageryInfo; … … 60 61 61 62 String buildRootUrl() { 63 if (serviceUrl == null) { 64 return null; 65 } 62 66 StringBuilder a = new StringBuilder(serviceUrl.getProtocol()); 63 67 a.append("://");
Note:
See TracChangeset
for help on using the changeset viewer.