Changeset 7119 in josm for trunk


Ignore:
Timestamp:
2014-05-14T00:51:20+02:00 (6 years ago)
Author:
Don-vip
Message:

code refactoring/cleanup/javadoc + fix bug in preset text comparator in menu

Location:
trunk/src/org/openstreetmap/josm
Files:
1 deleted
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r7112 r7119  
    3636import org.openstreetmap.josm.data.osm.history.HistoryWay;
    3737import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     38import org.openstreetmap.josm.gui.tagging.TaggingPresetNameTemplateList;
    3839import org.openstreetmap.josm.tools.AlphanumComparator;
    3940import org.openstreetmap.josm.tools.I18n;
    40 import org.openstreetmap.josm.tools.TaggingPresetNameTemplateList;
    4141import org.openstreetmap.josm.tools.Utils;
    4242import org.openstreetmap.josm.tools.Utils.Function;
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r7005 r7119  
    6767import org.openstreetmap.josm.io.imagery.WMSRequest;
    6868
    69 
    7069/**
    7170 * This is a layer that grabs the current screen from an WMS server. The data
     
    156155    private boolean isInvalidUrlConfirmed = false;
    157156
     157    /**
     158     * Constructs a new {@code WMSLayer}.
     159     */
    158160    public WMSLayer() {
    159161        this(new ImageryInfo(tr("Blank Layer")));
     
    338340
    339341        attribution.paintAttribution(g, mv.getWidth(), mv.getHeight(), null, null, 0, this);
    340 
    341342    }
    342343
     
    453454                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    454455                if (!img.paint(g, mv, x, y, leftEdge, bottomEdge)) {
    455                     WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, true);
    456                     addRequest(request);
     456                    addRequest(new WMSRequest(x, y, info.getPixelPerDegree(), real, true));
    457457                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
    458458                } else if (img.getState() == State.PARTLY_IN_CACHE && autoDownloadEnabled) {
    459                     WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, false);
    460                     addRequest(request);
     459                    addRequest(new WMSRequest(x, y, info.getPixelPerDegree(), real, false));
    461460                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
    462461                }
     
    658657
    659658    public class DownloadAction extends AbstractAction {
     659        /**
     660         * Constructs a new {@code DownloadAction}.
     661         */
    660662        public DownloadAction() {
    661663            super(tr("Download visible tiles"));
     
    776778
    777779    public class ReloadErrorTilesAction extends AbstractAction {
     780        /**
     781         * Constructs a new {@code ReloadErrorTilesAction}.
     782         */
    778783        public ReloadErrorTilesAction() {
    779784            super(tr("Reload erroneous tiles"));
     
    797802
    798803    public class ToggleAlphaAction extends AbstractAction implements LayerAction {
     804        /**
     805         * Constructs a new {@code ToggleAlphaAction}.
     806         */
    799807        public ToggleAlphaAction() {
    800808            super(tr("Alpha channel"));
     
    815823            Main.map.mapView.repaint();
    816824        }
     825
    817826        @Override
    818827        public Component createMenuComponent() {
     
    821830            return item;
    822831        }
     832
    823833        @Override
    824834        public boolean supportLayers(List<Layer> layers) {
     
    827837    }
    828838
    829 
    830839    public class ToggleAutoResolutionAction extends AbstractAction implements LayerAction {
     840
     841        /**
     842         * Constructs a new {@code ToggleAutoResolutionAction}.
     843         */
    831844        public ToggleAutoResolutionAction() {
    832845            super(tr("Automatically change resolution"));
     
    858871     */
    859872    public class BookmarkWmsAction extends AbstractAction {
     873        /**
     874         * Constructs a new {@code BookmarkWmsAction}.
     875         */
    860876        public BookmarkWmsAction() {
    861877            super(tr("Set WMS Bookmark"));
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetMenu.java

    r7005 r7119  
    88import java.awt.Point;
    99import java.awt.event.ActionEvent;
     10import java.io.Serializable;
    1011import java.util.ArrayList;
    1112import java.util.Collections;
     13import java.util.Comparator;
    1214import java.util.List;
    1315
     
    1921
    2022import org.openstreetmap.josm.Main;
    21 import org.openstreetmap.josm.tools.PresetTextComparator;
     23import org.openstreetmap.josm.tools.AlphanumComparator;
    2224
    2325public class TaggingPresetMenu extends TaggingPreset {
    24     public JMenu menu = null; // set by TaggingPresetPreferences
    25    
     26    public JMenu menu = null; // set by TaggingPresets
     27
     28    private static class PresetTextComparator implements Comparator<JMenuItem>, Serializable {
     29        @Override
     30        public int compare(JMenuItem o1, JMenuItem o2) {
     31            if (Main.main.menu.presetSearchAction.equals(o1.getAction()))
     32                return -1;
     33            else if (Main.main.menu.presetSearchAction.equals(o2.getAction()))
     34                return 1;
     35            else
     36                return AlphanumComparator.getInstance().compare(o1.getText(), o2.getText());
     37        }
     38    }
     39
    2640    @Override
    2741    public void setDisplayName() {
     
    6781        }
    6882    }
    69    
     83
    7084    /**
    7185     * Sorts the menu items using the translated item text
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetNameTemplateList.java

    r7116 r7119  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.tools;
     2package org.openstreetmap.josm.gui.tagging;
    33
    44import java.util.Collection;
     
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.data.osm.OsmPrimitive;
    11 import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    12 import org.openstreetmap.josm.gui.tagging.TaggingPresetListener;
    13 import org.openstreetmap.josm.gui.tagging.TaggingPresetType;
    14 import org.openstreetmap.josm.gui.tagging.TaggingPresets;
    1511
    1612/**
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r7089 r7119  
    6060        switch (this) {
    6161            case BZIP2:
    62                 return FileImporter.getBZip2InputStream(in);
     62                return Utils.getBZip2InputStream(in);
    6363            case GZIP:
    64                 return FileImporter.getGZipInputStream(in);
     64                return Utils.getGZipInputStream(in);
    6565            case ZIP:
    66                 return FileImporter.getZipInputStream(in);
     66                return Utils.getZipInputStream(in);
    6767            case NONE:
    6868            default:
  • trunk/src/org/openstreetmap/josm/io/FileImporter.java

    r7089 r7119  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.io.BufferedInputStream;
    76import java.io.File;
    87import java.io.IOException;
    9 import java.io.InputStream;
    10 import java.nio.charset.StandardCharsets;
    118import java.util.List;
    12 import java.util.zip.GZIPInputStream;
    13 import java.util.zip.ZipEntry;
    14 import java.util.zip.ZipInputStream;
    159
    1610import javax.swing.JOptionPane;
    1711
    18 import org.apache.tools.bzip2.CBZip2InputStream;
    1912import org.openstreetmap.josm.Main;
    2013import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    138131    }
    139132
    140     public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException {
    141         if (in == null) {
    142             return null;
    143         }
    144         BufferedInputStream bis = new BufferedInputStream(in);
    145         int b = bis.read();
    146         if (b != 'B')
    147             throw new IOException(tr("Invalid bz2 file."));
    148         b = bis.read();
    149         if (b != 'Z')
    150             throw new IOException(tr("Invalid bz2 file."));
    151         return new CBZip2InputStream(bis, /* see #9537 */ true);
    152     }
    153 
    154     public static GZIPInputStream getGZipInputStream(InputStream in) throws IOException {
    155         if (in == null) {
    156             return null;
    157         }
    158         return new GZIPInputStream(in);
    159     }
    160 
    161     public static ZipInputStream getZipInputStream(InputStream in) throws IOException {
    162         if (in == null) {
    163             return null;
    164         }
    165         ZipInputStream zis = new ZipInputStream(in, StandardCharsets.UTF_8);
    166         // Positions the stream at the beginning of first entry
    167         ZipEntry ze = zis.getNextEntry();
    168         if (ze != null && Main.isDebugEnabled()) {
    169             Main.debug("Zip entry: "+ze.getName());
    170         }
    171         return zis;
    172     }
    173 
    174133    /**
    175134     * Returns the enabled state of this {@code FileImporter}. When enabled, it is listed and usable in "File-&gt;Open" dialog.
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7083 r7119  
    4545import java.util.regex.Pattern;
    4646import java.util.zip.GZIPInputStream;
     47import java.util.zip.ZipEntry;
    4748import java.util.zip.ZipFile;
     49import java.util.zip.ZipInputStream;
    4850
    4951import org.apache.tools.bzip2.CBZip2InputStream;
    5052import org.openstreetmap.josm.Main;
    5153import org.openstreetmap.josm.data.Version;
    52 import org.openstreetmap.josm.io.FileImporter;
    5354
    5455/**
     
    665666    public static InputStream openURLAndDecompress(final URL url, final boolean decompress) throws IOException {
    666667        final URLConnection connection = setupURLConnection(url.openConnection());
    667         if (decompress && "application/x-gzip".equals(connection.getHeaderField("Content-Type"))) {
    668             return new GZIPInputStream(connection.getInputStream());
    669         } else if (decompress && "application/x-bzip2".equals(connection.getHeaderField("Content-Type"))) {
    670             return FileImporter.getBZip2InputStream(new BufferedInputStream(connection.getInputStream()));
    671         } else {
    672             return connection.getInputStream();
    673         }
     668        final InputStream in = connection.getInputStream();
     669        if (decompress) {
     670            switch (connection.getHeaderField("Content-Type")) {
     671            case "application/zip":
     672                return getZipInputStream(in);
     673            case "application/x-gzip":
     674                return getGZipInputStream(in);
     675            case "application/x-bzip2":
     676                return getBZip2InputStream(in);
     677            }
     678        }
     679        return in;
     680    }
     681
     682    /**
     683     * Returns a Bzip2 input stream wrapping given input stream.
     684     * @param in The raw input stream
     685     * @return a Bzip2 input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     686     * @throws IOException if the given input stream does not contain valid BZ2 header
     687     * @since 7119
     688     */
     689    public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException {
     690        if (in == null) {
     691            return null;
     692        }
     693        BufferedInputStream bis = new BufferedInputStream(in);
     694        int b = bis.read();
     695        if (b != 'B')
     696            throw new IOException(tr("Invalid bz2 file."));
     697        b = bis.read();
     698        if (b != 'Z')
     699            throw new IOException(tr("Invalid bz2 file."));
     700        return new CBZip2InputStream(bis, /* see #9537 */ true);
     701    }
     702
     703    /**
     704     * Returns a Gzip input stream wrapping given input stream.
     705     * @param in The raw input stream
     706     * @return a Gzip input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     707     * @throws IOException if an I/O error has occurred
     708     * @since 7119
     709     */
     710    public static GZIPInputStream getGZipInputStream(InputStream in) throws IOException {
     711        if (in == null) {
     712            return null;
     713        }
     714        return new GZIPInputStream(in);
     715    }
     716
     717    /**
     718     * Returns a Zip input stream wrapping given input stream.
     719     * @param in The raw input stream
     720     * @return a Zip input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     721     * @throws IOException if an I/O error has occurred
     722     * @since 7119
     723     */
     724    public static ZipInputStream getZipInputStream(InputStream in) throws IOException {
     725        if (in == null) {
     726            return null;
     727        }
     728        ZipInputStream zis = new ZipInputStream(in, StandardCharsets.UTF_8);
     729        // Positions the stream at the beginning of first entry
     730        ZipEntry ze = zis.getNextEntry();
     731        if (ze != null && Main.isDebugEnabled()) {
     732            Main.debug("Zip entry: "+ze.getName());
     733        }
     734        return zis;
    674735    }
    675736
Note: See TracChangeset for help on using the changeset viewer.