Changeset 6365 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2013-11-05T01:53:15+01:00 (10 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs - fix of recent violations

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r6302 r6365  
    1818
    1919/**
    20  * Command that basically replaces one OSM primitive by another of the
    21  * same type.
     20 * Command that basically replaces one OSM primitive by another of the same type.
    2221 *
    23  * @author Imi
     22 * @since 93
    2423 */
    2524public class ChangeCommand extends Command {
     
    4544        CheckParameterUtil.ensureParameterNotNull(osm, "osm");
    4645        CheckParameterUtil.ensureParameterNotNull(newOsm, "newOsm");
    47         if (newOsm instanceof Way) {
     46        if (newOsm instanceof Way && ((Way)newOsm).getNodesCount() == 0) {
    4847            // Do not allow to create empty ways (see #7465)
    49             if (((Way)newOsm).getNodesCount() == 0) {
    50                 throw new IllegalArgumentException(tr("New way {0} has 0 nodes", newOsm));
    51             }
     48            throw new IllegalArgumentException(tr("New way {0} has 0 nodes", newOsm));
    5249        }
    5350    }
    5451
    55     @Override public boolean executeCommand() {
     52    @Override
     53    public boolean executeCommand() {
    5654        super.executeCommand();
    5755        osm.cloneFrom(newOsm);
     
    6058    }
    6159
    62     @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
     60    @Override
     61    public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    6362        modified.add(osm);
    6463    }
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r6364 r6365  
    222222    }
    223223   
    224     private List<TileSource> getTileSources() {
     224    private final List<TileSource> getTileSources() {
    225225        List<TileSource> tileSources = new ArrayList<TileSource>();
    226226        for (TileSourceProvider provider: providers) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r6324 r6365  
    2424public class PropertiesCellRenderer extends DefaultTableCellRenderer {
    2525
    26     private void setColors(Component c, String key, boolean isSelected, boolean hasFocus) {
     26    private void setColors(Component c, String key, boolean isSelected) {
    2727        UIDefaults defaults = javax.swing.UIManager.getDefaults();
    2828        if (OsmPrimitive.getDiscardableKeys().contains(key)) {
     
    7171                    }
    7272                }
    73                 setColors(c, key, isSelected, hasFocus);
     73                setColors(c, key, isSelected);
    7474            }
    7575        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r6361 r6365  
    12411241    @Override
    12421242    public void preferenceChanged(PreferenceChangeEvent e) {
    1243         if ("display.discardable-keys".equals(e.getKey())) {
    1244             if (Main.main.getCurrentDataSet() != null) {
    1245                 // Re-load data when display preference change
    1246                 selectionChanged(Main.main.getCurrentDataSet().getSelected());
    1247             }
     1243        if ("display.discardable-keys".equals(e.getKey()) && Main.main.getCurrentDataSet() != null) {
     1244            // Re-load data when display preference change
     1245            selectionChanged(Main.main.getCurrentDataSet().getSelected());
    12481246        }
    12491247    }
  • trunk/src/org/openstreetmap/josm/gui/download/BookmarkList.java

    r6340 r6365  
    3434/**
    3535 * List class that read and save its content from the bookmark file.
    36  * @author imi
     36 * @since 6340
    3737 */
    3838public class BookmarkList extends JList {
     
    4040    /**
    4141     * Class holding one bookmarkentry.
    42      * @author imi
    4342     */
    4443    public static class Bookmark implements Comparable<Bookmark> {
     
    4645        private Bounds area;
    4746
     47        /**
     48         * Constructs a new {@code Bookmark} with the given contents.
     49         * @param list Bookmark contents as a list of 5 elements. First item is the name, then come bounds arguments (minlat, minlon, maxlat, maxlon)
     50         * @throws NumberFormatException If the bounds arguments are not numbers
     51         * @throws IllegalArgumentException If list contain less than 5 elements
     52         */
    4853        public Bookmark(Collection<String> list) throws NumberFormatException, IllegalArgumentException {
    4954            List<String> array = new ArrayList<String>(list);
     
    5661
    5762        /**
    58          * Constructs a new {@code Bookmark}.
     63         * Constructs a new empty {@code Bookmark}.
    5964         */
    6065        public Bookmark() {
     
    6368        }
    6469
     70        /**
     71         * Constructs a new unamed {@code Bookmark} for the given area.
     72         * @param area The bookmark area
     73         */
    6574        public Bookmark(Bounds area) {
    6675            this.area = area;
     
    7584            return name.toLowerCase().compareTo(b.name.toLowerCase());
    7685        }
    77 
     86       
     87        @Override
     88        public int hashCode() {
     89            final int prime = 31;
     90            int result = 1;
     91            result = prime * result + ((area == null) ? 0 : area.hashCode());
     92            result = prime * result + ((name == null) ? 0 : name.hashCode());
     93            return result;
     94        }
     95
     96        @Override
     97        public boolean equals(Object obj) {
     98            if (this == obj)
     99                return true;
     100            if (obj == null)
     101                return false;
     102            if (getClass() != obj.getClass())
     103                return false;
     104            Bookmark other = (Bookmark) obj;
     105            if (area == null) {
     106                if (other.area != null)
     107                    return false;
     108            } else if (!area.equals(other.area))
     109                return false;
     110            if (name == null) {
     111                if (other.name != null)
     112                    return false;
     113            } else if (!name.equals(other.name))
     114                return false;
     115            return true;
     116        }
     117
     118        /**
     119         * Returns the bookmark area
     120         * @return The bookmark area
     121         */
    78122        public Bounds getArea() {
    79123            return area;
    80124        }
    81125
     126        /**
     127         * Returns the bookmark name
     128         * @return The bookmark name
     129         */
    82130        public String getName() {
    83131            return name;
    84132        }
    85133
     134        /**
     135         * Sets the bookmark name
     136         * @param name The bookmark name
     137         */
    86138        public void setName(String name) {
    87139            this.name = name;
    88140        }
    89141
     142        /**
     143         * Sets the bookmark area
     144         * @param area The bookmark area
     145         */
    90146        public void setArea(Bounds area) {
    91147            this.area = area;
     
    94150
    95151    /**
    96      * Create a bookmark list as well as the Buttons add and remove.
     152     * Creates a bookmark list as well as the Buttons add and remove.
    97153     */
    98154    public BookmarkList() {
     
    106162     * Loads the bookmarks from file.
    107163     */
    108     public void load() {
     164    public final void load() {
    109165        DefaultListModel model = (DefaultListModel)getModel();
    110166        model.removeAllElements();
     
    161217                    save();
    162218                    Main.info("Removing obsolete bookmarks file");
    163                     bookmarkFile.delete();
     219                    if (!bookmarkFile.delete()) {
     220                        bookmarkFile.deleteOnExit();
     221                    }
    164222                }
    165223            } catch (IOException e) {
    166                 e.printStackTrace();
     224                Main.error(e);
    167225                JOptionPane.showMessageDialog(
    168226                        Main.parent,
     
    179237
    180238    /**
    181      * Save all bookmarks to the preferences file
     239     * Saves all bookmarks to the preferences file
    182240     */
    183241    public void save() {
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r6364 r6365  
    102102        buildMainPanelAboveDownloadSelections(pnl);
    103103
     104        slippyMapChooser = new SlippyMapChooser();
     105       
    104106        // predefined download selections
    105         downloadSelections.add(slippyMapChooser = new SlippyMapChooser());
     107        downloadSelections.add(slippyMapChooser);
    106108        downloadSelections.add(new BookmarkSelection());
    107109        downloadSelections.add(new BoundingBoxSelection());
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r6349 r6365  
    5151        GridBagConstraints gc = new GridBagConstraints();
    5252
    53         AuthenticationMethodChangeListener  authChangeListener = new AuthenticationMethodChangeListener();
     53        AuthenticationMethodChangeListener authChangeListener = new AuthenticationMethodChangeListener();
    5454
    5555        // -- radio button for basic authentication
     
    8383        gc.weightx = 1.0;
    8484        gc.weighty = 1.0;
    85         add(pnlAuthenticationParameteters = new JPanel(), gc);
     85        pnlAuthenticationParameteters = new JPanel();
     86        add(pnlAuthenticationParameteters, gc);
    8687        pnlAuthenticationParameteters.setLayout(new BorderLayout());
    8788
     
    9697        gc.gridy = 2;
    9798        gc.fill = GridBagConstraints.NONE;
    98         add(pnlMessagesPreferences = new MessagesNotifierPanel(), gc);
     99        pnlMessagesPreferences = new MessagesNotifierPanel();
     100        add(pnlMessagesPreferences, gc);
    99101    }
    100102
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/MessagesNotifierPanel.java

    r6349 r6365  
    6767     * Initializes the panel from preferences
    6868     */
    69     public void initFromPreferences() {
     69    public final void initFromPreferences() {
    7070        notifier.setSelected(MessageNotifier.PROP_NOTIFIER_ENABLED.get());
    7171        notifierInterval.setText(Integer.toString(MessageNotifier.PROP_INTERVAL.get()));
  • trunk/src/org/openstreetmap/josm/gui/widgets/JMultilineLabel.java

    r6340 r6365  
    11// License: GPL. For details, see LICENSE file.
    2 
    32package org.openstreetmap.josm.gui.widgets;
    43
     
    1716 * Note that this won't work if JMultilineLabel is put into a JScrollBox or
    1817 * similar as the bounds will never change. Instead scrollbars will be displayed.
     18 *
     19 * @since 6340
    1920 */
    2021public class JMultilineLabel extends JLabel {
     
    2930     *
    3031     * Use setMaxWidth to limit the width of the label.
    31      * @param text
     32     * @param text The text to display
    3233     */
    33     public JMultilineLabel(String text)
    34     {
     34    public JMultilineLabel(String text) {
    3535        super();
    36         text = text.trim().replaceAll("\n", "<br>");
    37         if(!text.startsWith("<html>")) {
    38             text = "<html>" + text + "</html>";
     36        String html = text.trim().replaceAll("\n", "<br>");
     37        if (!html.startsWith("<html>")) {
     38            html = "<html>" + html + "</html>";
    3939        }
    40         super.setText(text);
     40        super.setText(html);
    4141    }
    4242
  • trunk/src/org/openstreetmap/josm/gui/widgets/UrlLabel.java

    r6342 r6365  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.widgets;
    33
     
    1616/**
    1717 * Label that contains a clickable link.
    18  * @author Imi
    19  * 5050: Simplifications by Zverikk included by akks
     18 * @since 6340
    2019 */
    2120public class UrlLabel extends JLabel implements MouseListener {
     
    2524
    2625    /**
    27      * Constructs a new {@code UrlLabel}.
     26     * Constructs a new empty {@code UrlLabel}.
    2827     */
    2928    public UrlLabel() {
     
    3231    }
    3332
     33    /**
     34     * Constructs a new {@code UrlLabel} for the given URL.
     35     * @param url The URL to use, also used as description
     36     */
    3437    public UrlLabel(String url) {
    3538        this (url, url, 0);
    3639    }
    3740
     41    /**
     42     * Constructs a new {@code UrlLabel} for the given URL and font increase.
     43     * @param url The URL to use, also used as description
     44     * @param fontPlus The font increase in 1/72 of an inch units.
     45     */
    3846    public UrlLabel(String url, int fontPlus) {
    3947        this (url, url, fontPlus);
    4048    }
    4149
     50    /**
     51     * Constructs a new {@code UrlLabel} for the given URL and description.
     52     * @param url The URL to use
     53     * @param description The description to display
     54     */
    4255    public UrlLabel(String url, String description) {
    4356        this (url, description, 0);
    4457    }
    4558
     59    /**
     60     * Constructs a new {@code UrlLabel} for the given URL, description and font increase.
     61     * @param url The URL to use
     62     * @param description The description to display
     63     * @param fontPlus The font increase in 1/72 of an inch units.
     64     */
    4665    public UrlLabel(String url, String description, int fontPlus) {
    4766        this();
     
    5473    }
    5574
    56     protected void refresh() {
     75    protected final void refresh() {
    5776        if (url != null) {
    5877            setText("<html><a href=\""+url+"\">"+description+"</a></html>");
     
    7291     * @param url the url. Can be null.
    7392     */
    74     public void setUrl(String url) {
     93    public final void setUrl(String url) {
    7594        this.url = url;
    7695        refresh();
     
    82101     * @param description the description
    83102     */
    84     public void setDescription(String description) {
     103    public final void setDescription(String description) {
    85104        this.description = description == null? "" : description;
    86105        this.description = this.description.replace("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;");
     
    90109    @Override
    91110    public void mouseClicked(MouseEvent e) {
    92         if( SwingUtilities.isLeftMouseButton(e) ) {
     111        if (SwingUtilities.isLeftMouseButton(e)) {
    93112            OpenBrowser.displayUrl(url);
    94         } else if( SwingUtilities.isRightMouseButton(e) ) {
     113        } else if (SwingUtilities.isRightMouseButton(e)) {
    95114            Utils.copyToClipboard(url);
    96115        }
    97116    }
     117   
    98118    @Override
    99     public void mousePressed(MouseEvent e) {    }
     119    public void mousePressed(MouseEvent e) {
     120        // Ignored
     121    }
     122   
    100123    @Override
    101     public void mouseEntered(MouseEvent e) {    }
     124    public void mouseEntered(MouseEvent e) {
     125        // Ignored
     126    }
     127   
    102128    @Override
    103     public void mouseExited(MouseEvent e) {    }
     129    public void mouseExited(MouseEvent e) {
     130        // Ignored
     131    }
     132   
    104133    @Override
    105     public void mouseReleased(MouseEvent e) {    }
    106 
     134    public void mouseReleased(MouseEvent e) {
     135        // Ignored
     136    }
    107137}
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r6360 r6365  
    4646    public static final IntegerProperty PROP_INTERVAL = new IntegerProperty("message.notifier.interval", 5);
    4747   
    48     private static final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
     48    private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor();
    4949   
    50     private static final Runnable worker = new Worker();
     50    private static final Runnable WORKER = new Worker();
    5151   
    5252    private static ScheduledFuture<?> task = null;
     
    8989        int interval = PROP_INTERVAL.get();
    9090        if (!isRunning() && interval > 0 && isUserEnoughIdentified()) {
    91             task = executor.scheduleAtFixedRate(worker, 0, interval * 60, TimeUnit.SECONDS);
     91            task = EXECUTOR.scheduleAtFixedRate(WORKER, 0, interval * 60, TimeUnit.SECONDS);
    9292            Main.info("Message notifier active (checks every "+interval+" minute"+(interval>1?"s":"")+")");
    9393        }
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r6349 r6365  
    121121                    userInfo.setUnreadMessages(Integer.parseInt(v));
    122122                } catch(NumberFormatException e) {
    123                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v));
     123                    throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
    124124                }
    125125            }
  • trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java

    r6362 r6365  
    1111/**
    1212 * This is the default authenticator used in JOSM. It delegates lookup of credentials
    13  * for the OSM API and an optional proxy server to the currently configured
    14  * {@link CredentialsManager}.
    15  *
     13 * for the OSM API and an optional proxy server to the currently configured {@link CredentialsManager}.
     14 * @since 2641
    1615 */
    1716public final class DefaultAuthenticator extends Authenticator {
    1817    private static DefaultAuthenticator instance;
    1918
     19    /**
     20     * Returns the unique instance
     21     * @return The unique instance
     22     */
    2023    public static DefaultAuthenticator getInstance() {
    2124        return instance;
    2225    }
    2326
     27    /**
     28     * Creates the unique instance
     29     */
    2430    public static void createInstance() {
    2531        instance = new DefaultAuthenticator();
     
    3339
    3440    /**
    35      * Called by the Java http stack when either the OSM API server or a proxy requires
    36      * authentication.
    37      *
     41     * Called by the Java HTTP stack when either the OSM API server or a proxy requires authentication.
    3842     */
    39     @Override protected PasswordAuthentication getPasswordAuthentication() {
     43    @Override
     44    protected PasswordAuthentication getPasswordAuthentication() {
    4045        if (!enabled)
    4146            return null;
    4247        try {
    43             if (getRequestorType().equals(Authenticator.RequestorType.SERVER)) {
     48            if (getRequestorType().equals(Authenticator.RequestorType.SERVER) && OsmApi.isUsingOAuth()) {
    4449                // if we are working with OAuth we don't prompt for a password
    45                 if (OsmApi.isUsingOAuth())
    46                     return null;
     50                return null;
    4751            }
    4852            boolean tried = credentialsTried.get(getRequestorType()) != null;
Note: See TracChangeset for help on using the changeset viewer.