Changeset 6000 in josm for trunk


Ignore:
Timestamp:
2013-06-10T22:03:21+02:00 (11 years ago)
Author:
simon04
Message:

Add combobox for image format to dialog when creating WMS layer

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r5617 r6000  
    55
    66import java.awt.Dimension;
     7import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.io.IOException;
     
    1011import javax.swing.Action;
    1112import javax.swing.ImageIcon;
     13import javax.swing.JComboBox;
    1214import javax.swing.JOptionPane;
     15import javax.swing.JPanel;
    1316import javax.swing.JScrollPane;
    1417import org.openstreetmap.josm.Main;
     
    2023import org.openstreetmap.josm.io.imagery.WMSImagery;
    2124import org.openstreetmap.josm.gui.preferences.imagery.WMSLayerTree;
     25import org.openstreetmap.josm.tools.GBC;
    2226import org.openstreetmap.josm.tools.ImageProvider;
    2327
     
    7781            final WMSLayerTree tree = new WMSLayerTree();
    7882            tree.updateTree(wms);
     83            final JComboBox formats = new JComboBox(wms.getFormats().toArray());
     84            formats.setToolTipText(tr("Select image format for WMS layer"));
    7985
    8086            if (1 != new ExtendedDialog(Main.parent, tr("Select WMS layers"), new String[]{tr("Add layers"), tr("Cancel")}) {{
    8187                final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree());
    82                 setContent(scrollPane);
    8388                scrollPane.setPreferredSize(new Dimension(400, 400));
     89                final JPanel panel = new JPanel(new GridBagLayout());
     90                panel.add(scrollPane, GBC.eol().fill());
     91                panel.add(formats, GBC.eol().fill(GBC.HORIZONTAL));
     92                setContent(panel);
    8493            }}.showDialog().getValue()) {
    8594                return null;
    8695            }
    8796
    88             String url = wms.buildGetMapUrl(tree.getSelectedLayers());
     97            final String url = wms.buildGetMapUrl(
     98                    tree.getSelectedLayers(), (String) formats.getSelectedItem());
    8999            return new ImageryInfo(info.getName(), url, "wms", info.getEulaAcceptanceRequired(), info.getCookies());
    90100        } // exception handling from AddWMSLayerPanel.java
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java

    r5886 r6000  
    1212import java.io.IOException;
    1313import java.net.MalformedURLException;
     14import javax.swing.DefaultComboBoxModel;
    1415
    1516import javax.swing.JButton;
    1617import javax.swing.JCheckBox;
     18import javax.swing.JComboBox;
    1719import javax.swing.JLabel;
    1820import javax.swing.JOptionPane;
     
    3133    private final JCheckBox endpoint = new JCheckBox(tr("Store WMS endpoint only, select layers at usage"));
    3234    private final WMSLayerTree tree = new WMSLayerTree();
     35    private final JComboBox formats = new JComboBox();
    3336    private final JLabel wmsInstruction;
    3437    private final JosmTextArea wmsUrl = new JosmTextArea(3, 40);
     
    5356        add(new JScrollPane(showBounds), GBC.eop().fill());
    5457
    55         add(wmsInstruction = new JLabel(tr("3. Verify generated WMS URL")), GBC.eol());
     58        add(new JLabel(tr("3. Select image format")), GBC.eol());
     59        add(formats, GBC.eol().fill());
     60
     61        add(wmsInstruction = new JLabel(tr("4. Verify generated WMS URL")), GBC.eol());
    5662        add(wmsUrl, GBC.eop().fill());
    5763        wmsUrl.setLineWrap(true);
    5864
    59         add(new JLabel(tr("4. Enter name for this layer")), GBC.eol());
     65        add(new JLabel(tr("5. Enter name for this layer")), GBC.eol());
    6066        add(name, GBC.eop().fill());
    6167
     
    6672                    wms.attemptGetCapabilities(rawUrl.getText());
    6773                    tree.updateTree(wms);
     74                    formats.setModel(new DefaultComboBoxModel(wms.getFormats().toArray()));
    6875                } catch (MalformedURLException ex) {
    6976                    JOptionPane.showMessageDialog(getParent(), tr("Invalid service URL."),
     
    8794                showBounds.setEnabled(!endpoint.isSelected());
    8895                wmsInstruction.setEnabled(!endpoint.isSelected());
     96                formats.setEnabled(!endpoint.isSelected());
    8997                wmsUrl.setEnabled(!endpoint.isSelected());
    9098                if (endpoint.isSelected()) {
     
    99107            @Override
    100108            public void propertyChange(PropertyChangeEvent evt) {
     109                onLayerSelectionChanged();
     110            }
     111        });
     112
     113        formats.addActionListener(new ActionListener() {
     114            @Override
     115            public void actionPerformed(ActionEvent e) {
    101116                onLayerSelectionChanged();
    102117            }
     
    124139    protected final void onLayerSelectionChanged() {
    125140        if (wms.getServiceUrl() != null) {
    126             wmsUrl.setText(wms.buildGetMapUrl(tree.getSelectedLayers()));
     141            wmsUrl.setText(wms.buildGetMapUrl(tree.getSelectedLayers(), (String) formats.getSelectedItem()));
    127142            name.setText(wms.getServiceUrl().getHost() + ": " + Utils.join(", ", tree.getSelectedLayers()));
    128143        }
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r5731 r6000  
    1010import java.net.URL;
    1111import java.net.URLConnection;
     12import java.util.ArrayList;
    1213import java.util.Collection;
    1314import java.util.HashSet;
    14 import java.util.LinkedList;
    1515import java.util.List;
    1616import java.util.Set;
     
    5151    private List<LayerDetails> layers;
    5252    private URL serviceUrl;
     53    private List<String> formats;
    5354
    5455    public List<LayerDetails> getLayers() {
     
    5859    public URL getServiceUrl() {
    5960        return serviceUrl;
     61    }
     62
     63    public List<String> getFormats() {
     64        return formats;
    6065    }
    6166
     
    8388
    8489    public String buildGetMapUrl(Collection<LayerDetails> selectedLayers) {
     90        return buildGetMapUrl(selectedLayers, "image/jpeg");
     91    }
     92
     93    public String buildGetMapUrl(Collection<LayerDetails> selectedLayers, String format) {
    8594        return buildRootUrl()
    86                 + "FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS="
     95                + "FORMAT=" + format + "&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS="
    8796                + Utils.join(",", Utils.transform(selectedLayers, new Utils.Function<LayerDetails, String>() {
    8897            @Override
     
    151160            child = getChild(child, "Request");
    152161            child = getChild(child, "GetMap");
     162
     163            formats = new ArrayList<String>(Utils.transform(getChildren(child, "Format"), new Utils.Function<Element, String>() {
     164                @Override
     165                public String apply(Element x) {
     166                    return x.getTextContent();
     167                }
     168            }));
     169
    153170            child = getChild(child, "DCPType");
    154171            child = getChild(child, "HTTP");
     
    185202
    186203    private List<LayerDetails> parseLayers(List<Element> children, Set<String> parentCrs) {
    187         List<LayerDetails> details = new LinkedList<LayerDetails>();
     204        List<LayerDetails> details = new ArrayList<LayerDetails>();
    188205        for (Element element : children) {
    189206            details.add(parseLayer(element, parentCrs));
     
    281298
    282299    private static List<Element> getChildren(Element parent, String name) {
    283         List<Element> retVal = new LinkedList<Element>();
     300        List<Element> retVal = new ArrayList<Element>();
    284301        for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
    285302            if (child instanceof Element && name.equals(child.getNodeName())) {
Note: See TracChangeset for help on using the changeset viewer.