Ignore:
Timestamp:
2016-07-23T18:46:45+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

Location:
trunk/src/org/openstreetmap/josm/gui/preferences/plugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginListPanel.java

    r10228 r10611  
    1515import javax.swing.SwingConstants;
    1616import javax.swing.SwingUtilities;
    17 import javax.swing.event.HyperlinkEvent;
    1817import javax.swing.event.HyperlinkEvent.EventType;
    19 import javax.swing.event.HyperlinkListener;
    2018
    2119import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     
    151149            HtmlPanel description = new HtmlPanel();
    152150            description.setText(pi.getDescriptionAsHtml());
    153             description.getEditorPane().addHyperlinkListener(new HyperlinkListener() {
    154                 @Override
    155                 public void hyperlinkUpdate(HyperlinkEvent e) {
    156                     if (e.getEventType() == EventType.ACTIVATED) {
    157                         OpenBrowser.displayUrl(e.getURL().toString());
    158                     }
     151            description.getEditorPane().addHyperlinkListener(e -> {
     152                if (e.getEventType() == EventType.ACTIVATED) {
     153                    OpenBrowser.displayUrl(e.getURL().toString());
    159154                }
    160155            });
     
    170165        repaint();
    171166        if (visibleRect != null && visibleRect.width > 0 && visibleRect.height > 0) {
    172             SwingUtilities.invokeLater(new Runnable() {
    173                 @Override
    174                 public void run() {
    175                     scrollRectToVisible(visibleRect);
    176                 }
    177             });
     167            SwingUtilities.invokeLater(() -> scrollRectToVisible(visibleRect));
    178168        }
    179169    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r10482 r10611  
    150150        sb.append("</html>");
    151151        if (!GraphicsEnvironment.isHeadless()) {
    152             GuiHelper.runInEDTAndWait(new Runnable() {
    153                 @Override
    154                 public void run() {
    155                     HelpAwareOptionPane.showOptionDialog(
    156                             parent,
    157                             sb.toString(),
    158                             tr("Update plugins"),
    159                             !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
    160                                     HelpUtil.ht("/Preferences/Plugins")
    161                             );
    162                 }
    163             });
     152            GuiHelper.runInEDTAndWait(() -> HelpAwareOptionPane.showOptionDialog(
     153                    parent,
     154                    sb.toString(),
     155                    tr("Update plugins"),
     156                    !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
     157                            HelpUtil.ht("/Preferences/Plugins")
     158                    ));
    164159        }
    165160    }
     
    318313    public void readLocalPluginInformation() {
    319314        final ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask();
    320         Runnable r = new Runnable() {
    321             @Override
    322             public void run() {
    323                 if (!task.isCanceled()) {
    324                     SwingUtilities.invokeLater(new Runnable() {
    325                         @Override
    326                         public void run() {
    327                             model.setAvailablePlugins(task.getAvailablePlugins());
    328                             pnlPluginPreferences.refreshView();
    329                         }
    330                     });
    331                 }
     315        Runnable r = () -> {
     316            if (!task.isCanceled()) {
     317                SwingUtilities.invokeLater(() -> {
     318                    model.setAvailablePlugins(task.getAvailablePlugins());
     319                    pnlPluginPreferences.refreshView();
     320                });
    332321            }
    333322        };
     
    357346            }
    358347            final ReadRemotePluginInformationTask task = new ReadRemotePluginInformationTask(pluginSites);
    359             Runnable continuation = new Runnable() {
    360                 @Override
    361                 public void run() {
    362                     if (!task.isCanceled()) {
    363                         SwingUtilities.invokeLater(new Runnable() {
    364                             @Override
    365                             public void run() {
    366                                 model.updateAvailablePlugins(task.getAvailablePlugins());
    367                                 pnlPluginPreferences.refreshView();
    368                                 Main.pref.putInteger("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030
    369                             }
    370                         });
    371                     }
     348            Runnable continuation = () -> {
     349                if (!task.isCanceled()) {
     350                    SwingUtilities.invokeLater(() -> {
     351                        model.updateAvailablePlugins(task.getAvailablePlugins());
     352                        pnlPluginPreferences.refreshView();
     353                        Main.pref.putInteger("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030
     354                    });
    372355                }
    373356            };
     
    389372        protected void alertNothingToUpdate() {
    390373            try {
    391                 SwingUtilities.invokeAndWait(new Runnable() {
    392                     @Override
    393                     public void run() {
    394                         HelpAwareOptionPane.showOptionDialog(
    395                                 pnlPluginPreferences,
    396                                 tr("All installed plugins are up to date. JOSM does not have to download newer versions."),
    397                                 tr("Plugins up to date"),
    398                                 JOptionPane.INFORMATION_MESSAGE,
    399                                 null // FIXME: provide help context
    400                                 );
    401                     }
    402                 });
     374                SwingUtilities.invokeAndWait(() -> HelpAwareOptionPane.showOptionDialog(
     375                        pnlPluginPreferences,
     376                        tr("All installed plugins are up to date. JOSM does not have to download newer versions."),
     377                        tr("Plugins up to date"),
     378                        JOptionPane.INFORMATION_MESSAGE,
     379                        null // FIXME: provide help context
     380                        ));
    403381            } catch (InterruptedException | InvocationTargetException e) {
    404382                Main.error(e);
     
    421399            // to be run asynchronously after the plugin download
    422400            //
    423             final Runnable pluginDownloadContinuation = new Runnable() {
    424                 @Override
    425                 public void run() {
    426                     if (pluginDownloadTask.isCanceled())
    427                         return;
    428                     boolean restartRequired = false;
    429                     for (PluginInformation pi : pluginDownloadTask.getDownloadedPlugins()) {
    430                         if (!model.getNewlyActivatedPlugins().contains(pi) || !pi.canloadatruntime) {
    431                             restartRequired = true;
    432                             break;
    433                         }
    434                     }
    435                     notifyDownloadResults(pnlPluginPreferences, pluginDownloadTask, restartRequired);
    436                     model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins());
    437                     model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins());
    438                     GuiHelper.runInEDT(new Runnable() {
    439                         @Override
    440                         public void run() {
    441                             pnlPluginPreferences.refreshView();
    442                         }
    443                     });
    444                 }
     401            final Runnable pluginDownloadContinuation = () -> {
     402                if (pluginDownloadTask.isCanceled())
     403                    return;
     404                boolean restartRequired = false;
     405                for (PluginInformation pi : pluginDownloadTask.getDownloadedPlugins()) {
     406                    if (!model.getNewlyActivatedPlugins().contains(pi) || !pi.canloadatruntime) {
     407                        restartRequired = true;
     408                        break;
     409                    }
     410                }
     411                notifyDownloadResults(pnlPluginPreferences, pluginDownloadTask, restartRequired);
     412                model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins());
     413                model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins());
     414                GuiHelper.runInEDT(pnlPluginPreferences::refreshView);
    445415            };
    446416
    447417            // to be run asynchronously after the plugin list download
    448418            //
    449             final Runnable pluginInfoDownloadContinuation = new Runnable() {
    450                 @Override
    451                 public void run() {
    452                     if (pluginInfoDownloadTask.isCanceled())
    453                         return;
    454                     model.updateAvailablePlugins(pluginInfoDownloadTask.getAvailablePlugins());
    455                     // select plugins which actually have to be updated
    456                     //
    457                     Iterator<PluginInformation> it = toUpdate.iterator();
    458                     while (it.hasNext()) {
    459                         PluginInformation pi = it.next();
    460                         if (!pi.isUpdateRequired()) {
    461                             it.remove();
    462                         }
    463                     }
    464                     if (toUpdate.isEmpty()) {
    465                         alertNothingToUpdate();
    466                         return;
    467                     }
    468                     pluginDownloadTask.setPluginsToDownload(toUpdate);
    469                     Main.worker.submit(pluginDownloadTask);
    470                     Main.worker.submit(pluginDownloadContinuation);
    471                 }
     419            final Runnable pluginInfoDownloadContinuation = () -> {
     420                if (pluginInfoDownloadTask.isCanceled())
     421                    return;
     422                model.updateAvailablePlugins(pluginInfoDownloadTask.getAvailablePlugins());
     423                // select plugins which actually have to be updated
     424                //
     425                Iterator<PluginInformation> it = toUpdate.iterator();
     426                while (it.hasNext()) {
     427                    PluginInformation pi = it.next();
     428                    if (!pi.isUpdateRequired()) {
     429                        it.remove();
     430                    }
     431                }
     432                if (toUpdate.isEmpty()) {
     433                    alertNothingToUpdate();
     434                    return;
     435                }
     436                pluginDownloadTask.setPluginsToDownload(toUpdate);
     437                Main.worker.submit(pluginDownloadTask);
     438                Main.worker.submit(pluginDownloadContinuation);
    472439            };
    473440
     
    476443        }
    477444    }
    478 
    479445
    480446    /**
     
    509475
    510476        @Override
    511         public void changedUpdate(DocumentEvent arg0) {
     477        public void changedUpdate(DocumentEvent evt) {
    512478            filter();
    513479        }
    514480
    515481        @Override
    516         public void insertUpdate(DocumentEvent arg0) {
     482        public void insertUpdate(DocumentEvent evt) {
    517483            filter();
    518484        }
    519485
    520486        @Override
    521         public void removeUpdate(DocumentEvent arg0) {
     487        public void removeUpdate(DocumentEvent evt) {
    522488            filter();
    523489        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r10210 r10611  
    66import java.util.Collection;
    77import java.util.Collections;
    8 import java.util.Comparator;
    98import java.util.HashMap;
    109import java.util.HashSet;
     
    150149        Collections.sort(
    151150                availablePlugins,
    152                 new Comparator<PluginInformation>() {
    153                     @Override
    154                     public int compare(PluginInformation o1, PluginInformation o2) {
    155                         String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase(Locale.ENGLISH);
    156                         String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase(Locale.ENGLISH);
    157                         return n1.compareTo(n2);
    158                     }
     151                (o1, o2) -> {
     152                    String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase(Locale.ENGLISH);
     153                    String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase(Locale.ENGLISH);
     154                    return n1.compareTo(n2);
    159155                }
    160156        );
Note: See TracChangeset for help on using the changeset viewer.