Ignore:
Timestamp:
2024-06-11T23:53:20+02:00 (23 months ago)
Author:
taylor.smock
Message:

Cleanup some new PMD warnings from PMD 7.x

I haven't updated to PMD 7.x in ivy/maven yet since I still have 83 PMD violations
to go through, and I don't know (yet) if any of them were supposed to be ignored
by the xpath expressions in tools/pmd/josm-ruleset.xml.

I may re-enable some of the PMD checks I've temporarily disabled prior to committing
the update for PMD.

Additionally cleanup some SonarLint issues in the modified files.

File:
1 edited

Legend:

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

    r19080 r19101  
    5959import javax.swing.KeyStroke;
    6060import javax.swing.ListSelectionModel;
     61import javax.swing.SwingConstants;
    6162import javax.swing.UIManager;
    6263import javax.swing.event.CellEditorListener;
     
    112113 */
    113114public abstract class SourceEditor extends JPanel {
     115    private static final String DELETE = "delete";
     116    private static final String DIALOGS = "dialogs";
    114117
    115118    /** the type of source entry **/
     
    219222        RemoveActiveSourcesAction removeActiveSourcesAction = new RemoveActiveSourcesAction();
    220223        tblActiveSources.getSelectionModel().addListSelectionListener(removeActiveSourcesAction);
    221         tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
    222         tblActiveSources.getActionMap().put("delete", removeActiveSourcesAction);
     224        tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
     225        tblActiveSources.getActionMap().put(DELETE, removeActiveSourcesAction);
    223226
    224227        MoveUpDownAction moveUp = null;
     
    297300        gbc.insets = new Insets(0, 0, 0, 6);
    298301
    299         JToolBar sideButtonTB = new JToolBar(JToolBar.VERTICAL);
     302        JToolBar sideButtonTB = new JToolBar(SwingConstants.VERTICAL);
    300303        sideButtonTB.setFloatable(false);
    301304        sideButtonTB.setBorderPainted(false);
     
    363366        RemoveIconPathAction removeIconPathAction = new RemoveIconPathAction();
    364367        tblIconPaths.getSelectionModel().addListSelectionListener(removeIconPathAction);
    365         tblIconPaths.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
    366         tblIconPaths.getActionMap().put("delete", removeIconPathAction);
     368        tblIconPaths.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
     369        tblIconPaths.getActionMap().put(DELETE, removeIconPathAction);
    367370
    368371        gbc.gridx = 0;
     
    721724            data = IntStream.range(0, data.size())
    722725                    .filter(i -> !idxs.contains(i))
    723                     .mapToObj(i -> data.get(i))
     726                    .mapToObj(data::get)
    724727                    .collect(Collectors.toList());
    725728            fireTableDataChanged();
     
    909912            putValue(NAME, tr("New"));
    910913            putValue(SHORT_DESCRIPTION, getStr(I18nString.NEW_SOURCE_ENTRY_TOOLTIP));
    911             new ImageProvider("dialogs", "add").getResource().attachImageIcon(this);
     914            new ImageProvider(DIALOGS, "add").getResource().attachImageIcon(this);
    912915        }
    913916
     
    939942            putValue(NAME, tr("Remove"));
    940943            putValue(SHORT_DESCRIPTION, getStr(I18nString.REMOVE_SOURCE_TOOLTIP));
    941             new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this);
     944            new ImageProvider(DIALOGS, DELETE).getResource().attachImageIcon(this);
    942945            updateEnabledState();
    943946        }
     
    962965            putValue(NAME, tr("Edit"));
    963966            putValue(SHORT_DESCRIPTION, getStr(I18nString.EDIT_SOURCE_TOOLTIP));
    964             new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this);
     967            new ImageProvider(DIALOGS, "edit").getResource().attachImageIcon(this);
    965968            updateEnabledState();
    966969        }
     
    10081011        MoveUpDownAction(boolean isDown) {
    10091012            increment = isDown ? 1 : -1;
    1010             new ImageProvider("dialogs", isDown ? "down" : "up").getResource().attachImageIcon(this, true);
     1013            new ImageProvider(DIALOGS, isDown ? "down" : "up").getResource().attachImageIcon(this, true);
    10111014            putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up."));
    10121015            updateEnabledState();
     
    11101113            putValue(NAME, tr("Reload"));
    11111114            putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url));
    1112             new ImageProvider("dialogs", "refresh").getResource().attachImageIcon(this);
     1115            new ImageProvider(DIALOGS, "refresh").getResource().attachImageIcon(this);
    11131116            this.url = url;
    11141117            this.sourceProviders = sourceProviders;
     
    12521255            putValue(NAME, tr("New"));
    12531256            putValue(SHORT_DESCRIPTION, tr("Add a new icon path"));
    1254             new ImageProvider("dialogs", "add").getResource().attachImageIcon(this);
     1257            new ImageProvider(DIALOGS, "add").getResource().attachImageIcon(this);
    12551258        }
    12561259
     
    12661269            putValue(NAME, tr("Remove"));
    12671270            putValue(SHORT_DESCRIPTION, tr("Remove the selected icon paths"));
    1268             new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this);
     1271            new ImageProvider(DIALOGS, DELETE).getResource().attachImageIcon(this);
    12691272            updateEnabledState();
    12701273        }
     
    12891292            putValue(NAME, tr("Edit"));
    12901293            putValue(SHORT_DESCRIPTION, tr("Edit the selected icon path"));
    1291             new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this);
     1294            new ImageProvider(DIALOGS, "edit").getResource().attachImageIcon(this);
    12921295            updateEnabledState();
    12931296        }
     
    16081611        public void setInitialValue(String initialValue) {
    16091612            this.value = initialValue;
    1610             if (initialValue == null) {
    1611                 this.tfFileName.setText("");
    1612             } else {
    1613                 this.tfFileName.setText(initialValue);
    1614             }
     1613            this.tfFileName.setText(Objects.requireNonNullElse(initialValue, ""));
    16151614        }
    16161615
Note: See TracChangeset for help on using the changeset viewer.