Changeset 13746 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-05-13T11:41:14+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r13742 r13746 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout;7 6 import java.awt.Point; 7 import java.awt.event.InputMethodEvent; 8 import java.awt.event.InputMethodListener; 8 9 import java.io.ByteArrayInputStream; 9 10 import java.io.IOException; … … 29 30 30 31 import javax.imageio.ImageIO; 32 import javax.swing.JLabel; 31 33 import javax.swing.JPanel; 32 import javax.swing.JScrollPane;33 34 import javax.swing.JTable; 34 35 import javax.swing.ListSelectionModel; 36 import javax.swing.RowFilter; 35 37 import javax.swing.table.AbstractTableModel; 38 import javax.swing.table.TableRowSorter; 36 39 import javax.xml.namespace.QName; 37 40 import javax.xml.stream.XMLStreamException; … … 57 60 import org.openstreetmap.josm.gui.ExtendedDialog; 58 61 import org.openstreetmap.josm.gui.layer.NativeScaleLayer.ScaleList; 62 import org.openstreetmap.josm.gui.layer.imagery.WMTSLayerSelection; 63 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 59 64 import org.openstreetmap.josm.io.CachedFile; 60 65 import org.openstreetmap.josm.spi.preferences.Config; … … 170 175 return identifier; 171 176 } 177 178 /** 179 * 180 * @return projection of this tileMatrix 181 */ 182 public String getCrs() { 183 return crs; 184 } 172 185 } 173 186 … … 264 277 private static final class SelectLayerDialog extends ExtendedDialog { 265 278 private final transient List<Entry<String, List<Layer>>> layers; 266 private final JTablelist;279 private final WMTSLayerSelection list; 267 280 268 281 SelectLayerDialog(Collection<Layer> layers) { 269 282 super(Main.parent, tr("Select WMTS layer"), tr("Add layers"), tr("Cancel")); 270 283 this.layers = groupLayersByNameAndTileMatrixSet(layers); 271 this.list = getLayerSelectionPanel(this.layers); 272 JPanel panel = new JPanel(new GridBagLayout()); 273 panel.add(new JScrollPane(this.list), GBC.eol().fill()); 274 setContent(panel); 284 this.list = new WMTSLayerSelection(this.layers); 285 setContent(list); 275 286 } 276 287 277 288 public DefaultLayer getSelectedLayer() { 278 int index = list.getSelectedRow(); 279 if (index < 0) { 280 return null; //nothing selected 281 } 282 Layer selectedLayer = layers.get(list.convertRowIndexToModel(index)).getValue().get(0); 289 Layer selectedLayer = list.getSelectedLayer(); 283 290 return new DefaultLayer(ImageryType.WMTS, selectedLayer.identifier, selectedLayer.style, selectedLayer.tileMatrixSet.identifier); 284 291 } … … 951 958 } 952 959 953 public static J TablegetLayerSelectionPanel(List<Entry<String, List<Layer>>> layers) {960 public static JPanel getLayerSelectionPanel(List<Entry<String, List<Layer>>> layers) { 954 961 JTable list = new JTable( 955 962 new AbstractTableModel() { … … 1002 1009 list.setRowSelectionAllowed(true); 1003 1010 list.setColumnSelectionAllowed(false); 1004 return list; 1011 JPanel ret = new JPanel(); 1012 ret.add(new JLabel(tr("Filter layers:")), GBC.eol().fill(GBC.HORIZONTAL)); 1013 final JosmTextArea filter = new JosmTextArea(); 1014 filter.addInputMethodListener(new InputMethodListener() { 1015 @SuppressWarnings({ "unchecked", "rawtypes" }) 1016 @Override 1017 public void inputMethodTextChanged(InputMethodEvent event) { 1018 ((TableRowSorter) list.getRowSorter()).setRowFilter(RowFilter.regexFilter(filter.getText())); 1019 } 1020 1021 @Override 1022 public void caretPositionChanged(InputMethodEvent event) { 1023 return; 1024 } 1025 }); 1026 ret.add(list, GBC.eol().fill()); 1027 return ret; 1005 1028 } 1006 1029 -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java
r13745 r13746 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension;7 6 import java.awt.GridBagLayout; 8 7 import java.io.IOException; … … 16 15 import javax.swing.JOptionPane; 17 16 import javax.swing.JPanel; 18 import javax.swing.JScrollPane;19 import javax.swing.JTable;20 17 21 18 import org.openstreetmap.josm.data.imagery.DefaultLayer; … … 26 23 import org.openstreetmap.josm.data.imagery.WMTSTileSource.Layer; 27 24 import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException; 25 import org.openstreetmap.josm.gui.layer.imagery.WMTSLayerSelection; 28 26 import org.openstreetmap.josm.tools.GBC; 29 27 import org.openstreetmap.josm.tools.Logging; … … 36 34 public class AddWMTSLayerPanel extends AddImageryPanel { 37 35 private final transient JPanel layerPanel = new JPanel(new GridBagLayout()); 38 private transient JTablelayerTable;36 private transient WMTSLayerSelection layerTable; 39 37 private final JCheckBox setDefaultLayer = new JCheckBox(tr("Set default layer?")); 40 38 private List<Entry<String, List<Layer>>> layers; … … 69 67 WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(rawUrl.getText(), getCommonHeaders()); 70 68 layers = WMTSTileSource.groupLayersByNameAndTileMatrixSet(capabilities.getLayers()); 71 layerTable = WMTSTileSource.getLayerSelectionPanel(layers);69 layerTable = new WMTSLayerSelection(layers); 72 70 layerPanel.removeAll(); 73 JScrollPane scrollPane = new JScrollPane(layerTable); 74 scrollPane.setPreferredSize(new Dimension(100, 100)); 75 layerPanel.add(scrollPane, GBC.eol().fill()); 71 layerPanel.add(layerTable, GBC.eol().fill()); 76 72 layerPanel.revalidate(); 77 73 } catch (IOException | WMTSGetCapabilitiesException ex) { … … 93 89 throw new IllegalArgumentException(tr("You need to get fetch layers")); 94 90 } 95 int index = layerTable.getSelectedRow(); 96 if (index < 0) { 97 throw new IllegalArgumentException(tr("Invalid layer selected. Index: {1}", index)); 98 } 99 Layer selectedLayer = layers.get(layerTable.convertRowIndexToModel(index)).getValue().get(0); 91 Layer selectedLayer = layerTable.getSelectedLayer(); 100 92 ret.setDefaultLayers( 101 93 Collections.<DefaultLayer>singletonList(
Note:
See TracChangeset
for help on using the changeset viewer.