Changeset 13746 in josm


Ignore:
Timestamp:
2018-05-13T11:41:14+02:00 (12 months ago)
Author:
wiktorn
Message:

Add filter for WMTS layers, calculate preferred widths for columns.

See: #16249

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r13742 r13746  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.GridBagLayout;
    76import java.awt.Point;
     7import java.awt.event.InputMethodEvent;
     8import java.awt.event.InputMethodListener;
    89import java.io.ByteArrayInputStream;
    910import java.io.IOException;
     
    2930
    3031import javax.imageio.ImageIO;
     32import javax.swing.JLabel;
    3133import javax.swing.JPanel;
    32 import javax.swing.JScrollPane;
    3334import javax.swing.JTable;
    3435import javax.swing.ListSelectionModel;
     36import javax.swing.RowFilter;
    3537import javax.swing.table.AbstractTableModel;
     38import javax.swing.table.TableRowSorter;
    3639import javax.xml.namespace.QName;
    3740import javax.xml.stream.XMLStreamException;
     
    5760import org.openstreetmap.josm.gui.ExtendedDialog;
    5861import org.openstreetmap.josm.gui.layer.NativeScaleLayer.ScaleList;
     62import org.openstreetmap.josm.gui.layer.imagery.WMTSLayerSelection;
     63import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    5964import org.openstreetmap.josm.io.CachedFile;
    6065import org.openstreetmap.josm.spi.preferences.Config;
     
    170175            return identifier;
    171176        }
     177
     178        /**
     179         *
     180         * @return projection of this tileMatrix
     181         */
     182        public String getCrs() {
     183            return crs;
     184        }
    172185    }
    173186
     
    264277    private static final class SelectLayerDialog extends ExtendedDialog {
    265278        private final transient List<Entry<String, List<Layer>>> layers;
    266         private final JTable list;
     279        private final WMTSLayerSelection list;
    267280
    268281        SelectLayerDialog(Collection<Layer> layers) {
    269282            super(Main.parent, tr("Select WMTS layer"), tr("Add layers"), tr("Cancel"));
    270283            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);
    275286        }
    276287
    277288        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();
    283290            return new DefaultLayer(ImageryType.WMTS, selectedLayer.identifier, selectedLayer.style, selectedLayer.tileMatrixSet.identifier);
    284291        }
     
    951958    }
    952959
    953     public static JTable getLayerSelectionPanel(List<Entry<String, List<Layer>>> layers) {
     960    public static JPanel getLayerSelectionPanel(List<Entry<String, List<Layer>>> layers) {
    954961        JTable list = new JTable(
    955962                new AbstractTableModel() {
     
    10021009        list.setRowSelectionAllowed(true);
    10031010        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;
    10051028    }
    10061029
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java

    r13745 r13746  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Dimension;
    76import java.awt.GridBagLayout;
    87import java.io.IOException;
     
    1615import javax.swing.JOptionPane;
    1716import javax.swing.JPanel;
    18 import javax.swing.JScrollPane;
    19 import javax.swing.JTable;
    2017
    2118import org.openstreetmap.josm.data.imagery.DefaultLayer;
     
    2623import org.openstreetmap.josm.data.imagery.WMTSTileSource.Layer;
    2724import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException;
     25import org.openstreetmap.josm.gui.layer.imagery.WMTSLayerSelection;
    2826import org.openstreetmap.josm.tools.GBC;
    2927import org.openstreetmap.josm.tools.Logging;
     
    3634public class AddWMTSLayerPanel extends AddImageryPanel {
    3735    private final transient JPanel layerPanel = new JPanel(new GridBagLayout());
    38     private transient JTable layerTable;
     36    private transient WMTSLayerSelection layerTable;
    3937    private final JCheckBox setDefaultLayer = new JCheckBox(tr("Set default layer?"));
    4038    private List<Entry<String, List<Layer>>> layers;
     
    6967                WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(rawUrl.getText(), getCommonHeaders());
    7068                layers = WMTSTileSource.groupLayersByNameAndTileMatrixSet(capabilities.getLayers());
    71                 layerTable = WMTSTileSource.getLayerSelectionPanel(layers);
     69                layerTable = new WMTSLayerSelection(layers);
    7270                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());
    7672                layerPanel.revalidate();
    7773            } catch (IOException | WMTSGetCapabilitiesException ex) {
     
    9389                throw new IllegalArgumentException(tr("You need to get fetch layers"));
    9490            }
    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();
    10092            ret.setDefaultLayers(
    10193                    Collections.<DefaultLayer>singletonList(
Note: See TracChangeset for help on using the changeset viewer.