Changeset 19106 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2024-06-13T21:18:45+02:00 (5 months ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r17458 r19106 44 44 /** 45 45 * Tools / Orthogonalize 46 * 46 * <p> 47 47 * Align edges of a way so all angles are angles of 90 or 180 degrees. 48 48 * See USAGE String below. … … 73 73 * excepted deviation from an angle of 0, 90, 180, 360 degrees 74 74 * maximum value: 45 degrees 75 * 75 * <p> 76 76 * Current policy is to except just everything, no matter how strange the result would be. 77 77 */ … … 86 86 /** 87 87 * Undo the previous orthogonalization for certain nodes. 88 * 88 * <p> 89 89 * This is useful, if the way shares nodes that you don't like to change, e.g. imports or 90 90 * work of another user. 91 * 91 * <p> 92 92 * This action can be triggered by shortcut only. 93 93 */ … … 279 279 int n = wd.wayNodes.size(); 280 280 int i = wd.wayNodes.indexOf(singleNode); 281 Node n0, n2; 281 final Node n0; 282 final Node n2; 282 283 if (i == 0 && n >= 3 && singleNode.equals(wd.wayNodes.get(n-1))) { 283 284 n0 = wd.wayNodes.get(n-2); … … 428 429 for (Node n : cs) { 429 430 s.remove(n); 430 average += nC.get(n) .doubleValue();431 average += nC.get(n); 431 432 } 432 433 average = average / cs.size(); -
trunk/src/org/openstreetmap/josm/gui/animation/DropImage.java
r18932 r19106 9 9 import java.net.URL; 10 10 import java.net.URLDecoder; 11 import java.nio.charset.StandardCharsets; 11 12 import java.util.ArrayList; 12 13 import java.util.Enumeration; … … 71 72 String path = "images/presets/"; 72 73 URL url = DropImage.class.getClassLoader().getResource(path); 73 if (url != null && url.getProtocol().equals("file")) {74 if (url != null && "file".equals(url.getProtocol())) { 74 75 ArrayList<File> dirs = new ArrayList<>(); 75 76 dirs.add(new File(url.toURI())); … … 87 88 } while (!dirs.isEmpty()); 88 89 name = result.get(seed.nextInt(result.size())); 89 } else if (url != null && url.getProtocol().equals("jar")) {90 String jarPath = url.getPath().substring(5, url.getPath().indexOf( "!"));91 try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))) {90 } else if (url != null && "jar".equals(url.getProtocol())) { 91 String jarPath = url.getPath().substring(5, url.getPath().indexOf('!')); 92 try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8))) { 92 93 Enumeration<JarEntry> entries = jar.entries(); 93 94 while (entries.hasMoreElements()) { -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java
r18972 r19106 65 65 * decisions. {@link PropertyChangeListener}s can register for property value changes of 66 66 * {@link #FROZEN_PROP}. 67 * 67 * <p> 68 68 * ListMergeModel is an abstract class. Three methods have to be implemented by subclasses: 69 69 * <ul> … … 203 203 entries = new EnumMap<>(ListRole.class); 204 204 for (ListRole role : ListRole.values()) { 205 entries.put(role, new ArrayList< T>());205 entries.put(role, new ArrayList<>()); 206 206 } 207 207 … … 379 379 items.add(tr("{0} more...", deletedIds.size() - MAX_DELETED_PRIMITIVE_IN_DIALOG)); 380 380 } 381 StringBuilder sb = new StringBuilder(); 382 sb.append("<html>") 383 .append(tr("The following objects could not be copied to the target object<br>because they are deleted in the target dataset:")) 384 .append(Utils.joinAsHtmlUnorderedList(items)) 385 .append("</html>"); 381 String sb = "<html>" + 382 tr("The following objects could not be copied to the target object<br>because they are deleted in the target dataset:") + 383 Utils.joinAsHtmlUnorderedList(items) + 384 "</html>"; 386 385 HelpAwareOptionPane.showOptionDialog( 387 386 MainApplication.getMainFrame(), 388 sb .toString(),387 sb, 389 388 tr("Merging deleted objects failed"), 390 389 JOptionPane.WARNING_MESSAGE, -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueCellEditor.java
r19050 r19106 28 28 * proposed tag values. The editor also allows to select all proposed valued or 29 29 * to remove the tag. 30 * 30 * <p> 31 31 * The editor responds intercepts some keys and interprets them as navigation keys. It 32 32 * forwards navigation events to {@link NavigationListener}s registered with this editor. 33 33 * You should register the parent table using this editor as {@link NavigationListener}. 34 * 34 * <p> 35 35 * {@link KeyEvent#VK_ENTER} and {@link KeyEvent#VK_TAB} trigger a {@link NavigationListener#gotoNextDecision()}. 36 36 */ … … 88 88 public MultiValueCellEditor() { 89 89 editorModel = new JosmComboBoxModel<>(); 90 editor = new JosmComboBox< Object>(editorModel) {90 editor = new JosmComboBox<>(editorModel) { 91 91 @Override 92 92 public void processKeyEvent(KeyEvent e) { … … 216 216 */ 217 217 protected void renderValue(Object value) { 218 setFont(UIManager.getFont("ComboBox.font")); 218 final String comboBoxFont = "ComboBox.font"; 219 setFont(UIManager.getFont(comboBoxFont)); 219 220 if (value instanceof String) { 220 221 setText((String) value); … … 223 224 case UNDECIDED: 224 225 setText(tr("Choose a value")); 225 setFont(UIManager.getFont( "ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));226 setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD)); 226 227 break; 227 228 case KEEP_NONE: 228 229 setText(tr("none")); 229 setFont(UIManager.getFont( "ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));230 setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD)); 230 231 break; 231 232 case KEEP_ALL: 232 233 setText(tr("all")); 233 setFont(UIManager.getFont( "ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));234 setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD)); 234 235 break; 235 236 case SUM_ALL_NUMERIC: 236 237 setText(tr("sum")); 237 setFont(UIManager.getFont( "ComboBox.font").deriveFont(Font.ITALIC + Font.BOLD));238 setFont(UIManager.getFont(comboBoxFont).deriveFont(Font.ITALIC + Font.BOLD)); 238 239 break; 239 240 default: -
trunk/src/org/openstreetmap/josm/gui/datatransfer/TagTransferable.java
r11015 r19106 54 54 string.append('\n'); 55 55 } 56 string.append(e.getKey()) ;57 string.append('=');58 string.append(e.getValue());56 string.append(e.getKey()) 57 .append('=') 58 .append(e.getValue()); 59 59 } 60 60 return string.toString(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java
r19078 r19106 223 223 s.append(INDENT).append(INDENT); 224 224 addHeadline(m.getMember()); 225 s.append(tr(" as \"{0}\"", m.getRole())) ;226 s.append(NL);225 s.append(tr(" as \"{0}\"", m.getRole())) 226 .append(NL); 227 227 } 228 228 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r19101 r19106 529 529 .filter(i -> history.get(i).equals(selection)) 530 530 .findFirst() 531 .ifPresent( i -> history.remove(i));531 .ifPresent(history::remove); 532 532 int maxsize = Config.getPref().getInt("select.history-size", SELECTION_HISTORY_SIZE); 533 533 while (history.size() > maxsize) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r18871 r19106 11 11 import java.awt.Graphics; 12 12 import java.awt.GraphicsEnvironment; 13 import java.awt.GridBagConstraints; 13 14 import java.awt.GridBagLayout; 14 15 import java.awt.GridLayout; … … 46 47 import javax.swing.JToggleButton; 47 48 import javax.swing.Scrollable; 49 import javax.swing.SwingConstants; 48 50 import javax.swing.SwingUtilities; 49 51 … … 100 102 */ 101 103 public static final BooleanProperty PROP_DYNAMIC_BUTTONS = new BooleanProperty("dialog.dynamic.buttons", false); 104 private static final String SELECTED = "selected"; 102 105 103 106 private final transient ParametrizedEnumProperty<ButtonHidingType> propButtonHiding = 104 new ParametrizedEnumProperty< ToggleDialog.ButtonHidingType>(ButtonHidingType.class, ButtonHidingType.DYNAMIC) {105 @Override106 protected String getKey(String... params) {107 return preferencePrefix + ".buttonhiding";108 }109 110 @Override111 protected ButtonHidingType parse(String s) {112 try {113 return super.parse(s);114 } catch (IllegalArgumentException e) {115 // Legacy settings116 Logging.trace(e);117 return Boolean.parseBoolean(s) ? ButtonHidingType.DYNAMIC : ButtonHidingType.ALWAYS_SHOWN;118 }119 }120 };107 new ParametrizedEnumProperty<>(ButtonHidingType.class, ButtonHidingType.DYNAMIC) { 108 @Override 109 protected String getKey(String... params) { 110 return preferencePrefix + ".buttonhiding"; 111 } 112 113 @Override 114 protected ButtonHidingType parse(String s) { 115 try { 116 return super.parse(s); 117 } catch (IllegalArgumentException e) { 118 // Legacy settings 119 Logging.trace(e); 120 return Boolean.parseBoolean(s) ? ButtonHidingType.DYNAMIC : ButtonHidingType.ALWAYS_SHOWN; 121 } 122 } 123 }; 121 124 122 125 /** The action to toggle this dialog */ … … 354 357 windowMenuItem.setState(true); 355 358 } 356 toggleAction.putValue( "selected", Boolean.FALSE);357 toggleAction.putValue( "selected", Boolean.TRUE);359 toggleAction.putValue(SELECTED, Boolean.FALSE); 360 toggleAction.putValue(SELECTED, Boolean.TRUE); 358 361 } 359 362 … … 382 385 @Override 383 386 public void buttonHidden() { 384 if (Boolean.TRUE.equals(toggleAction.getValue( "selected"))) {387 if (Boolean.TRUE.equals(toggleAction.getValue(SELECTED))) { 385 388 toggleAction.actionPerformed(null); 386 389 } … … 402 405 } 403 406 setIsShowing(false); 404 toggleAction.putValue( "selected", Boolean.FALSE);407 toggleAction.putValue(SELECTED, Boolean.FALSE); 405 408 } 406 409 … … 551 554 // scale down the dialog icon 552 555 ImageIcon icon = ImageProvider.get("dialogs", iconName, ImageProvider.ImageSizes.SMALLICON); 553 lblTitle = new JLabel("", icon, JLabel.TRAILING);556 lblTitle = new JLabel("", icon, SwingConstants.TRAILING); 554 557 lblTitle.setIconTextGap(8); 555 558 … … 569 572 lblTitleWeak.setPreferredSize(new Dimension(Integer.MAX_VALUE, 20)); 570 573 lblTitleWeak.setMinimumSize(new Dimension(0, 20)); 571 add(lblTitleWeak, GBC.std().fill(G BC.HORIZONTAL));574 add(lblTitleWeak, GBC.std().fill(GridBagConstraints.HORIZONTAL)); 572 575 573 576 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r19016 r19106 176 176 buttons.add(new SideButton(fixAction)); 177 177 178 if ( ValidatorPrefHelper.PREF_USE_IGNORE.get()) {178 if (Boolean.TRUE.equals(ValidatorPrefHelper.PREF_USE_IGNORE.get())) { 179 179 ignoreAction = new AbstractAction() { 180 180 { … … 430 430 OsmDataLayer editLayer = e.getSource().getEditLayer(); 431 431 if (editLayer == null) { 432 tree.setErrorList(new ArrayList< TestError>());432 tree.setErrorList(new ArrayList<>()); 433 433 } else { 434 434 tree.setErrorList(editLayer.validationErrors); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTransferHandler.java
r16438 r19106 101 101 final RelationMemberTransferable.Data memberData = (RelationMemberTransferable.Data) 102 102 support.getTransferable().getTransferData(RelationMemberTransferable.RELATION_MEMBER_DATA); 103 importData(destination, insertRow, memberData.getRelationMemberData(), new AbstractRelationMemberConverter< RelationMemberData>() {103 importData(destination, insertRow, memberData.getRelationMemberData(), new AbstractRelationMemberConverter<>() { 104 104 @Override 105 105 protected RelationMember getMember(MemberTable destination, RelationMemberData data, OsmPrimitive p) { … … 113 113 final PrimitiveTransferData data = (PrimitiveTransferData) 114 114 support.getTransferable().getTransferData(PrimitiveTransferData.DATA_FLAVOR); 115 importData(destination, insertRow, data.getDirectlyAdded(), new AbstractRelationMemberConverter< PrimitiveData>() {115 importData(destination, insertRow, data.getDirectlyAdded(), new AbstractRelationMemberConverter<>() { 116 116 @Override 117 117 protected RelationMember getMember(MemberTable destination, PrimitiveData data, OsmPrimitive p) { -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkList.java
r17721 r19106 242 242 */ 243 243 public BookmarkList() { 244 setModel(new DefaultListModel< Bookmark>());244 setModel(new DefaultListModel<>()); 245 245 load(); 246 246 setVisibleRowCount(7); -
trunk/src/org/openstreetmap/josm/gui/download/OSMDownloadSource.java
r19050 r19106 110 110 bounds.extend(b); 111 111 } 112 } catch (InterruptedException | ExecutionException ex) { 112 } catch (InterruptedException ex) { 113 Thread.currentThread().interrupt(); 114 Logging.warn(ex); 115 } catch (ExecutionException ex) { 113 116 Logging.warn(ex); 114 117 } … … 215 218 checkboxChangeListener = e -> { 216 219 rememberSettings(); 217 dialog.getSelectedDownloadArea().ifPresent( OSMDownloadSourcePanel.this::boundingBoxChanged);220 dialog.getSelectedDownloadArea().ifPresent(this::boundingBoxChanged); 218 221 }; 219 222 … … 273 276 * It is mandatory to specify the area to download from OSM. 274 277 */ 275 if ( !settings.getDownloadBounds().isPresent()) {278 if (settings.getDownloadBounds().isEmpty()) { 276 279 JOptionPane.showMessageDialog( 277 280 this.getParent(), -
trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java
r19050 r19106 3 3 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 … … 10 11 import java.time.format.FormatStyle; 11 12 import java.util.ArrayList; 12 import java.util.Arrays;13 13 import java.util.Collection; 14 14 import java.util.Collections; … … 45 45 */ 46 46 public abstract class AbstractUploadTask extends PleaseWaitRunnable { 47 private static final String CANCEL_TR = marktr("Cancel"); 48 private static final String CANCEL = "cancel"; 49 private static final String UPDATE_DATA = "updatedata"; 47 50 48 51 /** … … 132 135 new ButtonSpec( 133 136 lbl, 134 new ImageProvider( "updatedata"),137 new ImageProvider(UPDATE_DATA), 135 138 null, null), 136 139 new ButtonSpec( 137 140 tr("Synchronize entire dataset"), 138 new ImageProvider( "updatedata"),141 new ImageProvider(UPDATE_DATA), 139 142 null, null), 140 143 new ButtonSpec( 141 tr( "Cancel"),142 new ImageProvider( "cancel"),144 tr(CANCEL_TR), 145 new ImageProvider(CANCEL), 143 146 null, null) 144 147 }; … … 167 170 case 0: synchronizePrimitive(primitiveType, id); break; 168 171 case 1: synchronizeDataSet(); break; 169 default: return;172 default: // Do nothing (just return) 170 173 } 171 174 } … … 180 183 new ButtonSpec( 181 184 tr("Synchronize entire dataset"), 182 new ImageProvider( "updatedata"),185 new ImageProvider(UPDATE_DATA), 183 186 null, null), 184 187 new ButtonSpec( 185 tr( "Cancel"),186 new ImageProvider( "cancel"),188 tr(CANCEL_TR), 189 new ImageProvider(CANCEL), 187 190 null, null) 188 191 }; … … 244 247 ), 245 248 new ButtonSpec( 246 tr( "Cancel"),247 new ImageProvider( "cancel"),249 tr(CANCEL_TR), 250 new ImageProvider(CANCEL), 248 251 tr("Click to cancel and to resume editing the map"), 249 252 null /* no specific help context */ … … 267 270 if (msg.contains("to delete")) { 268 271 DownloadReferrersAction.downloadReferrers(MainApplication.getLayerManager().getEditLayer(), 269 Arrays.asList(conflict.a));272 Collections.singletonList(conflict.a)); 270 273 } 271 274 if (msg.contains("to upload") && !conflict.b.isEmpty()) { -
trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java
r19050 r19106 32 32 import org.openstreetmap.josm.spi.preferences.Config; 33 33 import org.openstreetmap.josm.tools.ImageProvider; 34 import org.openstreetmap.josm.tools.Logging; 34 35 35 36 /** 36 37 * ChangesetManagementPanel allows to configure changeset to be used in the next upload. 37 * 38 * <p> 38 39 * It is displayed as one of the configuration panels in the {@link UploadDialog}. 39 * 40 * <p> 40 41 * ChangesetManagementPanel is a source for {@link java.beans.PropertyChangeEvent}s. Clients can listen to 41 42 * <ul> … … 50 51 static final String SELECTED_CHANGESET_PROP = ChangesetManagementPanel.class.getName() + ".selectedChangeset"; 51 52 static final String CLOSE_CHANGESET_AFTER_UPLOAD = ChangesetManagementPanel.class.getName() + ".closeChangesetAfterUpload"; 53 private static final String UPLOAD_CHANGESET_CLOSE = "upload.changeset.close"; 52 54 53 55 private JosmComboBox<Changeset> cbOpenChangesets; … … 142 144 cbOpenChangesets.addItemListener(closeChangesetAction); 143 145 144 cbCloseAfterUpload.setSelected(Config.getPref().getBoolean( "upload.changeset.close", true));146 cbCloseAfterUpload.setSelected(Config.getPref().getBoolean(UPLOAD_CHANGESET_CLOSE, true)); 145 147 cbCloseAfterUpload.addItemListener(new CloseAfterUploadItemStateListener()); 146 148 … … 198 200 case ItemEvent.SELECTED: 199 201 firePropertyChange(CLOSE_CHANGESET_AFTER_UPLOAD, false, true); 200 Config.getPref().putBoolean( "upload.changeset.close", true);202 Config.getPref().putBoolean(UPLOAD_CHANGESET_CLOSE, true); 201 203 break; 202 204 case ItemEvent.DESELECTED: 203 205 firePropertyChange(CLOSE_CHANGESET_AFTER_UPLOAD, true, false); 204 Config.getPref().putBoolean( "upload.changeset.close", false);206 Config.getPref().putBoolean(UPLOAD_CHANGESET_CLOSE, false); 205 207 break; 206 208 default: // Do nothing … … 262 264 ChangesetCache.getInstance().refreshChangesetsFromServer(); 263 265 } catch (OsmTransferException e) { 264 return;266 Logging.trace(e); 265 267 } 266 268 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadSelectionDialog.java
r16438 r19106 254 254 return Collections.emptyList(); 255 255 return Arrays.stream(indices).filter(i -> i >= 0) 256 .mapToObj( i -> data.get(i))256 .mapToObj(data::get) 257 257 .collect(Collectors.toList()); 258 258 } -
trunk/src/org/openstreetmap/josm/gui/io/importexport/GpxExporter.java
r18801 r19106 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagConstraints; 6 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionListener; … … 55 56 private static final String GPL_WARNING = "<html><font color='red' size='-2'>" 56 57 + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>"; 58 private static final String PUBLIC_DOMAIN = "public domain"; 57 59 58 60 private static final String[] LICENSES = { 59 61 "Creative Commons By-SA", 60 62 "Open Database License (ODbL)", 61 "public domain",63 PUBLIC_DOMAIN, 62 64 "GNU Lesser Public License (LGPL)", 63 65 "BSD License (MIT/X11)"}; … … 65 67 private static final String[] URLS = { 66 68 "https://creativecommons.org/licenses/by-sa/3.0", 67 "http ://opendatacommons.org/licenses/odbl/1.0",68 "public domain",69 "https://opendatacommons.org/licenses/odbl/1-0/", 70 PUBLIC_DOMAIN, 69 71 "https://www.gnu.org/copyleft/lesser.html", 70 "http ://www.opensource.org/licenses/bsd-license.php"};72 "https://opensource.org/license/BSD-2-Clause"}; 71 73 72 74 /** … … 108 110 if (quiet) { 109 111 gpxData = getGpxData(layer, file); 110 try (OutputStream fo = Compression.getCompressedFileOutputStream(file) ) {111 GpxWriter w = new GpxWriter(fo);112 try (OutputStream fo = Compression.getCompressedFileOutputStream(file); 113 GpxWriter w = new GpxWriter(fo)) { 112 114 w.write(gpxData); 113 w.close();114 115 fo.flush(); 115 116 } … … 135 136 desc.setLineWrap(true); 136 137 desc.setText(gpxData.getString(META_DESC)); 137 p.add(new JScrollPane(desc), GBC.eop().fill(G BC.BOTH));138 p.add(new JScrollPane(desc), GBC.eop().fill(GridBagConstraints.BOTH)); 138 139 139 140 JCheckBox author = new JCheckBox(tr("Add author information"), Config.getPref().getBoolean("lastAddAuthor", true)); … … 143 144 p.add(nameLabel, GBC.std().insets(10, 0, 5, 0)); 144 145 JosmTextField authorName = new JosmTextField(); 145 p.add(authorName, GBC.eol().fill(G BC.HORIZONTAL));146 p.add(authorName, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 146 147 nameLabel.setLabelFor(authorName); 147 148 … … 149 150 p.add(emailLabel, GBC.std().insets(10, 0, 5, 0)); 150 151 JosmTextField email = new JosmTextField(); 151 p.add(email, GBC.eol().fill(G BC.HORIZONTAL));152 p.add(email, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 152 153 emailLabel.setLabelFor(email); 153 154 … … 155 156 p.add(copyrightLabel, GBC.std().insets(10, 0, 5, 0)); 156 157 JosmTextField copyright = new JosmTextField(); 157 p.add(copyright, GBC.std().fill(G BC.HORIZONTAL));158 p.add(copyright, GBC.std().fill(GridBagConstraints.HORIZONTAL)); 158 159 copyrightLabel.setLabelFor(copyright); 159 160 … … 164 165 p.add(copyrightYearLabel, GBC.std().insets(10, 0, 5, 5)); 165 166 JosmTextField copyrightYear = new JosmTextField(""); 166 p.add(copyrightYear, GBC.eol().fill(G BC.HORIZONTAL));167 p.add(copyrightYear, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 167 168 copyrightYearLabel.setLabelFor(copyrightYear); 168 169 169 170 JLabel warning = new JLabel("<html><font size='-2'> </html"); 170 p.add(warning, GBC.eol().fill(G BC.HORIZONTAL).insets(15, 0, 0, 0));171 p.add(warning, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(15, 0, 0, 0)); 171 172 addDependencies(gpxData, author, authorName, email, copyright, predefined, copyrightYear, nameLabel, emailLabel, 172 173 copyrightLabel, copyrightYearLabel, warning); … … 175 176 JosmTextField keywords = new JosmTextField(); 176 177 keywords.setText(gpxData.getString(META_KEYWORDS)); 177 p.add(keywords, GBC.eol().fill(G BC.HORIZONTAL));178 p.add(keywords, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 178 179 179 180 boolean sel = Config.getPref().getBoolean("gpx.export.colors", true); 180 181 JCheckBox colors = new JCheckBox(tr("Save track colors in GPX file"), sel); 181 p.add(colors, GBC.eol().fill(G BC.HORIZONTAL));182 p.add(colors, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 182 183 JCheckBox garmin = new JCheckBox(tr("Use Garmin compatible GPX extensions"), 183 184 Config.getPref().getBoolean("gpx.export.colors.garmin", false)); 184 185 garmin.setEnabled(sel); 185 p.add(garmin, GBC.eol().fill(G BC.HORIZONTAL).insets(20, 0, 0, 0));186 p.add(garmin, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(20, 0, 0, 0)); 186 187 187 188 boolean hasPrefs = !gpxData.getLayerPrefs().isEmpty(); … … 189 190 hasPrefs && Config.getPref().getBoolean("gpx.export.prefs", true)); 190 191 layerPrefs.setEnabled(hasPrefs); 191 p.add(layerPrefs, GBC.eop().fill(G BC.HORIZONTAL));192 p.add(layerPrefs, GBC.eop().fill(GridBagConstraints.HORIZONTAL)); 192 193 193 194 ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(), … … 197 198 .setContent(p); 198 199 199 colors.addActionListener(l -> { 200 garmin.setEnabled(colors.isSelected()); 201 }); 200 colors.addActionListener(l -> garmin.setEnabled(colors.isSelected())); 202 201 203 202 garmin.addActionListener(l -> { … … 268 267 } 269 268 270 try (OutputStream fo = Compression.getCompressedFileOutputStream(file) ) {271 GpxWriter w = new GpxWriter(fo) ;269 try (OutputStream fo = Compression.getCompressedFileOutputStream(file); 270 GpxWriter w = new GpxWriter(fo)) { 272 271 w.write(gpxData, cFormat, layerPrefs.isSelected()); 273 w.close();274 272 fo.flush(); 275 273 } … … 409 407 for (int i : l.getSelectedIndices()) { 410 408 if (i == 2) { 411 license = new StringBuilder( "public domain");409 license = new StringBuilder(PUBLIC_DOMAIN); 412 410 break; 413 411 } -
trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java
r18466 r19106 24 24 * <h1>Threading</h1> 25 25 * Synchronization of the layer manager is done by synchronizing all read/write access. All changes are internally done in the EDT thread. 26 * 26 * <p> 27 27 * Methods of this manager may be called from any thread in any order. 28 28 * Listeners are called while this layer manager is locked, so they should not block on other threads. … … 189 189 } 190 190 191 private static final String LISTENER = "listener"; 192 private static final String EVENT = "event"; 193 191 194 /** 192 195 * This is the list of layers we manage. The list is unmodifiable. That way, read access does 193 196 * not need to be synchronized. 194 * 197 * <p> 195 198 * It is only changed in the EDT. 196 199 * @see LayerManager#updateLayers(Consumer) … … 255 258 protected synchronized void realRemoveLayer(Layer layer) { 256 259 GuiHelper.assertCallFromEdt(); 257 Set<Layer> toRemove = Collections.newSetFromMap(new IdentityHashMap< Layer, Boolean>());260 Set<Layer> toRemove = Collections.newSetFromMap(new IdentityHashMap<>()); 258 261 toRemove.add(layer); 259 262 … … 361 364 /** 362 365 * Replies an unmodifiable list of layers of a certain type. 363 * 366 * <p> 364 367 * Example: 365 368 * <pre> … … 459 462 l.layerAdded(e); 460 463 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException t) { 461 throw BugReport.intercept(t).put( "listener", l).put("event", e);464 throw BugReport.intercept(t).put(LISTENER, l).put(EVENT, e); 462 465 } 463 466 } … … 476 479 l.layerRemoving(e); 477 480 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException t) { 478 throw BugReport.intercept(t).put( "listener", l).put("event", e).put("layer", layer);481 throw BugReport.intercept(t).put(LISTENER, l).put(EVENT, e).put("layer", layer); 479 482 } 480 483 } … … 492 495 l.layerOrderChanged(e); 493 496 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException t) { 494 throw BugReport.intercept(t).put( "listener", l).put("event", e);497 throw BugReport.intercept(t).put(LISTENER, l).put(EVENT, e); 495 498 } 496 499 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/SynchronizeTimeFromPhotoDialog.java
r18051 r19106 163 163 JPanel panelLst = new JPanel(new BorderLayout()); 164 164 165 JList<String> imgList = new JList<>(new AbstractListModel< String>() {165 JList<String> imgList = new JList<>(new AbstractListModel<>() { 166 166 @Override 167 167 public String getElementAt(int i) { -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r18871 r19106 593 593 for (WayPoint trkPnt : segment) { 594 594 Object val = trkPnt.get(GpxConstants.PT_HDOP); 595 if (val != null) {596 double hdop = ((Float) val) .doubleValue();595 if (val instanceof Float) { 596 double hdop = ((Float) val); 597 597 if (hdop > maxval) { 598 598 maxval = hdop; … … 1466 1466 1467 1467 // typical rendering rate -> use realtime preview instead of accurate display 1468 final double maxSegm = 25_000, nrSegms = listSegm.size(); 1468 final double maxSegm = 25_000; 1469 final double nrSegms = listSegm.size(); 1469 1470 1470 1471 // determine random drop rate … … 1511 1512 1512 1513 // collect frequently used items 1513 final long fromX = (long) fromPnt.getX(); final long deltaX = (long) (toPnt.getX() - fromX); 1514 final long fromY = (long) fromPnt.getY(); final long deltaY = (long) (toPnt.getY() - fromY); 1514 final long fromX = (long) fromPnt.getX(); 1515 final long fromY = (long) fromPnt.getY(); 1516 final long deltaX = (long) (toPnt.getX() - fromX); 1517 final long deltaY = (long) (toPnt.getY() - fromY); 1515 1518 1516 1519 // use same random values for each point -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r16488 r19106 81 81 * Create a new {@link TileSourceDisplaySettings} 82 82 */ 83 @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") // See https://github.com/pmd/pmd/issues/5069 83 84 public TileSourceDisplaySettings() { 84 85 this(new String[] {PREFERENCE_PREFIX}); -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r18211 r19106 83 83 * @author imi 84 84 */ 85 @SuppressWarnings("deprecation")86 85 public final class PreferenceTabbedPane extends JTabbedPane implements ExpertModeChangeListener, ChangeListener { 87 86 … … 118 117 } 119 118 if (requiresRestart) { 120 sb.append(tr("You have to restart JOSM for some settings to take effect.")) ;121 sb.append("<br/><br/>");122 sb.append(tr("Would you like to restart now?"));119 sb.append(tr("You have to restart JOSM for some settings to take effect.")) 120 .append("<br/><br/>") 121 .append(tr("Would you like to restart now?")); 123 122 } 124 123 sb.append("</html>"); … … 358 357 selectTabBy(tps -> tps.equals(tab)); 359 358 return tab.selectSubTab(sub); 360 } catch (NoSuchElementException ignore) {361 Logging.trace( ignore);359 } catch (NoSuchElementException e) { 360 Logging.trace(e); 362 361 return false; 363 362 } … … 564 563 private int computeMaxTabWidth() { 565 564 FontMetrics fm = getFontMetrics(getFont()); 566 return settings.stream().filter(x -> x instanceof TabPreferenceSetting).map(x -> ((TabPreferenceSetting) x).getTitle()) 565 return settings.stream().filter(TabPreferenceSetting.class::isInstance) 566 .map(TabPreferenceSetting.class::cast).map(TabPreferenceSetting::getTitle) 567 567 .filter(Objects::nonNull).mapToInt(fm::stringWidth).max().orElse(120); 568 568 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r19101 r19106 859 859 }); 860 860 861 ListCellRenderer<ActionDefinition> renderer = new ListCellRenderer< ActionDefinition>() {861 ListCellRenderer<ActionDefinition> renderer = new ListCellRenderer<>() { 862 862 private final DefaultListCellRenderer def = new DefaultListCellRenderer(); 863 863 864 @Override 864 865 public Component getListCellRendererComponent(JList<? extends ActionDefinition> list, 865 ActionDefinition action, int index, boolean isSelected, boolean cellHasFocus) {866 ActionDefinition action, int index, boolean isSelected, boolean cellHasFocus) { 866 867 String s; 867 868 Icon i; -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CacheSettingsPanel.java
r18871 r19106 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagConstraints; 6 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionEvent; … … 60 61 private final JosmTextField cacheDir = new JosmTextField(11); 61 62 private final JSpinner maxElementsOnDisk = new JSpinner(new SpinnerNumberModel( 62 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().intValue(), 0, Integer.MAX_VALUE, 1));63 (int) AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get(), 0, Integer.MAX_VALUE, 1)); 63 64 64 65 /** … … 70 71 add(new JLabel(tr("Tile cache directory: ")), GBC.std()); 71 72 add(GBC.glue(5, 0), GBC.std()); 72 add(cacheDir, GBC.eol().fill(G BC.HORIZONTAL));73 add(cacheDir, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 73 74 74 75 add(new JLabel(tr("Maximum size of disk cache (per imagery) in MB: ")), GBC.std()); … … 94 95 GBC.eol().insets(5, 5, 0, 0)); 95 96 add(new JScrollPane(getTableForCache(cache, tableModel)), 96 GBC.eol().fill(G BC.BOTH));97 GBC.eol().fill(GridBagConstraints.BOTH)); 97 98 }); 98 99 } … … 212 213 private static boolean removeCacheFiles(String path, long maxSize) { 213 214 File directory = new File(path); 214 File[] cacheFiles = directory.listFiles((dir, name) -> name.endsWith(".data") || name.endsWith(".key")); 215 final String data = ".data"; 216 final String key = ".key"; 217 File[] cacheFiles = directory.listFiles((dir, name) -> name.endsWith(data) || name.endsWith(key)); 215 218 boolean restartRequired = false; 216 219 if (cacheFiles != null) { … … 223 226 Utils.deleteFile(cacheFile); 224 227 File otherFile = null; 225 if (cacheFile.getName().endsWith( ".data")) {226 otherFile = new File(cacheFile.getPath().replaceAll("\\.data$", ".key"));227 } else if (cacheFile.getName().endsWith( ".key")) {228 otherFile = new File(cacheFile.getPath().replaceAll("\\.key$", ".data"));228 if (cacheFile.getName().endsWith(data)) { 229 otherFile = new File(cacheFile.getPath().replaceAll("\\.data$", key)); 230 } else if (cacheFile.getName().endsWith(key)) { 231 otherFile = new File(cacheFile.getPath().replaceAll("\\.key$", data)); 229 232 } 230 233 if (otherFile != null) { -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java
r19103 r19106 49 49 TMSLayer.MAX_ZOOM, 1)); 50 50 maxConcurrentDownloads = new JSpinner(new SpinnerNumberModel( 51 TMSCachedTileLoader.THREAD_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));51 (int) TMSCachedTileLoader.THREAD_LIMIT.get(), 0, Integer.MAX_VALUE, 1)); 52 52 maxDownloadsPerHost = new JSpinner(new SpinnerNumberModel( 53 TMSCachedTileLoader.HOST_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));53 (int) TMSCachedTileLoader.HOST_LIMIT.get(), 0, Integer.MAX_VALUE, 1)); 54 54 55 55 -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r18871 r19106 3 3 4 4 import static java.awt.GridBagConstraints.HORIZONTAL; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 import static org.openstreetmap.josm.tools.I18n.trc; … … 71 72 */ 72 73 public final class PluginPreference extends ExtensibleTabPreferenceSetting { 74 private static final String HTML_START = "<html>"; 75 private static final String HTML_END = "</html>"; 76 private static final String UPDATE_PLUGINS = marktr("Update plugins"); 73 77 74 78 /** … … 112 116 downloaded.size(), 113 117 downloaded.size() 114 )) ;115 sb.append("<ul>");118 )) 119 .append("<ul>"); 116 120 for (PluginInformation pi: downloaded) { 117 121 sb.append("<li>").append(pi.name).append(" (").append(pi.version).append(")</li>"); … … 125 129 failed.size(), 126 130 failed.size() 127 )) ;128 sb.append("<ul>");131 )) 132 .append("<ul>"); 129 133 for (PluginInformation pi: failed) { 130 134 sb.append("<li>").append(pi.name).append("</li>"); … … 149 153 final Collection<PluginInformation> failed = task.getFailedPlugins(); 150 154 final StringBuilder sb = new StringBuilder(); 151 sb.append( "<html>")155 sb.append(HTML_START) 152 156 .append(buildDownloadSummary(task)); 153 157 if (restartRequired) { 154 158 sb.append(tr("Please restart JOSM to activate the downloaded plugins.")); 155 159 } 156 sb.append( "</html>");160 sb.append(HTML_END); 157 161 GuiHelper.runInEDTAndWait(() -> HelpAwareOptionPane.showOptionDialog( 158 162 parent, 159 163 sb.toString(), 160 tr( "Update plugins"),164 tr(UPDATE_PLUGINS), 161 165 !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE, 162 166 HelpUtil.ht("/Preferences/Plugins") … … 375 379 class UpdateSelectedPluginsAction extends AbstractAction { 376 380 UpdateSelectedPluginsAction() { 377 putValue(NAME, tr( "Update plugins"));381 putValue(NAME, tr(UPDATE_PLUGINS)); 378 382 putValue(SHORT_DESCRIPTION, tr("Update the selected plugins")); 379 383 new ImageProvider("dialogs", "refresh").getResource().attachImageIcon(this); … … 388 392 JOptionPane.INFORMATION_MESSAGE, 389 393 null // FIXME: provide help context 390 )); 391 } catch (InterruptedException | InvocationTargetException e) { 394 )); 395 } catch (InterruptedException e) { 396 Thread.currentThread().interrupt(); 397 Logging.error(e); 398 } catch (InvocationTargetException e) { 392 399 Logging.error(e); 393 400 } … … 401 408 pnlPluginPreferences, 402 409 toUpdate, 403 tr( "Update plugins")410 tr(UPDATE_PLUGINS) 404 411 ); 405 412 // the async task for downloading plugin information … … 444 451 // Time to find the missing plugins... 445 452 toAdd.addAll(pi.getRequiredPlugins().stream().filter(plugin -> PluginHandler.getPlugin(plugin) == null) 446 .map( plugin -> model.getPluginInformation(plugin))453 .map(model::getPluginInformation) 447 454 .collect(Collectors.toSet())); 448 455 } … … 502 509 JCheckBox deleteNotInList = new JCheckBox(tr("Disable all other plugins")); 503 510 504 JLabel helpLabel = new JLabel( "<html>"+ String.join("<br/>",511 JLabel helpLabel = new JLabel(HTML_START + String.join("<br/>", 505 512 tr("Enter a list of plugins you want to download."), 506 513 tr("You should add one plugin id per line, version information is ignored."), 507 tr("You can copy+paste the list of a status report here.")) + "</html>");514 tr("You can copy+paste the list of a status report here.")) + HTML_END); 508 515 509 516 if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(GuiHelper.getFrameForComponent(getTabPane()), … … 556 563 private boolean confirmIgnoreNotFound(List<String> notFound) { 557 564 String list = "<ul><li>" + String.join("</li><li>", notFound) + "</li></ul>"; 558 String message = "<html>" + tr("The following plugins were not found. Continue anyway?") + list + "</html>";565 String message = HTML_START + tr("The following plugins were not found. Continue anyway?") + list + HTML_END; 559 566 return JOptionPane.showConfirmDialog(GuiHelper.getFrameForComponent(getTabPane()), 560 567 message) == JOptionPane.OK_OPTION; -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompComboBox.java
r18305 r19106 32 32 */ 33 33 public AutoCompComboBox() { 34 this(new AutoCompComboBoxModel< E>());34 this(new AutoCompComboBoxModel<>()); 35 35 } 36 36 … … 42 42 public AutoCompComboBox(AutoCompComboBoxModel<E> model) { 43 43 super(model); 44 setEditor(new AutoCompComboBoxEditor< E>());44 setEditor(new AutoCompComboBoxEditor<>()); 45 45 setEditable(true); 46 46 getEditorComponent().setModel(model); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemGuiSupport.java
r18801 r19106 135 135 Tagged tagged = Tagged.ofMap(selected.iterator().next().getKeys()); 136 136 // update changed tags 137 changedTagsSupplier.get().forEach(tag -> tagged.put(tag));137 changedTagsSupplier.get().forEach(tagged::put); 138 138 return tagged; 139 139 } -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r19050 r19106 147 147 .collect(Collectors.toList()); 148 148 149 validprefixes = namespaces.stream().map( n -> n.getPrefix()).collect(Collectors.toList());149 validprefixes = namespaces.stream().map(XMLNamespace::getPrefix).collect(Collectors.toList()); 150 150 151 151 data.creator = JOSM_CREATOR_NAME; -
trunk/src/org/openstreetmap/josm/io/MaxChangesetSizeExceededPolicy.java
r12687 r19106 6 6 * @since 12687 (moved from {@code gui.io} package) 7 7 */ 8 @SuppressWarnings("PMD.LongVariable") 8 9 public enum MaxChangesetSizeExceededPolicy { 9 10 /** -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r19050 r19106 357 357 Logging.error(e); 358 358 if (e.getCause() instanceof OsmTransferException) 359 throw (OsmTransferException) e.getCause(); 359 throw (OsmTransferException) e.getCause(); // NOPMD 360 360 } 361 361 } -
trunk/src/org/openstreetmap/josm/io/OsmPbfReader.java
r19077 r19106 7 7 import java.io.IOException; 8 8 import java.io.InputStream; 9 import java.io.OutputStream;10 9 import java.util.ArrayList; 11 10 import java.util.Arrays; … … 68 67 @Override 69 68 public int read() throws IOException { 70 count++; 71 return this.source.read(); 69 final int read = this.source.read(); 70 if (read > 0) { 71 count++; 72 } 73 return read; 74 } 75 76 @Override 77 public int read(@Nonnull byte[] b, int off, int len) throws IOException { 78 final int read = this.source.read(b, off, len); 79 if (read > 0) { 80 this.count += read; 81 } 82 return read; 72 83 } 73 84 … … 104 115 public boolean markSupported() { 105 116 return this.source.markSupported(); 106 }107 108 @Override109 public long transferTo(OutputStream out) throws IOException {110 return super.transferTo(out);111 117 } 112 118 … … 251 257 int size = Integer.MIN_VALUE; 252 258 Blob.CompressionType type = null; 253 ProtobufRecord current;254 259 // Needed since size and compression type + compression data may be in a different order 255 260 byte[] bytes = null; 256 261 while (parser.hasNext() && cis.getCount() - start < header.dataSize()) { 257 current = new ProtobufRecord(baos, parser); 258 switch (current.getField()) { 259 case 1: 260 type = Blob.CompressionType.raw; 261 bytes = current.getBytes(); 262 break; 263 case 2: 264 size = current.asUnsignedVarInt().intValue(); 265 break; 266 case 3: 267 type = Blob.CompressionType.zlib; 268 bytes = current.getBytes(); 269 break; 270 case 4: 271 type = Blob.CompressionType.lzma; 272 bytes = current.getBytes(); 273 break; 274 case 5: 275 type = Blob.CompressionType.bzip2; 276 bytes = current.getBytes(); 277 break; 278 case 6: 279 type = Blob.CompressionType.lz4; 280 bytes = current.getBytes(); 281 break; 282 case 7: 283 type = Blob.CompressionType.zstd; 284 bytes = current.getBytes(); 285 break; 286 default: 287 throw new IllegalStateException("Unknown compression type: " + current.getField()); 262 try (ProtobufRecord current = new ProtobufRecord(baos, parser)) { 263 switch (current.getField()) { 264 case 1: 265 type = Blob.CompressionType.raw; 266 bytes = current.getBytes(); 267 break; 268 case 2: 269 size = current.asUnsignedVarInt().intValue(); 270 break; 271 case 3: 272 type = Blob.CompressionType.zlib; 273 bytes = current.getBytes(); 274 break; 275 case 4: 276 type = Blob.CompressionType.lzma; 277 bytes = current.getBytes(); 278 break; 279 case 5: 280 type = Blob.CompressionType.bzip2; 281 bytes = current.getBytes(); 282 break; 283 case 6: 284 type = Blob.CompressionType.lz4; 285 bytes = current.getBytes(); 286 break; 287 case 7: 288 type = Blob.CompressionType.zstd; 289 bytes = current.getBytes(); 290 break; 291 default: 292 throw new IllegalStateException("Unknown compression type: " + current.getField()); 293 } 288 294 } 289 295 } … … 421 427 } 422 428 for (ProtobufRecord primitiveGroup : primitiveGroups) { 423 try {429 try (primitiveGroup) { 424 430 ds.beginUpdate(); 425 431 parsePrimitiveGroup(baos, primitiveGroup.getBytes(), primitiveBlockRecord); -
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionExporter.java
r18466 r19106 79 79 80 80 @Override 81 @SuppressWarnings("resource") 81 // The new closable resources in this method will close the input OutputStream 82 @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) 82 83 protected void addDataFile(OutputStream out) { 83 84 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java
r18466 r19106 3 3 4 4 import java.awt.Component; 5 import java.awt.GridBagConstraints; 5 6 import java.awt.GridBagLayout; 6 7 import java.io.IOException; … … 18 19 import javax.swing.SwingConstants; 19 20 21 import org.openstreetmap.josm.data.gpx.GpxConstants; 20 22 import org.openstreetmap.josm.data.gpx.GpxData; 21 23 import org.openstreetmap.josm.gui.MainApplication; … … 66 68 p.add(export, GBC.std()); 67 69 p.add(lbl, GBC.std()); 68 p.add(GBC.glue(1, 0), GBC.std().fill(G BC.HORIZONTAL));70 p.add(GBC.glue(1, 0), GBC.std().fill(GridBagConstraints.HORIZONTAL)); 69 71 return p; 70 72 } … … 93 95 } 94 96 95 @SuppressWarnings("resource") 97 // The new closable resources in this method will close the input OutputStream 98 @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) 96 99 protected void addDataFile(OutputStream out) { 97 100 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); … … 132 135 } 133 136 }); 134 data.put(Gpx Data.META_DESC, "exported JOSM marker layer");137 data.put(GpxConstants.META_DESC, "exported JOSM marker layer"); 135 138 for (Marker m : layer.data) { 136 139 data.waypoints.add(m.convertToWayPoint()); -
trunk/src/org/openstreetmap/josm/plugins/PluginClassLoader.java
r17664 r19106 59 59 Class<?> result = findLoadedClass(name); 60 60 if (result == null) { 61 for (PluginClassLoader dep : dependencies) { 62 try { 63 result = dep.loadClass(name, resolve); 64 if (result != null) { 65 return result; 66 } 67 } catch (ClassNotFoundException e) { 68 Logging.trace("Plugin class not found in dep {0}: {1}", dep, e.getMessage()); 69 Logging.trace(e); 70 } 71 } 61 result = findClassInDependencies(name, resolve); 72 62 try { 73 63 // Will delegate to parent.loadClass(name, resolve) if needed … … 93 83 } 94 84 85 /** 86 * Try to find the specified class in this classes dependencies 87 * @param name The name of the class to find 88 * @param resolve {@code true} to resolve the class 89 * @return the class, if found, otherwise {@code null} 90 */ 91 @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method... 92 private Class<?> findClassInDependencies(String name, boolean resolve) { 93 for (PluginClassLoader dep : dependencies) { 94 try { 95 Class<?> result = dep.loadClass(name, resolve); 96 if (result != null) { 97 return result; 98 } 99 } catch (ClassNotFoundException e) { 100 Logging.trace("Plugin class not found in dep {0}: {1}", dep, e.getMessage()); 101 Logging.trace(e); 102 } 103 } 104 return null; 105 } 106 95 107 @Override 108 @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method... 96 109 public URL findResource(String name) { 97 110 URL resource = super.findResource(name); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r19101 r19106 56 56 import javax.swing.UIManager; 57 57 58 import jakarta.annotation.Nullable; 58 59 import org.openstreetmap.josm.actions.RestartAction; 59 60 import org.openstreetmap.josm.data.Preferences; … … 770 771 771 772 // make sure the dependencies to other plugins are not broken 772 //773 773 if (requires != null) { 774 Set<String> pluginNames = new HashSet<>(); 775 for (PluginInformation pi: plugins) { 776 pluginNames.add(pi.name); 777 if (pi.provides != null) { 778 pluginNames.add(pi.provides); 779 } 780 } 781 Set<String> missingPlugins = new HashSet<>(); 782 List<String> requiredPlugins = local ? plugin.getLocalRequiredPlugins() : plugin.getRequiredPlugins(); 783 for (String requiredPlugin : requiredPlugins) { 784 if (!pluginNames.contains(requiredPlugin)) { 785 missingPlugins.add(requiredPlugin); 786 } 787 } 774 Set<String> missingPlugins = findMissingPlugins(plugins, plugin, local); 788 775 if (!missingPlugins.isEmpty()) { 789 776 if (parent != null) { … … 794 781 } 795 782 return true; 783 } 784 785 /** 786 * Find the missing plugin(s) for a specified plugin 787 * @param plugins The currently loaded plugins 788 * @param plugin The plugin to find the missing information for 789 * @param local Determines if the local or up-to-date plugin dependencies are to be checked. 790 * @return A set of missing plugins for the given plugin 791 */ 792 private static Set<String> findMissingPlugins(Collection<PluginInformation> plugins, PluginInformation plugin, boolean local) { 793 Set<String> pluginNames = new HashSet<>(); 794 for (PluginInformation pi: plugins) { 795 pluginNames.add(pi.name); 796 if (pi.provides != null) { 797 pluginNames.add(pi.provides); 798 } 799 } 800 Set<String> missingPlugins = new HashSet<>(); 801 List<String> requiredPlugins = local ? plugin.getLocalRequiredPlugins() : plugin.getRequiredPlugins(); 802 for (String requiredPlugin : requiredPlugins) { 803 if (!pluginNames.contains(requiredPlugin)) { 804 missingPlugins.add(requiredPlugin); 805 } 806 } 807 return missingPlugins; 796 808 } 797 809 … … 818 830 * @param plugins the plugins to add 819 831 */ 832 @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method... 820 833 private static void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins) { 821 834 // iterate all plugins and collect all libraries of all plugins: … … 901 914 return; 902 915 903 for (PluginInformation info : toLoad) { 904 PluginClassLoader cl = AccessController.doPrivileged((PrivilegedAction<PluginClassLoader>) 905 () -> new PluginClassLoader( 906 info.libraries.toArray(new URL[0]), 907 PluginHandler.class.getClassLoader(), 908 null)); 909 classLoaders.put(info.name, cl); 910 } 916 generateClassloaders(toLoad); 911 917 912 918 // resolve dependencies 913 for (PluginInformation info : toLoad) { 914 PluginClassLoader cl = classLoaders.get(info.name); 915 DEPENDENCIES: 916 for (String depName : info.getLocalRequiredPlugins()) { 917 for (PluginInformation depInfo : toLoad) { 918 if (isDependency(depInfo, depName)) { 919 cl.addDependency(classLoaders.get(depInfo.name)); 920 continue DEPENDENCIES; 921 } 922 } 923 for (PluginProxy proxy : pluginList) { 924 if (isDependency(proxy.getPluginInformation(), depName)) { 925 cl.addDependency(proxy.getClassLoader()); 926 continue DEPENDENCIES; 927 } 928 } 929 Logging.error("unable to find dependency " + depName + " for plugin " + info.getName()); 930 } 931 } 919 resolveDependencies(toLoad); 932 920 933 921 extendJoinedPluginResourceCL(toLoad); … … 944 932 } 945 933 934 /** 935 * Generate classloaders for a list of plugins 936 * @param toLoad The plugins to generate the classloaders for 937 */ 938 @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // NOSONAR the classloaders and put in a map which we want to keep. 939 private static void generateClassloaders(List<PluginInformation> toLoad) { 940 for (PluginInformation info : toLoad) { 941 PluginClassLoader cl = AccessController.doPrivileged((PrivilegedAction<PluginClassLoader>) 942 () -> new PluginClassLoader( 943 info.libraries.toArray(new URL[0]), 944 PluginHandler.class.getClassLoader(), 945 null)); 946 classLoaders.put(info.name, cl); 947 } 948 } 949 950 /** 951 * Resolve dependencies for a list of plugins 952 * @param toLoad The plugins to resolve dependencies for 953 */ 954 @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // NOSONAR the classloaders are from a persistent map 955 private static void resolveDependencies(List<PluginInformation> toLoad) { 956 for (PluginInformation info : toLoad) { 957 PluginClassLoader cl = classLoaders.get(info.name); 958 for (String depName : info.getLocalRequiredPlugins()) { 959 boolean finished = false; 960 for (PluginInformation depInfo : toLoad) { 961 if (isDependency(depInfo, depName)) { 962 cl.addDependency(classLoaders.get(depInfo.name)); 963 finished = true; 964 break; 965 } 966 } 967 if (finished) { 968 continue; 969 } 970 for (PluginProxy proxy : pluginList) { 971 if (isDependency(proxy.getPluginInformation(), depName)) { 972 cl.addDependency(proxy.getClassLoader()); 973 break; 974 } 975 } 976 Logging.error("unable to find dependency " + depName + " for plugin " + info.getName()); 977 } 978 } 979 } 980 946 981 private static boolean isDependency(PluginInformation pi, String depName) { 947 982 return depName.equals(pi.getName()) || depName.equals(pi.provides); … … 999 1034 * 1000 1035 */ 1036 @Nullable 1037 @SuppressWarnings("squid:S1168") // The null return is part of the API for this method. 1001 1038 private static Map<String, PluginInformation> loadLocallyAvailablePluginInformation(ProgressMonitor monitor) { 1002 1039 if (monitor == null) { … … 1012 1049 return null; 1013 1050 } catch (InterruptedException e) { 1051 Thread.currentThread().interrupt(); 1014 1052 Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName() 1015 1053 + " while loading locally available plugin information"); … … 1027 1065 1028 1066 private static void alertMissingPluginInformation(Component parent, Collection<String> plugins) { 1029 StringBuilder sb = new StringBuilder(); 1030 sb.append(HTML_START) 1031 .append(trn("JOSM could not find information about the following plugin:", 1032 "JOSM could not find information about the following plugins:", 1033 plugins.size())) 1034 .append(Utils.joinAsHtmlUnorderedList(plugins)) 1035 .append(trn("The plugin is not going to be loaded.", 1036 "The plugins are not going to be loaded.", 1037 plugins.size())) 1038 .append(HTML_END); 1067 String sb = HTML_START + 1068 trn("JOSM could not find information about the following plugin:", 1069 "JOSM could not find information about the following plugins:", 1070 plugins.size()) + 1071 Utils.joinAsHtmlUnorderedList(plugins) + 1072 trn("The plugin is not going to be loaded.", 1073 "The plugins are not going to be loaded.", 1074 plugins.size()) + 1075 HTML_END; 1039 1076 HelpAwareOptionPane.showOptionDialog( 1040 1077 parent, 1041 sb .toString(),1078 sb, 1042 1079 tr(WARNING), 1043 1080 JOptionPane.WARNING_MESSAGE, … … 1191 1228 // don't abort in case of error, continue with downloading plugins below 1192 1229 } catch (InterruptedException e) { 1230 Thread.currentThread().interrupt(); 1193 1231 Logging.warn(tr("Failed to download plugin information list") + ": InterruptedException"); 1194 1232 // don't abort in case of error, continue with downloading plugins below … … 1240 1278 return plugins; 1241 1279 } catch (InterruptedException e) { 1280 Thread.currentThread().interrupt(); 1242 1281 Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName() 1243 1282 + " while updating plugins"); … … 1535 1574 GuiHelper.runInEDT(task); 1536 1575 return task.get(); 1537 } catch (InterruptedException | ExecutionException e) { 1576 } catch (InterruptedException e) { 1577 Thread.currentThread().interrupt(); 1578 Logging.warn(e); 1579 } catch (ExecutionException e) { 1538 1580 Logging.warn(e); 1539 1581 } -
trunk/src/org/openstreetmap/josm/spi/lifecycle/Lifecycle.java
r17663 r19106 67 67 * @since 14139 68 68 */ 69 // PMD wasn't detecting that we were trying to shutdown the ExecutorService 70 @SuppressWarnings("PMD.CloseResource") 69 71 public static void initialize(InitializationSequence initSequence) { 70 72 // Initializes tasks that must be run before parallel tasks … … 90 92 Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown executor service", e); 91 93 } 92 } catch (InterruptedException | ExecutionException ex) { 94 } catch (InterruptedException ex) { 95 Thread.currentThread().interrupt(); 96 throw new JosmRuntimeException(ex); 97 } catch (ExecutionException ex) { 93 98 throw new JosmRuntimeException(ex); 94 99 }
Note:
See TracChangeset
for help on using the changeset viewer.