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
Files:
26 edited

Legend:

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

    r10369 r10611  
    1212import java.awt.Insets;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.ActionListener;
    1514import java.awt.event.KeyEvent;
    1615import java.awt.event.WindowAdapter;
     
    1918import javax.swing.AbstractAction;
    2019import javax.swing.BorderFactory;
     20import javax.swing.JButton;
    2121import javax.swing.JCheckBox;
    2222import javax.swing.JComponent;
    23 import javax.swing.JButton;
    2423import javax.swing.JDialog;
    2524import javax.swing.JPanel;
     
    5857        JCheckBox expert = new JCheckBox(tr("Expert mode"));
    5958        expert.setSelected(ExpertToggleAction.isExpert());
    60         expert.addActionListener(new ActionListener() {
    61             @Override
    62             public void actionPerformed(ActionEvent e) {
    63                 ExpertToggleAction.getInstance().actionPerformed(null);
    64             }
    65         });
     59        expert.addActionListener(e -> ExpertToggleAction.getInstance().actionPerformed(null));
    6660
    6761        JPanel btns = new JPanel(new FlowLayout(FlowLayout.CENTER));
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r10600 r10611  
    322322
    323323    public void selectTabByName(String name) {
    324         selectTabBy(new TabIdentifier() {
    325             @Override
    326             public boolean identify(TabPreferenceSetting tps, Object name) {
    327                 return name != null && tps != null && tps.getIconName() != null && name.equals(tps.getIconName());
    328             }
    329         }, name);
     324        selectTabBy((tps, name1) -> name1 != null && tps != null && tps.getIconName() != null && name1.equals(tps.getIconName()), name);
    330325    }
    331326
    332327    public void selectTabByPref(Class<? extends TabPreferenceSetting> clazz) {
    333         selectTabBy(new TabIdentifier() {
    334             @Override
    335             public boolean identify(TabPreferenceSetting tps, Object clazz) {
    336                 return tps.getClass().isAssignableFrom((Class<?>) clazz);
    337             }
    338         }, clazz);
     328        selectTabBy((tps, clazz1) -> tps.getClass().isAssignableFrom((Class<?>) clazz1), clazz);
    339329    }
    340330
     
    344334                final SubPreferenceSetting sub = (SubPreferenceSetting) setting;
    345335                final TabPreferenceSetting tab = sub.getTabPreferenceSetting(this);
    346                 selectTabBy(new TabIdentifier() {
    347                     @Override
    348                     public boolean identify(TabPreferenceSetting tps, Object unused) {
    349                         return tps.equals(tab);
    350                     }
    351                 }, null);
     336                selectTabBy((tps, unused) -> tps.equals(tab), null);
    352337                return tab.selectSubTab(sub);
    353338            }
     
    419404    public void savePreferences() {
    420405        // create a task for downloading plugins if the user has activated, yet not downloaded, new plugins
    421         //
    422406        final PluginPreference preference = getPluginPreference();
    423407        final Set<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload();
     
    430414
    431415        // this is the task which will run *after* the plugins are downloaded
    432         //
    433416        final Runnable continuation = new PluginDownloadAfterTask(preference, task, toDownload);
    434417
     
    436419            // if we have to launch a plugin download task we do it asynchronously, followed
    437420            // by the remaining "save preferences" activites run on the Swing EDT.
    438             //
    439421            Main.worker.submit(task);
    440             Main.worker.submit(
    441                     new Runnable() {
    442                         @Override
    443                         public void run() {
    444                             SwingUtilities.invokeLater(continuation);
    445                         }
    446                     }
    447                     );
     422            Main.worker.submit(() -> SwingUtilities.invokeLater(continuation));
    448423        } else {
    449424            // no need for asynchronous activities. Simply run the remaining "save preference"
    450425            // activities on this thread (we are already on the Swing EDT
    451             //
    452426            continuation.run();
    453427        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r10482 r10611  
    1818import java.awt.event.MouseAdapter;
    1919import java.awt.event.MouseEvent;
    20 import java.beans.PropertyChangeEvent;
    21 import java.beans.PropertyChangeListener;
    2220import java.io.BufferedReader;
    2321import java.io.File;
     
    2927import java.util.Collection;
    3028import java.util.Collections;
    31 import java.util.Comparator;
    3229import java.util.EventObject;
    3330import java.util.HashMap;
     
    6663import javax.swing.event.CellEditorListener;
    6764import javax.swing.event.ChangeEvent;
    68 import javax.swing.event.ChangeListener;
    6965import javax.swing.event.DocumentEvent;
    7066import javax.swing.event.DocumentListener;
     
    165161        }
    166162
    167         activeSourcesModel.addTableModelListener(new TableModelListener() {
    168             @Override
    169             public void tableChanged(TableModelEvent e) {
    170                 listCellRenderer.updateSources(activeSourcesModel.getSources());
    171                 lstAvailableSources.repaint();
    172             }
     163        activeSourcesModel.addTableModelListener(e -> {
     164            listCellRenderer.updateSources(activeSourcesModel.getSources());
     165            lstAvailableSources.repaint();
    173166        });
    174         tblActiveSources.addPropertyChangeListener(new PropertyChangeListener() {
    175             @Override
    176             public void propertyChange(PropertyChangeEvent evt) {
    177                 listCellRenderer.updateSources(activeSourcesModel.getSources());
    178                 lstAvailableSources.repaint();
    179             }
     167        tblActiveSources.addPropertyChangeListener(evt -> {
     168            listCellRenderer.updateSources(activeSourcesModel.getSources());
     169            lstAvailableSources.repaint();
    180170        });
    181         activeSourcesModel.addTableModelListener(new TableModelListener() {
    182             // Force swing to show horizontal scrollbars for the JTable
    183             // Yes, this is a little ugly, but should work
    184             @Override
    185             public void tableChanged(TableModelEvent e) {
    186                 TableHelper.adjustColumnWidth(tblActiveSources, canEnable ? 1 : 0, 800);
    187             }
    188         });
     171        // Force Swing to show horizontal scrollbars for the JTable
     172        // Yes, this is a little ugly, but should work
     173        activeSourcesModel.addTableModelListener(e -> TableHelper.adjustColumnWidth(tblActiveSources, canEnable ? 1 : 0, 800));
    189174        activeSourcesModel.setActiveSources(getInitialSourcesList());
    190175
     
    12381223
    12391224        protected void sort() {
    1240             Collections.sort(
    1241                     data,
    1242                     new Comparator<String>() {
    1243                         @Override
    1244                         public int compare(String o1, String o2) {
    1245                             if (o1.isEmpty() && o2.isEmpty())
    1246                                 return 0;
    1247                             if (o1.isEmpty()) return 1;
    1248                             if (o2.isEmpty()) return -1;
    1249                             return o1.compareTo(o2);
    1250                         }
    1251                     }
    1252                     );
     1225            Collections.sort(data,
     1226                    (o1, o2) -> {
     1227                        if (o1.isEmpty() && o2.isEmpty())
     1228                            return 0;
     1229                        if (o1.isEmpty()) return 1;
     1230                        if (o2.isEmpty()) return -1;
     1231                        return o1.compareTo(o2);
     1232                    });
    12531233        }
    12541234
     
    13801360            final String msg = tr(getStr(I18nString.FAILED_TO_LOAD_SOURCES_FROM), url, emsg);
    13811361
    1382             GuiHelper.runInEDT(new Runnable() {
    1383                 @Override
    1384                 public void run() {
    1385                     HelpAwareOptionPane.showOptionDialog(
    1386                             Main.parent,
    1387                             msg,
    1388                             tr("Error"),
    1389                             JOptionPane.ERROR_MESSAGE,
    1390                             ht(getStr(I18nString.FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC))
    1391                             );
    1392                 }
    1393             });
     1362            GuiHelper.runInEDT(() -> HelpAwareOptionPane.showOptionDialog(
     1363                    Main.parent,
     1364                    msg,
     1365                    tr("Error"),
     1366                    JOptionPane.ERROR_MESSAGE,
     1367                    ht(getStr(I18nString.FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC))
     1368                    ));
    13941369        }
    13951370
     
    17461721     */
    17471722    public final void deferLoading(final DefaultTabPreferenceSetting tab, final Component component) {
    1748         tab.getTabPane().addChangeListener(
    1749                 new ChangeListener() {
    1750                     @Override
    1751                     public void stateChanged(ChangeEvent e) {
    1752                         if (tab.getTabPane().getSelectedComponent() == component) {
    1753                             SourceEditor.this.initiallyLoadAvailableSources();
    1754                         }
    1755                     }
    1756                 }
    1757                 );
     1723        tab.getTabPane().addChangeListener(e -> {
     1724            if (tab.getTabPane().getSelectedComponent() == component) {
     1725                SourceEditor.this.initiallyLoadAvailableSources();
     1726            }
     1727        });
    17581728    }
    17591729
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r10378 r10611  
    1818import java.awt.event.InputEvent;
    1919import java.awt.event.KeyEvent;
    20 import java.beans.PropertyChangeEvent;
    21 import java.beans.PropertyChangeListener;
    2220import java.io.IOException;
    2321import java.util.ArrayList;
     
    5149import javax.swing.MenuElement;
    5250import javax.swing.TransferHandler;
    53 import javax.swing.event.ListSelectionEvent;
    54 import javax.swing.event.ListSelectionListener;
    5551import javax.swing.event.PopupMenuEvent;
    5652import javax.swing.event.PopupMenuListener;
    57 import javax.swing.event.TreeSelectionEvent;
    58 import javax.swing.event.TreeSelectionListener;
    5953import javax.swing.table.AbstractTableModel;
    6054import javax.swing.tree.DefaultMutableTreeNode;
     
    6963import org.openstreetmap.josm.actions.ParameterizedAction;
    7064import org.openstreetmap.josm.actions.ParameterizedActionDecorator;
    71 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    72 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    7365import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    7466import org.openstreetmap.josm.tools.GBC;
     
    762754            };
    763755            selectedList.setCellRenderer(renderer);
    764             selectedList.addListSelectionListener(new ListSelectionListener() {
    765                 @Override
    766                 public void valueChanged(ListSelectionEvent e) {
    767                     boolean sel = selectedList.getSelectedIndex() != -1;
    768                     if (sel) {
    769                         actionsTree.clearSelection();
    770                         ActionDefinition action = selected.get(selectedList.getSelectedIndex());
    771                         actionParametersModel.setCurrentAction(action);
    772                         actionParametersPanel.setVisible(actionParametersModel.getRowCount() > 0);
    773                     }
    774                     updateEnabledState();
    775                 }
     756            selectedList.addListSelectionListener(e -> {
     757                boolean sel = selectedList.getSelectedIndex() != -1;
     758                if (sel) {
     759                    actionsTree.clearSelection();
     760                    ActionDefinition action = selected.get(selectedList.getSelectedIndex());
     761                    actionParametersModel.setCurrentAction(action);
     762                    actionParametersPanel.setVisible(actionParametersModel.getRowCount() > 0);
     763                }
     764                updateEnabledState();
    776765            });
    777766
     
    804793            });
    805794            actionsTree.setDragEnabled(true);
    806             actionsTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    807                 @Override public void valueChanged(TreeSelectionEvent e) {
    808                     updateEnabledState();
    809                 }
    810             });
     795            actionsTree.getSelectionModel().addTreeSelectionListener(e -> updateEnabledState());
    811796
    812797            final JPanel left = new JPanel(new GridBagLayout());
     
    914899        control.setFloatable(false);
    915900        control.setComponentPopupMenu(popupMenu);
    916         Main.pref.addPreferenceChangeListener(new PreferenceChangedListener() {
    917             @Override
    918             public void preferenceChanged(PreferenceChangeEvent e) {
    919                 if ("toolbar.visible".equals(e.getKey())) {
    920                     refreshToolbarControl();
    921                 }
     901        Main.pref.addPreferenceChangeListener(e -> {
     902            if ("toolbar.visible".equals(e.getKey())) {
     903                refreshToolbarControl();
    922904            }
    923905        });
     
    10781060                } else {
    10791061                    // hide action text if an icon is set later (necessary for delayed/background image loading)
    1080                     action.getParametrizedAction().addPropertyChangeListener(new PropertyChangeListener() {
    1081 
    1082                         @Override
    1083                         public void propertyChange(PropertyChangeEvent evt) {
    1084                             if (Action.SMALL_ICON.equals(evt.getPropertyName())) {
    1085                                 b.setHideActionText(evt.getNewValue() != null);
    1086                             }
     1062                    action.getParametrizedAction().addPropertyChangeListener(evt -> {
     1063                        if (Action.SMALL_ICON.equals(evt.getPropertyName())) {
     1064                            b.setHideActionText(evt.getNewValue() != null);
    10871065                        }
    10881066                    });
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r9759 r10611  
    7575    private final Map<String, String> profileTypes = new LinkedHashMap<>();
    7676
    77     private final Comparator<PrefEntry> customComparator = new Comparator<PrefEntry>() {
    78         @Override
    79         public int compare(PrefEntry o1, PrefEntry o2) {
    80             if (o1.isChanged() && !o2.isChanged())
    81                 return -1;
    82             if (o2.isChanged() && !o1.isChanged())
    83                 return 1;
    84             if (!(o1.isDefault()) && o2.isDefault())
    85                 return -1;
    86             if (!(o2.isDefault()) && o1.isDefault())
    87                 return 1;
    88             return o1.compareTo(o2);
    89         }
     77    private final Comparator<PrefEntry> customComparator = (o1, o2) -> {
     78        if (o1.isChanged() && !o2.isChanged())
     79            return -1;
     80        if (o2.isChanged() && !o1.isChanged())
     81            return 1;
     82        if (!(o1.isDefault()) && o2.isDefault())
     83            return -1;
     84        if (!(o2.isDefault()) && o1.isDefault())
     85            return 1;
     86        return o1.compareTo(o2);
    9087    };
    9188
     
    139136        p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    140137        p.add(add, GBC.std().insets(0, 5, 0, 0));
    141         add.addActionListener(new ActionListener() {
    142             @Override public void actionPerformed(ActionEvent e) {
    143                 PrefEntry pe = table.addPreference(gui);
    144                 if (pe != null) {
    145                     allData.add(pe);
    146                     Collections.sort(allData);
    147                     applyFilter();
    148                 }
     138        add.addActionListener(e -> {
     139            PrefEntry pe = table.addPreference(gui);
     140            if (pe != null) {
     141                allData.add(pe);
     142                Collections.sort(allData);
     143                applyFilter();
    149144            }
    150145        });
     
    152147        JButton edit = new JButton(tr("Edit"));
    153148        p.add(edit, GBC.std().insets(5, 5, 5, 0));
    154         edit.addActionListener(new ActionListener() {
    155             @Override public void actionPerformed(ActionEvent e) {
    156                 if (table.editPreference(gui))
    157                     applyFilter();
    158             }
     149        edit.addActionListener(e -> {
     150            if (table.editPreference(gui))
     151                applyFilter();
    159152        });
    160153
    161154        JButton reset = new JButton(tr("Reset"));
    162155        p.add(reset, GBC.std().insets(0, 5, 0, 0));
    163         reset.addActionListener(new ActionListener() {
    164             @Override public void actionPerformed(ActionEvent e) {
    165                 table.resetPreferences(gui);
    166             }
    167         });
     156        reset.addActionListener(e -> table.resetPreferences(gui));
    168157
    169158        JButton read = new JButton(tr("Read from file"));
    170159        p.add(read, GBC.std().insets(5, 5, 0, 0));
    171         read.addActionListener(new ActionListener() {
    172             @Override public void actionPerformed(ActionEvent e) {
    173                 readPreferencesFromXML();
    174             }
    175         });
     160        read.addActionListener(e -> readPreferencesFromXML());
    176161
    177162        JButton export = new JButton(tr("Export selected items"));
    178163        p.add(export, GBC.std().insets(5, 5, 0, 0));
    179         export.addActionListener(new ActionListener() {
    180             @Override public void actionPerformed(ActionEvent e) {
    181                 exportSelectedToXML();
    182             }
    183         });
     164        export.addActionListener(e -> exportSelectedToXML());
    184165
    185166        final JButton more = new JButton(tr("More..."));
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ListEditor.java

    r10047 r10611  
    1919import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2020import org.openstreetmap.josm.tools.GBC;
    21 import org.openstreetmap.josm.tools.Predicate;
    2221import org.openstreetmap.josm.tools.Utils;
    2322
     
    4443    @Override
    4544    public List<String> getData() {
    46         return new ArrayList<>(Utils.filter(model.getData(), new Predicate<String>() {
    47             @Override
    48             public boolean evaluate(String object) {
    49                 return object != null && !object.isEmpty();
    50             }
    51         }));
     45        return new ArrayList<>(Utils.filter(model.getData(), object -> object != null && !object.isEmpty()));
    5246    }
    5347
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r10001 r10611  
    55
    66import java.awt.Color;
    7 import java.awt.Component;
    87import java.awt.Dimension;
    98import java.awt.GridBagLayout;
    10 import java.awt.event.ActionEvent;
    11 import java.awt.event.ActionListener;
    129import java.awt.event.MouseAdapter;
    1310import java.awt.event.MouseEvent;
     
    156153
    157154        colorEdit = new JButton(tr("Choose"));
    158         colorEdit.addActionListener(new ActionListener() {
    159             @Override
    160             public void actionPerformed(ActionEvent e) {
    161                 int sel = colors.getSelectedRow();
    162                 JColorChooser chooser = new JColorChooser((Color) colors.getValueAt(sel, 1));
    163                 int answer = JOptionPane.showConfirmDialog(
    164                         gui, chooser,
    165                         tr("Choose a color for {0}", getName((String) colors.getValueAt(sel, 0))),
    166                         JOptionPane.OK_CANCEL_OPTION,
    167                         JOptionPane.PLAIN_MESSAGE);
    168                 if (answer == JOptionPane.OK_OPTION) {
    169                     colors.setValueAt(chooser.getColor(), sel, 1);
    170                 }
     155        colorEdit.addActionListener(e -> {
     156            int sel = colors.getSelectedRow();
     157            JColorChooser chooser = new JColorChooser((Color) colors.getValueAt(sel, 1));
     158            int answer = JOptionPane.showConfirmDialog(
     159                    gui, chooser,
     160                    tr("Choose a color for {0}", getName((String) colors.getValueAt(sel, 0))),
     161                    JOptionPane.OK_CANCEL_OPTION,
     162                    JOptionPane.PLAIN_MESSAGE);
     163            if (answer == JOptionPane.OK_OPTION) {
     164                colors.setValueAt(chooser.getColor(), sel, 1);
    171165            }
    172166        });
    173167        defaultSet = new JButton(tr("Set to default"));
    174         defaultSet.addActionListener(new ActionListener() {
    175             @Override
    176             public void actionPerformed(ActionEvent e) {
    177                 int sel = colors.getSelectedRow();
    178                 String name = (String) colors.getValueAt(sel, 0);
     168        defaultSet.addActionListener(e -> {
     169            int sel = colors.getSelectedRow();
     170            String name = (String) colors.getValueAt(sel, 0);
     171            Color c = Main.pref.getDefaultColor(name);
     172            if (c != null) {
     173                colors.setValueAt(c, sel, 1);
     174            }
     175        });
     176        JButton defaultAll = new JButton(tr("Set all to default"));
     177        defaultAll.addActionListener(e -> {
     178            for (int i = 0; i < colors.getRowCount(); ++i) {
     179                String name = (String) colors.getValueAt(i, 0);
    179180                Color c = Main.pref.getDefaultColor(name);
    180181                if (c != null) {
    181                     colors.setValueAt(c, sel, 1);
     182                    colors.setValueAt(c, i, 1);
    182183                }
    183184            }
    184185        });
    185         JButton defaultAll = new JButton(tr("Set all to default"));
    186         defaultAll.addActionListener(new ActionListener() {
    187             @Override
    188             public void actionPerformed(ActionEvent e) {
    189                 for (int i = 0; i < colors.getRowCount(); ++i) {
    190                     String name = (String) colors.getValueAt(i, 0);
    191                     Color c = Main.pref.getDefaultColor(name);
    192                     if (c != null) {
    193                         colors.setValueAt(c, i, 1);
    194                     }
    195                 }
    196             }
    197         });
    198186        remove = new JButton(tr("Remove"));
    199         remove.addActionListener(new ActionListener() {
    200             @Override
    201             public void actionPerformed(ActionEvent e) {
    202                 int sel = colors.getSelectedRow();
    203                 del.add((String) colors.getValueAt(sel, 0));
    204                 tableModel.removeRow(sel);
    205             }
     187        remove.addActionListener(e -> {
     188            int sel = colors.getSelectedRow();
     189            del.add((String) colors.getValueAt(sel, 0));
     190            tableModel.removeRow(sel);
    206191        });
    207192        remove.setEnabled(false);
     
    233218        colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    234219        final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class);
    235         colors.setDefaultRenderer(Object.class, new TableCellRenderer() {
    236             @Override
    237             public Component getTableCellRendererComponent(JTable t, Object o, boolean selected, boolean focus, int row, int column) {
    238                 if (o == null)
    239                     return new JLabel();
    240                 if (column == 1) {
    241                     Color c = (Color) o;
    242                     JLabel l = new JLabel(ColorHelper.color2html(c));
    243                     GuiHelper.setBackgroundReadable(l, c);
    244                     l.setOpaque(true);
    245                     return l;
    246                 }
    247                 return oldColorsRenderer.getTableCellRendererComponent(t, getName(o.toString()), selected, focus, row, column);
    248             }
     220        colors.setDefaultRenderer(Object.class, (t, o, selected, focus, row, column) -> {
     221            if (o == null)
     222                return new JLabel();
     223            if (column == 1) {
     224                Color c = (Color) o;
     225                JLabel l = new JLabel(ColorHelper.color2html(c));
     226                GuiHelper.setBackgroundReadable(l, c);
     227                l.setOpaque(true);
     228                return l;
     229            }
     230            return oldColorsRenderer.getTableCellRendererComponent(t, getName(o.toString()), selected, focus, row, column);
    249231        });
    250232        colors.getColumnModel().getColumn(1).setWidth(100);
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/DrawingPreference.java

    r9778 r10611  
    55
    66import java.awt.GridBagLayout;
    7 import java.awt.event.ActionEvent;
    8 import java.awt.event.ActionListener;
    97
    108import javax.swing.BorderFactory;
     
    7169
    7270        // directionHint
    73         directionHint.addActionListener(new ActionListener() {
    74             @Override
    75             public void actionPerformed(ActionEvent e) {
    76                 if (directionHint.isSelected()) {
    77                     headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
    78                 } else {
    79                     headArrow.setSelected(false);
    80                 }
    81                 headArrow.setEnabled(directionHint.isSelected());
     71        directionHint.addActionListener(e -> {
     72            if (directionHint.isSelected()) {
     73                headArrow.setSelected(Main.pref.getBoolean("draw.segment.head_only", false));
     74            } else {
     75                headArrow.setSelected(false);
    8276            }
     77            headArrow.setEnabled(directionHint.isSelected());
    8378        });
    8479        directionHint.setToolTipText(tr("Draw direction hints for way segments."));
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

    r10378 r10611  
    77import java.awt.Component;
    88import java.awt.GridBagLayout;
    9 import java.awt.event.ActionEvent;
    109import java.awt.event.ActionListener;
    1110
     
    1817import javax.swing.JPanel;
    1918import javax.swing.JRadioButton;
    20 import javax.swing.event.ChangeEvent;
    21 import javax.swing.event.ChangeListener;
    2219
    2320import org.openstreetmap.josm.Main;
     
    140137        ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesAll);
    141138
    142         drawRawGpsLinesActionListener = new ActionListener() {
    143             @Override
    144             public void actionPerformed(ActionEvent e) {
    145                 boolean f = drawRawGpsLinesNone.isSelected() || drawRawGpsLinesGlobal.isSelected();
    146                 forceRawGpsLines.setEnabled(!f);
    147                 drawRawGpsMaxLineLength.setEnabled(!(f || drawRawGpsLinesLocal.isSelected()));
    148                 drawRawGpsMaxLineLengthLocal.setEnabled(!f);
    149                 drawGpsArrows.setEnabled(!f);
    150                 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    151                 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    152             }
     139        drawRawGpsLinesActionListener = e -> {
     140            boolean f = drawRawGpsLinesNone.isSelected() || drawRawGpsLinesGlobal.isSelected();
     141            forceRawGpsLines.setEnabled(!f);
     142            drawRawGpsMaxLineLength.setEnabled(!(f || drawRawGpsLinesLocal.isSelected()));
     143            drawRawGpsMaxLineLengthLocal.setEnabled(!f);
     144            drawGpsArrows.setEnabled(!f);
     145            drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
     146            drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    153147        };
    154148
     
    181175
    182176        // drawGpsArrows
    183         drawGpsArrows.addActionListener(new ActionListener() {
    184             @Override
    185             public void actionPerformed(ActionEvent e) {
    186                 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    187                 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    188             }
     177        drawGpsArrows.addActionListener(e -> {
     178            drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
     179            drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    189180        });
    190181        drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
     
    231222        colorGroup.add(colorTypeTime);
    232223
    233         colorTypeVelocity.addChangeListener(new ChangeListener() {
    234             @Override
    235             public void stateChanged(ChangeEvent e) {
    236                 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected());
    237                 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
    238             }
     224        colorTypeVelocity.addChangeListener(e -> {
     225            colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected());
     226            colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
    239227        });
    240         colorTypeDilution.addChangeListener(new ChangeListener() {
    241             @Override
    242             public void stateChanged(ChangeEvent e) {
    243                 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
    244             }
    245         });
     228        colorTypeDilution.addChangeListener(e -> colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()));
    246229
    247230        colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager."));
     
    283266            label.setLabelFor(waypointLabel);
    284267            add(waypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    285             waypointLabel.addActionListener(new ActionListener() {
    286                 @Override
    287                 public void actionPerformed(ActionEvent e) {
    288                     updateWaypointPattern(waypointLabel, waypointLabelPattern);
    289                 }
    290             });
     268            waypointLabel.addActionListener(e -> updateWaypointPattern(waypointLabel, waypointLabelPattern));
    291269            updateWaypointLabelCombobox(waypointLabel, waypointLabelPattern, TemplateEntryProperty.forMarker(layerName));
    292270            add(waypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
     
    304282            label.setLabelFor(audioWaypointLabel);
    305283            add(audioWaypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    306             audioWaypointLabel.addActionListener(new ActionListener() {
    307                 @Override
    308                 public void actionPerformed(ActionEvent e) {
    309                     updateWaypointPattern(audioWaypointLabel, audioWaypointLabelPattern);
    310                 }
    311             });
     284            audioWaypointLabel.addActionListener(e -> updateWaypointPattern(audioWaypointLabel, audioWaypointLabelPattern));
    312285            updateWaypointLabelCombobox(audioWaypointLabel, audioWaypointLabelPattern, TemplateEntryProperty.forAudioMarker(layerName));
    313286            add(audioWaypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddImageryPanel.java

    r10600 r10611  
    99import javax.swing.AbstractButton;
    1010import javax.swing.JPanel;
    11 import javax.swing.event.ChangeEvent;
    12 import javax.swing.event.ChangeListener;
    1311import javax.swing.event.DocumentEvent;
    1412import javax.swing.event.DocumentListener;
     
    5654
    5755    protected final void registerValidableComponent(AbstractButton component) {
    58         component.addChangeListener(new ChangeListener() {
    59             @Override
    60             public void stateChanged(ChangeEvent e) {
    61                 notifyListeners();
    62             }
    63         });
     56        component.addChangeListener(e -> notifyListeners());
    6457    }
    6558
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java

    r10520 r10611  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    8 import java.awt.event.ItemEvent;
    9 import java.awt.event.ItemListener;
    10 import java.beans.PropertyChangeEvent;
    11 import java.beans.PropertyChangeListener;
    126import java.io.IOException;
    137import java.net.MalformedURLException;
     
    7569        add(name, GBC.eop().fill());
    7670
    77         getLayers.addActionListener(new ActionListener() {
    78             @Override
    79             public void actionPerformed(ActionEvent e) {
    80                 try {
    81                     wms.attemptGetCapabilities(rawUrl.getText());
    82                     tree.updateTree(wms);
    83                     formats.setModel(new DefaultComboBoxModel<>(wms.getFormats().toArray(new String[0])));
    84                     formats.setSelectedItem(wms.getPreferredFormats());
    85                 } catch (MalformedURLException ex) {
    86                     Main.error(ex, false);
    87                     JOptionPane.showMessageDialog(getParent(), tr("Invalid service URL."),
    88                             tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    89                 } catch (IOException ex) {
    90                     Main.error(ex, false);
    91                     JOptionPane.showMessageDialog(getParent(), tr("Could not retrieve WMS layer list."),
    92                             tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    93                 } catch (WMSImagery.WMSGetCapabilitiesException ex) {
    94                     String incomingData = ex.getIncomingData().trim();
    95                     String title = tr("WMS Error");
    96                     String message = tr("Could not parse WMS layer list.");
    97                     Main.error(ex, "Could not parse WMS layer list. Incoming data:\n"+incomingData);
    98                     if ((incomingData.startsWith("<html>") || incomingData.startsWith("<HTML>"))
    99                       && (incomingData.endsWith("</html>") || incomingData.endsWith("</HTML>"))) {
    100                         GuiHelper.notifyUserHtmlError(AddWMSLayerPanel.this, title, message, incomingData);
    101                     } else {
    102                         if (ex.getMessage() != null) {
    103                             message += '\n' + ex.getMessage();
    104                         }
    105                         JOptionPane.showMessageDialog(getParent(), message, title, JOptionPane.ERROR_MESSAGE);
     71        getLayers.addActionListener(e -> {
     72            try {
     73                wms.attemptGetCapabilities(rawUrl.getText());
     74                tree.updateTree(wms);
     75                formats.setModel(new DefaultComboBoxModel<>(wms.getFormats().toArray(new String[0])));
     76                formats.setSelectedItem(wms.getPreferredFormats());
     77            } catch (MalformedURLException ex1) {
     78                Main.error(ex1, false);
     79                JOptionPane.showMessageDialog(getParent(), tr("Invalid service URL."),
     80                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
     81            } catch (IOException ex2) {
     82                Main.error(ex2, false);
     83                JOptionPane.showMessageDialog(getParent(), tr("Could not retrieve WMS layer list."),
     84                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
     85            } catch (WMSImagery.WMSGetCapabilitiesException ex3) {
     86                String incomingData = ex3.getIncomingData().trim();
     87                String title = tr("WMS Error");
     88                String message = tr("Could not parse WMS layer list.");
     89                Main.error(ex3, "Could not parse WMS layer list. Incoming data:\n"+incomingData);
     90                if ((incomingData.startsWith("<html>") || incomingData.startsWith("<HTML>"))
     91                  && (incomingData.endsWith("</html>") || incomingData.endsWith("</HTML>"))) {
     92                    GuiHelper.notifyUserHtmlError(AddWMSLayerPanel.this, title, message, incomingData);
     93                } else {
     94                    if (ex3.getMessage() != null) {
     95                        message += '\n' + ex3.getMessage();
    10696                    }
     97                    JOptionPane.showMessageDialog(getParent(), message, title, JOptionPane.ERROR_MESSAGE);
    10798                }
    10899            }
    109100        });
    110101
    111         endpoint.addItemListener(new ItemListener() {
    112             @Override
    113             public void itemStateChanged(ItemEvent e) {
    114                 tree.getLayerTree().setEnabled(!endpoint.isSelected());
    115                 showBounds.setEnabled(!endpoint.isSelected());
    116                 wmsInstruction.setEnabled(!endpoint.isSelected());
    117                 formats.setEnabled(!endpoint.isSelected());
    118                 wmsUrl.setEnabled(!endpoint.isSelected());
    119                 if (endpoint.isSelected()) {
    120                     URL url = wms.getServiceUrl();
    121                     if (url != null) {
    122                         name.setText(url.getHost());
    123                     }
    124                 } else {
    125                     onLayerSelectionChanged();
     102        endpoint.addItemListener(e -> {
     103            tree.getLayerTree().setEnabled(!endpoint.isSelected());
     104            showBounds.setEnabled(!endpoint.isSelected());
     105            wmsInstruction.setEnabled(!endpoint.isSelected());
     106            formats.setEnabled(!endpoint.isSelected());
     107            wmsUrl.setEnabled(!endpoint.isSelected());
     108            if (endpoint.isSelected()) {
     109                URL url = wms.getServiceUrl();
     110                if (url != null) {
     111                    name.setText(url.getHost());
    126112                }
    127             }
    128         });
    129 
    130         tree.getLayerTree().addPropertyChangeListener("selectedLayers", new PropertyChangeListener() {
    131             @Override
    132             public void propertyChange(PropertyChangeEvent evt) {
     113            } else {
    133114                onLayerSelectionChanged();
    134115            }
    135116        });
    136117
    137         formats.addActionListener(new ActionListener() {
    138             @Override
    139             public void actionPerformed(ActionEvent e) {
    140                 onLayerSelectionChanged();
    141             }
    142         });
     118        tree.getLayerTree().addPropertyChangeListener("selectedLayers", evt -> onLayerSelectionChanged());
    143119
    144         showBounds.addActionListener(new ActionListener() {
    145             @Override
    146             public void actionPerformed(ActionEvent e) {
    147                 if (tree.getSelectedLayers().get(0).bounds != null) {
    148                     SlippyMapBBoxChooser mapPanel = new SlippyMapBBoxChooser();
    149                     mapPanel.setBoundingBox(tree.getSelectedLayers().get(0).bounds);
    150                     JOptionPane.showMessageDialog(null, mapPanel, tr("Show Bounds"), JOptionPane.PLAIN_MESSAGE);
    151                 } else {
    152                     JOptionPane.showMessageDialog(null, tr("No bounding box was found for this layer."),
    153                             tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    154                 }
     120        formats.addActionListener(e -> onLayerSelectionChanged());
     121
     122        showBounds.addActionListener(e -> {
     123            if (tree.getSelectedLayers().get(0).bounds != null) {
     124                SlippyMapBBoxChooser mapPanel = new SlippyMapBBoxChooser();
     125                mapPanel.setBoundingBox(tree.getSelectedLayers().get(0).bounds);
     126                JOptionPane.showMessageDialog(null, mapPanel, tr("Show Bounds"), JOptionPane.PLAIN_MESSAGE);
     127            } else {
     128                JOptionPane.showMessageDialog(null, tr("No bounding box was found for this layer."),
     129                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    155130            }
    156131        });
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CacheContentsPanel.java

    r10541 r10611  
    88import java.util.ArrayList;
    99import java.util.Collections;
    10 import java.util.Comparator;
    1110import java.util.List;
    1211import java.util.Map;
     
    5150    public CacheContentsPanel() {
    5251        super(new GridBagLayout());
    53         Main.worker.submit(new Runnable() {
    54             @Override
    55             public void run() {
    56                 addToPanel(TMSLayer.getCache(), "TMS");
    57                 addToPanel(WMSLayer.getCache(), "WMS");
    58                 addToPanel(WMTSLayer.getCache(), "WMTS");
    59             }
     52        Main.worker.submit(() -> {
     53            addToPanel(TMSLayer.getCache(), "TMS");
     54            addToPanel(WMSLayer.getCache(), "WMS");
     55            addToPanel(WMTSLayer.getCache(), "WMTS");
    6056        });
    6157    }
     
    6561        final TableModel tableModel = getTableModel(cache);
    6662
    67         GuiHelper.runInEDT(new Runnable() {
    68             @Override
    69             public void run() {
    70                 add(
    71                         new JLabel(tr("{0} cache, total cache size: {1} bytes", name, cacheSize)),
    72                         GBC.eol().insets(5, 5, 0, 0));
    73 
    74                 add(
    75                         new JScrollPane(getTableForCache(cache, tableModel)),
    76                         GBC.eol().fill(GBC.BOTH));
    77             }
     63        GuiHelper.runInEDT(() -> {
     64            add(new JLabel(tr("{0} cache, total cache size: {1} bytes", name, cacheSize)),
     65                GBC.eol().insets(5, 5, 0, 0));
     66            add(new JScrollPane(getTableForCache(cache, tableModel)),
     67                GBC.eol().fill(GBC.BOTH));
    7868        });
    7969    }
     
    8878                        return (Long) val;
    8979                    }
    90 
    9180                }
    9281            }
     
    116105            sortedStats.add(new Pair<>(e.getKey(), e.getValue()[0]));
    117106        }
    118         Collections.sort(sortedStats, new Comparator<Pair<String, Integer>>() {
    119             @Override
    120             public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
    121                 return -1 * o1.b.compareTo(o2.b);
    122             }
    123         });
     107        Collections.sort(sortedStats, (o1, o2) -> -1 * o1.b.compareTo(o2.b));
    124108        String[][] ret = new String[sortedStats.size()][3];
    125109        int index = 0;
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java

    r10418 r10611  
    66import java.awt.Color;
    77import java.awt.GridBagLayout;
    8 import java.awt.event.ActionEvent;
    9 import java.awt.event.ActionListener;
    108import java.io.File;
    119import java.io.FilenameFilter;
     
    5553                AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().intValue(), 0, Integer.MAX_VALUE, 1));
    5654
    57 
    5855        this.btnFadeColor = new JButton();
    59 
    60         this.btnFadeColor.addActionListener(new ActionListener() {
    61             @Override
    62             public void actionPerformed(ActionEvent e) {
    63                 JColorChooser chooser = new JColorChooser(btnFadeColor.getBackground());
    64                 int answer = JOptionPane.showConfirmDialog(
    65                         CommonSettingsPanel.this, chooser,
    66                         tr("Choose a color for {0}", tr("imagery fade")),
    67                         JOptionPane.OK_CANCEL_OPTION,
    68                         JOptionPane.PLAIN_MESSAGE);
    69                 if (answer == JOptionPane.OK_OPTION) {
    70                     Color colFadeColor = chooser.getColor();
    71                     btnFadeColor.setBackground(colFadeColor);
    72                     btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
    73                 }
     56        this.btnFadeColor.addActionListener(e -> {
     57            JColorChooser chooser = new JColorChooser(btnFadeColor.getBackground());
     58            int answer = JOptionPane.showConfirmDialog(
     59                    CommonSettingsPanel.this, chooser,
     60                    tr("Choose a color for {0}", tr("imagery fade")),
     61                    JOptionPane.OK_CANCEL_OPTION,
     62                    JOptionPane.PLAIN_MESSAGE);
     63            if (answer == JOptionPane.OK_OPTION) {
     64                Color colFadeColor = chooser.getColor();
     65                btnFadeColor.setBackground(colFadeColor);
     66                btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
    7467            }
    7568        });
     
    159152    private void removeCacheFiles(String path) {
    160153        File directory = new File(path);
    161         File[] cacheFiles = directory.listFiles(new FilenameFilter() {
    162             @Override
    163             public boolean accept(File dir, String name) {
    164                 return name.endsWith(".data") || name.endsWith(".key");
    165             }
    166 
    167         });
     154        File[] cacheFiles = directory.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".data") || name.endsWith(".key"));
    168155        JCSCacheManager.shutdown(); // shutdown Cache - so files can by safely deleted
    169156        for (File cacheFile: cacheFiles) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r10179 r10611  
    1414import java.awt.GridBagLayout;
    1515import java.awt.event.ActionEvent;
    16 import java.awt.event.ActionListener;
    1716import java.awt.event.MouseEvent;
    1817import java.io.IOException;
     
    4140import javax.swing.event.ListSelectionEvent;
    4241import javax.swing.event.ListSelectionListener;
    43 import javax.swing.event.TableModelEvent;
    44 import javax.swing.event.TableModelListener;
    4542import javax.swing.table.DefaultTableCellRenderer;
    4643import javax.swing.table.DefaultTableModel;
     
    312309            defaultTable = new JTable(defaultModel);
    313310
    314             defaultModel.addTableModelListener(
    315                     new TableModelListener() {
    316                         @Override
    317                         public void tableChanged(TableModelEvent e) {
    318                             activeTable.repaint();
    319                         }
    320                     }
    321                     );
    322 
    323             activeModel.addTableModelListener(
    324                     new TableModelListener() {
    325                         @Override
    326                         public void tableChanged(TableModelEvent e) {
    327                             defaultTable.repaint();
    328                         }
    329                     }
    330                     );
     311            defaultModel.addTableModelListener(e -> activeTable.repaint());
     312            activeModel.addTableModelListener(e -> defaultTable.repaint());
    331313
    332314            TableColumnModel mod = defaultTable.getColumnModel();
     
    839821            JButton add = new JButton(tr("Add"));
    840822            buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0));
    841             add.addActionListener(new ActionListener() {
    842                 @Override
    843                 public void actionPerformed(ActionEvent e) {
    844                     OffsetBookmark b = new OffsetBookmark(Main.getProjection().toCode(), "", "", 0, 0);
    845                     model.addRow(b);
    846                 }
    847             });
     823            add.addActionListener(e -> model.addRow(new OffsetBookmark(Main.getProjection().toCode(), "", "", 0, 0)));
    848824
    849825            JButton delete = new JButton(tr("Delete"));
    850826            buttonPanel.add(delete, GBC.std().insets(0, 5, 0, 0));
    851             delete.addActionListener(new ActionListener() {
    852                 @Override
    853                 public void actionPerformed(ActionEvent e) {
    854                     if (list.getSelectedRow() == -1) {
    855                         JOptionPane.showMessageDialog(gui, tr("Please select the row to delete."));
    856                     } else {
    857                         Integer i;
    858                         while ((i = list.getSelectedRow()) != -1) {
    859                             model.removeRow(i);
    860                         }
     827            delete.addActionListener(e -> {
     828                if (list.getSelectedRow() == -1) {
     829                    JOptionPane.showMessageDialog(gui, tr("Please select the row to delete."));
     830                } else {
     831                    Integer i;
     832                    while ((i = list.getSelectedRow()) != -1) {
     833                        model.removeRow(i);
    861834                    }
    862835                }
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/BackupPreference.java

    r9543 r10611  
    55
    66import java.awt.GridBagLayout;
    7 import java.awt.event.ActionEvent;
    87import java.awt.event.ActionListener;
    98
     
    101100        panel.add(notification, GBC.eop());
    102101
    103         ActionListener autosaveEnabled = new ActionListener() {
    104             @Override
    105             public void actionPerformed(ActionEvent e) {
    106                 boolean enabled = autosave.isSelected();
    107                 autosaveIntervalLabel.setEnabled(enabled);
    108                 autosaveInterval.setEnabled(enabled);
    109                 backupPerLayerLabel.setEnabled(enabled);
    110                 backupPerLayer.setEnabled(enabled);
    111             }
     102        ActionListener autosaveEnabled = e -> {
     103            boolean enabled = autosave.isSelected();
     104            autosaveIntervalLabel.setEnabled(enabled);
     105            autosaveInterval.setEnabled(enabled);
     106            backupPerLayerLabel.setEnabled(enabled);
     107            backupPerLayer.setEnabled(enabled);
    112108        };
    113109        autosave.addActionListener(autosaveEnabled);
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r10420 r10611  
    3333import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
    3434import org.openstreetmap.josm.tools.GBC;
    35 import org.openstreetmap.josm.tools.Predicate;
    3635import org.openstreetmap.josm.tools.Utils;
    3736
     
    233232            int insertionIdx = 0;
    234233            for (final SourceEntry def : defaults) {
    235                 int i = Utils.indexOf(list,
    236                         new Predicate<SourceEntry>() {
    237                     @Override
    238                     public boolean evaluate(SourceEntry se) {
    239                         return Objects.equals(def.url, se.url);
    240                     }
    241                 });
     234                int i = Utils.indexOf(list, se -> Objects.equals(def.url, se.url));
    242235                if (i == -1 && !knownDefaults.contains(def.url)) {
    243236                    def.active = false;
     
    255248
    256249            // XML style is not bundled anymore
    257             list.remove(Utils.find(list, new Predicate<SourceEntry>() {
    258                             @Override
    259                             public boolean evaluate(SourceEntry se) {
    260                                 return "resource://styles/standard/elemstyles.xml".equals(se.url);
    261                             }
    262                         }));
     250            list.remove(Utils.find(list, se -> "resource://styles/standard/elemstyles.xml".equals(se.url)));
    263251
    264252            return changed;
  • 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        );
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r10242 r10611  
    77import java.awt.GridBagLayout;
    88import java.awt.Insets;
    9 import java.awt.event.ActionEvent;
    109import java.awt.event.ActionListener;
    1110import java.util.Arrays;
     
    113112
    114113            JButton btnCheck = new JButton(tr("Validate"));
    115             btnCheck.addActionListener(new ActionListener() {
    116                 @Override
    117                 public void actionPerformed(ActionEvent e) {
    118                     val.validate();
    119                 }
    120             });
     114            btnCheck.addActionListener(e -> val.validate());
    121115            btnCheck.setLayout(new BorderLayout());
    122116            btnCheck.setMargin(new Insets(-1, 0, -1, 0));
    123117
    124118            JButton btnInfo = new JButton(tr("Parameter information..."));
    125             btnInfo.addActionListener(new ActionListener() {
    126                 @Override
    127                 public void actionPerformed(ActionEvent e) {
    128                     CustomProjectionChoice.ParameterInfoDialog dlg = new CustomProjectionChoice.ParameterInfoDialog();
    129                     dlg.showDialog();
    130                     dlg.toFront();
    131                 }
     119            btnInfo.addActionListener(e -> {
     120                CustomProjectionChoice.ParameterInfoDialog dlg = new CustomProjectionChoice.ParameterInfoDialog();
     121                dlg.showDialog();
     122                dlg.toFront();
    132123            });
    133124
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r10310 r10611  
    66import java.awt.Component;
    77import java.awt.GridBagLayout;
    8 import java.awt.event.ActionEvent;
    98import java.awt.event.ActionListener;
    109import java.util.ArrayList;
     
    449448            return;
    450449
    451         final ActionListener listener = new ActionListener() {
    452             @Override
    453             public void actionPerformed(ActionEvent e) {
    454                 updateMeta(pc);
    455             }
    456         };
     450        final ActionListener listener = e -> updateMeta(pc);
    457451
    458452        // Replace old panel with new one
     
    485479            throw new RuntimeException("Couldn't find the current projection in the list of available projections!");
    486480
    487         projectionCombo.addActionListener(new ActionListener() {
    488             @Override
    489             public void actionPerformed(ActionEvent e) {
    490                 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem();
    491                 selectedProjectionChanged(pc);
    492             }
     481        projectionCombo.addActionListener(e -> {
     482            ProjectionChoice pc1 = (ProjectionChoice) projectionCombo.getSelectedItem();
     483            selectedProjectionChanged(pc1);
    493484        });
    494485        return pc;
  • trunk/src/org/openstreetmap/josm/gui/preferences/remotecontrol/RemoteControlPreference.java

    r9778 r10611  
    77import java.awt.Font;
    88import java.awt.GridBagLayout;
    9 import java.awt.event.ActionEvent;
    109import java.awt.event.ActionListener;
    1110import java.io.IOException;
     
    120119            wrapper.add(installCertificate, GBC.std().insets(5, 5, 0, 0));
    121120            wrapper.add(uninstallCertificate, GBC.eol().insets(5, 5, 0, 0));
    122             enableHttpsSupport.addActionListener(new ActionListener() {
    123                 @Override
    124                 public void actionPerformed(ActionEvent e) {
    125                     installCertificate.setEnabled(enableHttpsSupport.isSelected());
     121            enableHttpsSupport.addActionListener(e -> installCertificate.setEnabled(enableHttpsSupport.isSelected()));
     122            installCertificate.addActionListener(e -> {
     123                try {
     124                    boolean changed = RemoteControlHttpsServer.setupPlatform(
     125                            RemoteControlHttpsServer.loadJosmKeystore());
     126                    String msg = changed ?
     127                            tr("Certificate has been successfully installed.") :
     128                            tr("Certificate is already installed. Nothing to do.");
     129                    Main.info(msg);
     130                    JOptionPane.showMessageDialog(wrapper, msg);
     131                } catch (IOException | GeneralSecurityException ex) {
     132                    Main.error(ex);
    126133                }
    127134            });
    128             installCertificate.addActionListener(new ActionListener() {
    129                 @Override
    130                 public void actionPerformed(ActionEvent e) {
    131                     try {
    132                         boolean changed = RemoteControlHttpsServer.setupPlatform(
    133                                 RemoteControlHttpsServer.loadJosmKeystore());
    134                         String msg = changed ?
    135                                 tr("Certificate has been successfully installed.") :
    136                                 tr("Certificate is already installed. Nothing to do.");
    137                         Main.info(msg);
    138                         JOptionPane.showMessageDialog(wrapper, msg);
    139                     } catch (IOException | GeneralSecurityException ex) {
    140                         Main.error(ex);
     135            uninstallCertificate.addActionListener(e -> {
     136                try {
     137                    String msg;
     138                    KeyStore ks = PlatformHookWindows.getRootKeystore();
     139                    if (ks.containsAlias(RemoteControlHttpsServer.ENTRY_ALIAS)) {
     140                        Main.info(tr("Removing certificate {0} from root keystore.", RemoteControlHttpsServer.ENTRY_ALIAS));
     141                        ks.deleteEntry(RemoteControlHttpsServer.ENTRY_ALIAS);
     142                        msg = tr("Certificate has been successfully uninstalled.");
     143                    } else {
     144                        msg = tr("Certificate is not installed. Nothing to do.");
    141145                    }
    142                 }
    143             });
    144             uninstallCertificate.addActionListener(new ActionListener() {
    145                 @Override
    146                 public void actionPerformed(ActionEvent e) {
    147                     try {
    148                         String msg;
    149                         KeyStore ks = PlatformHookWindows.getRootKeystore();
    150                         if (ks.containsAlias(RemoteControlHttpsServer.ENTRY_ALIAS)) {
    151                             Main.info(tr("Removing certificate {0} from root keystore.", RemoteControlHttpsServer.ENTRY_ALIAS));
    152                             ks.deleteEntry(RemoteControlHttpsServer.ENTRY_ALIAS);
    153                             msg = tr("Certificate has been successfully uninstalled.");
    154                         } else {
    155                             msg = tr("Certificate is not installed. Nothing to do.");
    156                         }
    157                         Main.info(msg);
    158                         JOptionPane.showMessageDialog(wrapper, msg);
    159                     } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) {
    160                         Main.error(ex);
    161                     }
     146                    Main.info(msg);
     147                    JOptionPane.showMessageDialog(wrapper, msg);
     148                } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) {
     149                    Main.error(ex);
    162150                }
    163151            });
     
    181169        alwaysAskUserConfirm.setSelected(Main.pref.getBoolean(RequestHandler.globalConfirmationKey, RequestHandler.globalConfirmationDefault));
    182170
    183         ActionListener remoteControlEnabled = new ActionListener() {
    184 
    185             @Override
    186             public void actionPerformed(ActionEvent e) {
    187                 GuiHelper.setEnabledRec(wrapper, enableRemoteControl.isSelected());
    188                 // 'setEnabled(false)' does not work for JLabel with html text, so do it manually
    189                 // FIXME: use QuadStateCheckBox to make checkboxes unset when disabled
    190                 if (installCertificate != null && uninstallCertificate != null) {
    191                     // Install certificate button is enabled if HTTPS is also enabled
    192                     installCertificate.setEnabled(enableRemoteControl.isSelected() && enableHttpsSupport.isSelected());
    193                     // Uninstall certificate button is always enabled
    194                     uninstallCertificate.setEnabled(true);
    195                 }
     171        ActionListener remoteControlEnabled = e -> {
     172            GuiHelper.setEnabledRec(wrapper, enableRemoteControl.isSelected());
     173            // 'setEnabled(false)' does not work for JLabel with html text, so do it manually
     174            // FIXME: use QuadStateCheckBox to make checkboxes unset when disabled
     175            if (installCertificate != null && uninstallCertificate != null) {
     176                // Install certificate button is enabled if HTTPS is also enabled
     177                installCertificate.setEnabled(enableRemoteControl.isSelected() && enableHttpsSupport.isSelected());
     178                // Uninstall certificate button is always enabled
     179                uninstallCertificate.setEnabled(true);
    196180            }
    197181        };
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/FeaturesPanel.java

    r9073 r10611  
    1010import javax.swing.JLabel;
    1111import javax.swing.JPanel;
    12 import javax.swing.event.ChangeEvent;
    13 import javax.swing.event.ChangeListener;
    1412
    1513import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
     
    4442        notifier = new JCheckBox(tr("Periodically check for new messages"));
    4543        add(notifier, GBC.eol());
    46         notifier.addChangeListener(new ChangeListener() {
    47             @Override
    48             public void stateChanged(ChangeEvent e) {
    49                 updateEnabledState();
    50             }
    51         });
     44        notifier.addChangeListener(e -> updateEnabledState());
    5245
    5346        intervalLabel = new JLabel(tr("Check interval (minutes):"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r10424 r10611  
    1313import java.awt.event.ActionEvent;
    1414import java.awt.event.ItemEvent;
    15 import java.awt.event.ItemListener;
    1615import java.beans.PropertyChangeEvent;
    1716import java.beans.PropertyChangeListener;
     
    7877        cbShowAdvancedParameters.setSelected(false);
    7978        cbShowAdvancedParameters.addItemListener(
    80                 new ItemListener() {
    81                     @Override
    82                     public void itemStateChanged(ItemEvent evt) {
    83                         pnlAdvancedProperties.setVisible(evt.getStateChange() == ItemEvent.SELECTED);
    84                     }
    85                 }
     79                evt -> pnlAdvancedProperties.setVisible(evt.getStateChange() == ItemEvent.SELECTED)
    8680        );
    8781
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java

    r10424 r10611  
    186186            final ApiUrlTestTask task = new ApiUrlTestTask(OsmApiUrlInputPanel.this, url);
    187187            Main.worker.submit(task);
    188             Runnable r = new Runnable() {
    189                 @Override
    190                 public void run() {
    191                     if (task.isCanceled())
    192                         return;
    193                     Runnable r = new Runnable() {
    194                         @Override
    195                         public void run() {
    196                             if (task.isSuccess()) {
    197                                 lblValid.setIcon(ImageProvider.get("dialogs", "valid"));
    198                                 lblValid.setToolTipText(tr("The API URL is valid."));
    199                                 lastTestedUrl = url;
    200                                 updateEnabledState();
    201                             } else {
    202                                 lblValid.setIcon(ImageProvider.get("warning-small"));
    203                                 lblValid.setToolTipText(tr("Validation failed. The API URL seems to be invalid."));
    204                             }
    205                         }
    206                     };
    207                     SwingUtilities.invokeLater(r);
    208                 }
     188            Runnable r = () -> {
     189                if (task.isCanceled())
     190                    return;
     191                Runnable r1 = () -> {
     192                    if (task.isSuccess()) {
     193                        lblValid.setIcon(ImageProvider.get("dialogs", "valid"));
     194                        lblValid.setToolTipText(tr("The API URL is valid."));
     195                        lastTestedUrl = url;
     196                        updateEnabledState();
     197                    } else {
     198                        lblValid.setIcon(ImageProvider.get("warning-small"));
     199                        lblValid.setToolTipText(tr("Validation failed. The API URL seems to be invalid."));
     200                    }
     201                };
     202                SwingUtilities.invokeLater(r1);
    209203            };
    210204            Main.worker.submit(r);
  • trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java

    r9778 r10611  
    55
    66import java.awt.GridBagLayout;
    7 import java.awt.event.ActionEvent;
    87import java.awt.event.ActionListener;
    98import java.util.ArrayList;
     
    7675        testPanel.add(prefOtherUpload, GBC.eol());
    7776
    78         ActionListener otherUploadEnabled = new ActionListener() {
    79             @Override
    80             public void actionPerformed(ActionEvent e) {
    81                 prefOtherUpload.setEnabled(prefOther.isSelected());
    82             }
    83         };
     77        ActionListener otherUploadEnabled = e -> prefOtherUpload.setEnabled(prefOther.isSelected());
    8478        prefOther.addActionListener(otherUploadEnabled);
    8579        otherUploadEnabled.actionPerformed(null);
Note: See TracChangeset for help on using the changeset viewer.