Changeset 14977 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-04-09T01:32:56+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r14153 r14977 16 16 import java.nio.file.InvalidPathException; 17 17 import java.util.ArrayList; 18 import java.util.Arrays; 18 19 import java.util.Collection; 19 20 import java.util.Collections; … … 44 45 import org.openstreetmap.josm.spi.preferences.AbstractPreferences; 45 46 import org.openstreetmap.josm.spi.preferences.Config; 47 import org.openstreetmap.josm.spi.preferences.DefaultPreferenceChangeEvent; 46 48 import org.openstreetmap.josm.spi.preferences.IBaseDirectories; 47 49 import org.openstreetmap.josm.spi.preferences.ListSetting; 50 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; 48 51 import org.openstreetmap.josm.spi.preferences.Setting; 49 52 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 51 54 import org.openstreetmap.josm.tools.Logging; 52 55 import org.openstreetmap.josm.tools.PlatformManager; 56 import org.openstreetmap.josm.tools.ReflectionUtils; 53 57 import org.openstreetmap.josm.tools.Utils; 54 58 import org.xml.sax.SAXException; … … 120 124 121 125 /** 126 * Preferences classes calling directly the method {@link #putSetting(String, Setting)}. 127 * This collection allows us to exclude them when searching the business class who set a preference. 128 * The found class is used as event source when notifying event listeners. 129 */ 130 private static final Collection<Class<?>> preferencesClasses = Arrays.asList( 131 Preferences.class, PreferencesUtils.class, AbstractPreferences.class); 132 133 /** 122 134 * Constructs a new {@code Preferences}. 123 135 */ … … 216 228 217 229 protected void firePreferenceChanged(String key, Setting<?> oldValue, Setting<?> newValue) { 218 final org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent evt =219 new org.openstreetmap.josm.spi.preferences.DefaultPreferenceChangeEvent(key, oldValue, newValue);230 final PreferenceChangeEvent evt = 231 new DefaultPreferenceChangeEvent(ReflectionUtils.findCallerClass(preferencesClasses), key, oldValue, newValue); 220 232 listeners.fireEvent(listener -> listener.preferenceChanged(evt)); 221 233 -
trunk/src/org/openstreetmap/josm/data/StructUtils.java
r13647 r14977 33 33 import org.openstreetmap.josm.tools.Logging; 34 34 import org.openstreetmap.josm.tools.MultiMap; 35 import org.openstreetmap.josm.tools. Utils;35 import org.openstreetmap.josm.tools.ReflectionUtils; 36 36 37 37 /** … … 161 161 } 162 162 try { 163 Utils.setObjectsAccessible(f);163 ReflectionUtils.setObjectsAccessible(f); 164 164 Object fieldValue = f.get(struct); 165 165 Object defaultFieldValue = f.get(structPrototype); … … 215 215 continue; 216 216 } 217 Utils.setObjectsAccessible(f);217 ReflectionUtils.setObjectsAccessible(f); 218 218 if (f.getType() == Boolean.class || f.getType() == boolean.class) { 219 219 value = Boolean.valueOf(keyValue.getValue()); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r14695 r14977 158 158 import org.openstreetmap.josm.tools.PlatformHookWindows; 159 159 import org.openstreetmap.josm.tools.PlatformManager; 160 import org.openstreetmap.josm.tools.ReflectionUtils; 160 161 import org.openstreetmap.josm.tools.Shortcut; 161 162 import org.openstreetmap.josm.tools.Utils; … … 991 992 try { 992 993 Field field = Toolkit.class.getDeclaredField("resources"); 993 Utils.setObjectsAccessible(field);994 ReflectionUtils.setObjectsAccessible(field); 994 995 field.set(null, ResourceBundle.getBundle("sun.awt.resources.awt")); 995 996 } catch (ReflectiveOperationException | RuntimeException e) { // NOPMD -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r14379 r14977 253 253 tr("The name of the object at the mouse pointer."), 254 254 getNameLabelCharacterCount(MainApplication.getMainFrame()), PROP_BACKGROUND_COLOR.get()); 255 private final JosmTextField helpText = new JosmTextField( );255 private final JosmTextField helpText = new JosmTextField(null, null, 0, false); 256 256 private final JProgressBar progressBar = new JProgressBar(); 257 257 private final transient ComponentAdapter mvComponentAdapter; -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
r14555 r14977 57 57 58 58 // CHECKSTYLE.OFF: SingleSpaceSeparator 59 private final JosmTextField tfID = new JosmTextField( 10);59 private final JosmTextField tfID = new JosmTextField(null, null, 10, false); 60 60 private final JosmTextArea taComment = new JosmTextArea(5, 40); 61 private final JosmTextField tfOpen = new JosmTextField( 10);62 private final JosmTextField tfUser = new JosmTextField( "");63 private final JosmTextField tfCreatedOn = new JosmTextField( 20);64 private final JosmTextField tfClosedOn = new JosmTextField( 20);61 private final JosmTextField tfOpen = new JosmTextField(null, null, 10, false); 62 private final JosmTextField tfUser = new JosmTextField(null, "", 0); 63 private final JosmTextField tfCreatedOn = new JosmTextField(null, null, 20, false); 64 private final JosmTextField tfClosedOn = new JosmTextField(null, null, 20, false); 65 65 66 66 private final OpenChangesetPopupMenuAction actOpenChangesetPopupMenu = new OpenChangesetPopupMenuAction(); -
trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java
r12846 r14977 17 17 import java.util.LinkedList; 18 18 import java.util.List; 19 import java.util.Objects; 19 20 import java.util.concurrent.TimeUnit; 20 21 … … 33 34 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 34 35 import org.openstreetmap.josm.spi.preferences.Config; 35 import org.openstreetmap.josm.tools.CheckParameterUtil;36 36 import org.openstreetmap.josm.tools.GBC; 37 37 import org.openstreetmap.josm.tools.Utils; … … 78 78 hcbUploadComment.setToolTipText(tr("Enter an upload comment")); 79 79 hcbUploadComment.setMaxTextLength(Changeset.MAX_CHANGESET_TAG_LENGTH); 80 List<String> cmtHistory = new LinkedList<>(Config.getPref().getList(HISTORY_KEY, new LinkedList<String>())); 81 Collections.reverse(cmtHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 82 hcbUploadComment.setPossibleItems(cmtHistory); 80 populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<String>()); 83 81 CommentModelListener commentModelListener = new CommentModelListener(hcbUploadComment, changesetCommentModel); 84 82 hcbUploadComment.getEditor().addActionListener(commentModelListener); … … 92 90 final String source = MainApplication.getMap().mapView.getLayerInformationForSourceTag(); 93 91 hcbUploadSource.setText(Utils.shortenString(source, Changeset.MAX_CHANGESET_TAG_LENGTH)); 94 // Fix #9965 95 changesetSourceModel.setComment(hcbUploadSource.getText()); 92 changesetSourceModel.setComment(hcbUploadSource.getText()); // Fix #9965 96 93 } 97 94 }); … … 100 97 hcbUploadSource.setToolTipText(tr("Enter a source")); 101 98 hcbUploadSource.setMaxTextLength(Changeset.MAX_CHANGESET_TAG_LENGTH); 102 List<String> sourceHistory = new LinkedList<>(Config.getPref().getList(SOURCE_HISTORY_KEY, getDefaultSources())); 103 Collections.reverse(sourceHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 104 hcbUploadSource.setPossibleItems(sourceHistory); 99 populateHistoryComboBox(hcbUploadSource, SOURCE_HISTORY_KEY, getDefaultSources()); 105 100 CommentModelListener sourceModelListener = new CommentModelListener(hcbUploadSource, changesetSourceModel); 106 101 hcbUploadSource.getEditor().addActionListener(sourceModelListener); … … 108 103 pnl.add(hcbUploadSource, GBC.eol().fill(GBC.HORIZONTAL)); 109 104 return pnl; 105 } 106 107 /** 108 * Refreshes contents of upload history combo boxes from preferences. 109 */ 110 protected void refreshHistoryComboBoxes() { 111 populateHistoryComboBox(hcbUploadComment, HISTORY_KEY, new LinkedList<String>()); 112 populateHistoryComboBox(hcbUploadSource, SOURCE_HISTORY_KEY, getDefaultSources()); 113 } 114 115 private static void populateHistoryComboBox(HistoryComboBox hcb, String historyKey, List<String> defaultValues) { 116 List<String> cmtHistory = new LinkedList<>(Config.getPref().getList(historyKey, defaultValues)); 117 Collections.reverse(cmtHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 118 hcb.setPossibleItems(cmtHistory); 119 hcb.discardAllUndoableEdits(); 120 } 121 122 /** 123 * Discards undoable edits of upload history combo boxes. 124 */ 125 protected void discardAllUndoableEdits() { 126 hcbUploadComment.discardAllUndoableEdits(); 127 hcbUploadSource.discardAllUndoableEdits(); 110 128 } 111 129 … … 133 151 * @param changesetSourceModel the model for the changeset source. Must not be null. 134 152 * @param changesetReviewModel the model for the changeset review. Must not be null. 135 * @throws IllegalArgumentException if {@code changesetCommentModel}is null153 * @throws NullPointerException if a model is null 136 154 * @since 12719 (signature) 137 155 */ 138 156 public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel, 139 157 ChangesetReviewModel changesetReviewModel) { 140 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 141 CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel"); 142 CheckParameterUtil.ensureParameterNotNull(changesetReviewModel, "changesetReviewModel"); 143 this.changesetCommentModel = changesetCommentModel; 144 this.changesetSourceModel = changesetSourceModel; 145 this.changesetReviewModel = changesetReviewModel; 158 this.changesetCommentModel = Objects.requireNonNull(changesetCommentModel, "changesetCommentModel"); 159 this.changesetSourceModel = Objects.requireNonNull(changesetSourceModel, "changesetSourceModel"); 160 this.changesetReviewModel = Objects.requireNonNull(changesetReviewModel, "changesetReviewModel"); 146 161 changesetCommentModel.addChangeListener(new ChangesetCommentChangeListener(hcbUploadComment)); 147 162 changesetSourceModel.addChangeListener(new ChangesetCommentChangeListener(hcbUploadSource)); … … 167 182 hcbUploadComment.addCurrentItemToHistory(); 168 183 Config.getPref().putList(HISTORY_KEY, hcbUploadComment.getHistory()); 169 Config.getPref().put Int(HISTORY_LAST_USED_KEY, (int) (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));184 Config.getPref().putLong(HISTORY_LAST_USED_KEY, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())); 170 185 // store the history of sources 171 186 hcbUploadSource.addCurrentItemToHistory(); … … 197 212 } 198 213 214 /** 215 * Returns the panel that displays a summary of data the user is about to upload. 216 * @return the upload parameter summary panel 217 */ 199 218 public UploadParameterSummaryPanel getUploadParameterSummaryPanel() { 200 219 return pnlUploadParameterSummary; 220 } 221 222 /** 223 * Forces update of comment/source model if matching text field is focused. 224 * @since 14977 225 */ 226 public void forceUpdateActiveField() { 227 updateModelIfFocused(hcbUploadComment, changesetCommentModel); 228 updateModelIfFocused(hcbUploadSource, changesetSourceModel); 229 } 230 231 private static void updateModelIfFocused(HistoryComboBox hcb, ChangesetCommentModel changesetModel) { 232 if (hcb.getEditorComponent().hasFocus()) { 233 changesetModel.setComment(hcb.getText()); 234 } 201 235 } 202 236 -
trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java
r13130 r14977 33 33 34 34 /** 35 * ChangesetManagementPanel allows to configure changeset to be used in the next 36 * upload. 35 * ChangesetManagementPanel allows to configure changeset to be used in the next upload. 37 36 * 38 37 * It is displayed as one of the configuration panels in the {@link UploadDialog}. 39 38 * 40 * ChangesetManagementPanel is a source for {@link java.beans.PropertyChangeEvent}s. Clients can listen 41 * to 39 * ChangesetManagementPanel is a source for {@link java.beans.PropertyChangeEvent}s. Clients can listen to 42 40 * <ul> 43 41 * <li>{@link #SELECTED_CHANGESET_PROP} - the new value in the property change event is 44 42 * the changeset selected by the user. The value is null if the user didn't select a 45 * a changeset or if he chose dto use a new changeset.</li>43 * a changeset or if he chose to use a new changeset.</li> 46 44 * <li> {@link #CLOSE_CHANGESET_AFTER_UPLOAD} - the new value is a boolean value indicating 47 45 * whether the changeset should be closed after the next upload</li> -
trunk/src/org/openstreetmap/josm/gui/io/IUploadDialog.java
r12687 r14977 66 66 */ 67 67 void handleIllegalChunkSize(); 68 69 /** 70 * Forces update of comment/source model if matching text field is active. 71 * @since 14977 72 */ 73 void forceUpdateActiveField(); 68 74 } -
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r13198 r14977 4 4 import java.awt.BorderLayout; 5 5 import java.util.Map; 6 import java.util.Objects; 6 7 import java.util.Optional; 7 8 … … 17 18 import org.openstreetmap.josm.gui.tagging.TagModel; 18 19 import org.openstreetmap.josm.spi.preferences.Config; 19 import org.openstreetmap.josm.tools.CheckParameterUtil;20 20 21 21 /** … … 38 38 * @param changesetSourceModel the changeset source model. Must not be null. 39 39 * @param changesetReviewModel the model for the changeset review. Must not be null. 40 * @throws IllegalArgumentException if {@code changesetCommentModel}is null40 * @throws NullPointerException if a model is null 41 41 * @since 12719 (signature) 42 42 */ 43 43 public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel, 44 44 ChangesetReviewModel changesetReviewModel) { 45 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 46 CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel"); 47 CheckParameterUtil.ensureParameterNotNull(changesetReviewModel, "changesetReviewModel"); 48 this.changesetCommentModel = changesetCommentModel; 49 this.changesetSourceModel = changesetSourceModel; 50 this.changesetReviewModel = changesetReviewModel; 45 this.changesetCommentModel = Objects.requireNonNull(changesetCommentModel, "changesetCommentModel"); 46 this.changesetSourceModel = Objects.requireNonNull(changesetSourceModel, "changesetSourceModel"); 47 this.changesetReviewModel = Objects.requireNonNull(changesetReviewModel, "changesetReviewModel"); 51 48 changesetCommentModel.addChangeListener(new ChangesetCommentChangeListener("comment", "hashtags")); 52 49 changesetSourceModel.addChangeListener(new ChangesetCommentChangeListener("source")); -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r14355 r14977 283 283 */ 284 284 public void setChangesetTags(DataSet dataSet) { 285 setChangesetTags(dataSet, false); 286 } 287 288 /** 289 * Sets the tags for this upload based on (later items overwrite earlier ones): 290 * <ul> 291 * <li>previous "source" and "comment" input</li> 292 * <li>the tags set in the dataset (see {@link DataSet#getChangeSetTags()})</li> 293 * <li>the tags from the selected open changeset</li> 294 * <li>the JOSM user agent (see {@link Version#getAgentString(boolean)})</li> 295 * </ul> 296 * 297 * @param dataSet to obtain the tags set in the dataset 298 * @param keepSourceComment if {@code true}, keep upload {@code source} and {@code comment} current values from models 299 */ 300 private void setChangesetTags(DataSet dataSet, boolean keepSourceComment) { 285 301 final Map<String, String> tags = new HashMap<>(); 286 302 287 303 // obtain from previous input 288 tags.put("source", getLastChangesetSourceFromHistory()); 289 tags.put("comment", getLastChangesetCommentFromHistory()); 304 if (!keepSourceComment) { 305 tags.put("source", getLastChangesetSourceFromHistory()); 306 tags.put("comment", getLastChangesetCommentFromHistory()); 307 } 290 308 291 309 // obtain from dataset … … 318 336 } 319 337 338 // ignore source/comment to keep current values from models ? 339 if (keepSourceComment) { 340 tags.put("source", changesetSourceModel.getComment()); 341 tags.put("comment", changesetCommentModel.getComment()); 342 } 343 320 344 pnlTagSettings.initFromTags(tags); 321 345 pnlTagSettings.tableChanged(null); 346 pnlBasicUploadSettings.discardAllUndoableEdits(); 322 347 } 323 348 … … 519 544 @Override 520 545 public void actionPerformed(ActionEvent e) { 546 // force update of model in case dialog is closed before focus lost event, see #17452 547 dialog.forceUpdateActiveField(); 548 521 549 if (isUploadCommentTooShort(dialog.getUploadComment()) && warnUploadComment()) { 522 550 // abort for missing comment … … 620 648 if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) { 621 649 Changeset cs = (Changeset) evt.getNewValue(); 622 setChangesetTags(dataSet );650 setChangesetTags(dataSet, cs == null); // keep comment/source of first tab for new changesets 623 651 if (cs == null) { 624 652 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset")); … … 634 662 @Override 635 663 public void preferenceChanged(PreferenceChangeEvent e) { 636 if (e.getKey() == null || !"osm-server.url".equals(e.getKey())) 637 return; 638 final Setting<?> newValue = e.getNewValue(); 664 if (e.getKey() != null 665 && e.getSource() != getClass() 666 && e.getSource() != BasicUploadSettingsPanel.class) { 667 switch (e.getKey()) { 668 case "osm-server.url": 669 osmServerUrlChanged(e.getNewValue()); 670 break; 671 case BasicUploadSettingsPanel.HISTORY_KEY: 672 case BasicUploadSettingsPanel.SOURCE_HISTORY_KEY: 673 pnlBasicUploadSettings.refreshHistoryComboBoxes(); 674 break; 675 default: 676 return; 677 } 678 } 679 } 680 681 private void osmServerUrlChanged(Setting<?> newValue) { 639 682 final String url; 640 683 if (newValue == null || newValue.getValue() == null) { … … 648 691 private static String getLastChangesetTagFromHistory(String historyKey, List<String> def) { 649 692 Collection<String> history = Config.getPref().getList(historyKey, def); 650 int age = (int) (System.currentTimeMillis() / 1000 - Config.getPref().getInt(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0));651 if ( history != null && age < Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toMillis(4))693 long age = System.currentTimeMillis() / 1000 - Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_LAST_USED_KEY, 0); 694 if (age < Config.getPref().getLong(BasicUploadSettingsPanel.HISTORY_MAX_AGE_KEY, TimeUnit.HOURS.toSeconds(4)) 652 695 && !history.isEmpty()) { 653 696 return history.iterator().next(); 654 } else { 655 return null; 656 } 697 } 698 return null; 657 699 } 658 700 … … 661 703 * @return the last changeset comment from history 662 704 */ 663 public String getLastChangesetCommentFromHistory() {705 public static String getLastChangesetCommentFromHistory() { 664 706 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.HISTORY_KEY, new ArrayList<String>()); 665 707 } … … 669 711 * @return the last changeset source from history 670 712 */ 671 public String getLastChangesetSourceFromHistory() {713 public static String getLastChangesetSourceFromHistory() { 672 714 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.SOURCE_HISTORY_KEY, BasicUploadSettingsPanel.getDefaultSources()); 673 715 } … … 695 737 } 696 738 739 @Override 740 public void forceUpdateActiveField() { 741 if (tpConfigPanels.getSelectedComponent() == pnlBasicUploadSettings) { 742 pnlBasicUploadSettings.forceUpdateActiveField(); 743 } 744 } 745 697 746 /** 698 747 * Clean dialog state and release resources. -
trunk/src/org/openstreetmap/josm/gui/oauth/AccessTokenInfoPanel.java
r12686 r14977 22 22 public class AccessTokenInfoPanel extends JPanel { 23 23 24 private final JosmTextField tfAccessTokenKey = new JosmTextField( );25 private final JosmTextField tfAccessTokenSecret = new JosmTextField( );24 private final JosmTextField tfAccessTokenKey = new JosmTextField(null, null, 0, false); 25 private final JosmTextField tfAccessTokenSecret = new JosmTextField(null, null, 0, false); 26 26 private final JCheckBox cbSaveAccessTokenInPreferences = new JCheckBox(tr("Save Access Token in preferences")); 27 27 -
trunk/src/org/openstreetmap/josm/gui/oauth/SemiAutomaticAuthorizationUI.java
r12686 r14977 211 211 private class RetrieveAccessTokenPanel extends JPanel { 212 212 213 private final JosmTextField tfAuthoriseUrl = new JosmTextField( );213 private final JosmTextField tfAuthoriseUrl = new JosmTextField(null, null, 0, false); 214 214 215 215 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java
r12931 r14977 212 212 */ 213 213 private class AlreadyAuthorisedPanel extends JPanel { 214 private final JosmTextField tfAccessTokenKey = new JosmTextField( );215 private final JosmTextField tfAccessTokenSecret = new JosmTextField( );214 private final JosmTextField tfAccessTokenKey = new JosmTextField(null, null, 0, false); 215 private final JosmTextField tfAccessTokenSecret = new JosmTextField(null, null, 0, false); 216 216 217 217 /** -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java
r14302 r14977 34 34 */ 35 35 public class JosmComboBox<E> extends JComboBox<E> { 36 37 private final ContextMenuHandler handler = new ContextMenuHandler(); 36 38 37 39 /** … … 165 167 166 168 protected final void init(E prototype) { 169 init(prototype, true); 170 } 171 172 protected final void init(E prototype, boolean registerPropertyChangeListener) { 167 173 if (prototype != null) { 168 174 setPrototypeDisplayValue(prototype); … … 186 192 } 187 193 // Handle text contextual menus for editable comboboxes 188 ContextMenuHandler handler = new ContextMenuHandler(); 189 addPropertyChangeListener("editable", handler); 190 addPropertyChangeListener("editor", handler); 194 if (registerPropertyChangeListener) { 195 addPropertyChangeListener("editable", handler); 196 addPropertyChangeListener("editor", handler); 197 } 191 198 } 192 199 … … 232 239 } 233 240 241 private void discardAllUndoableEdits() { 242 if (launcher != null) { 243 launcher.discardAllUndoableEdits(); 244 } 245 } 246 234 247 @Override 235 248 public void mousePressed(MouseEvent e) { … … 250 263 251 264 /** 252 * Reinitializes this {@link JosmComboBox} to the specified values. This may needed if a custom renderer is used.265 * Reinitializes this {@link JosmComboBox} to the specified values. This may be needed if a custom renderer is used. 253 266 * @param values The values displayed in the combo box. 254 267 * @since 5558 255 268 */ 256 269 public final void reinitialize(Collection<E> values) { 257 init(findPrototypeDisplayValue(values)); 270 init(findPrototypeDisplayValue(values), false); 271 discardAllUndoableEdits(); 272 } 273 274 /** 275 * Empties the internal undo manager, if any. 276 * @since 14977 277 */ 278 public final void discardAllUndoableEdits() { 279 handler.discardAllUndoableEdits(); 258 280 } 259 281 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmImageView.java
r13649 r14977 17 17 import org.openstreetmap.josm.tools.ImageProvider; 18 18 import org.openstreetmap.josm.tools.Logging; 19 import org.openstreetmap.josm.tools. Utils;19 import org.openstreetmap.josm.tools.ReflectionUtils; 20 20 21 21 /** … … 48 48 widthField = getDeclaredField("width"); 49 49 heightField = getDeclaredField("height"); 50 Utils.setObjectsAccessible(imageField, stateField, widthField, heightField);50 ReflectionUtils.setObjectsAccessible(imageField, stateField, widthField, heightField); 51 51 } 52 52 … … 108 108 // And update the size params 109 109 Method updateImageSize = ImageView.class.getDeclaredMethod("updateImageSize"); 110 Utils.setObjectsAccessible(updateImageSize);110 ReflectionUtils.setObjectsAccessible(updateImageSize); 111 111 updateImageSize.invoke(this); 112 112 } finally { … … 136 136 } else { 137 137 Method loadImage = ImageView.class.getDeclaredMethod("loadImage"); 138 Utils.setObjectsAccessible(loadImage);138 ReflectionUtils.setObjectsAccessible(loadImage); 139 139 loadImage.invoke(this); 140 140 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java
r14463 r14977 146 146 public final void setHint(String hint) { 147 147 this.hint = hint; 148 } 149 150 /** 151 * Empties the internal undo manager. 152 * @since 14977 153 */ 154 public final void discardAllUndoableEdits() { 155 launcher.discardAllUndoableEdits(); 148 156 } 149 157 -
trunk/src/org/openstreetmap/josm/gui/widgets/PopupMenuLauncher.java
r14676 r14977 155 155 return menu; 156 156 } 157 158 /** 159 * Empties the internal undo manager, if any. 160 * @since 14977 161 */ 162 public void discardAllUndoableEdits() { 163 if (menu instanceof TextContextualPopupMenu) { 164 ((TextContextualPopupMenu) menu).discardAllUndoableEdits(); 165 } 166 } 157 167 } -
trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
r14138 r14977 61 61 protected final transient UndoableEditListener undoEditListener = e -> { 62 62 undo.addEdit(e.getEdit()); 63 undoAction.updateUndoState(); 64 redoAction.updateRedoState(); 63 updateUndoRedoState(); 65 64 }; 66 65 … … 77 76 protected TextContextualPopupMenu() { 78 77 // Restricts visibility 78 } 79 80 private void updateUndoRedoState() { 81 undoAction.updateUndoState(); 82 redoAction.updateRedoState(); 79 83 } 80 84 … … 90 94 if (component != null && !isAttached()) { 91 95 this.component = component; 92 this.undoRedo = undoRedo;93 96 if (undoRedo && component.isEditable()) { 94 component.getDocument().addUndoableEditListener(undoEditListener); 95 if (!GraphicsEnvironment.isHeadless()) { 96 component.getInputMap().put( 97 KeyStroke.getKeyStroke(KeyEvent.VK_Z, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), undoAction); 98 component.getInputMap().put( 99 KeyStroke.getKeyStroke(KeyEvent.VK_Y, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), redoAction); 100 } 97 enableUndoRedo(); 101 98 } 102 99 addMenuEntries(); … … 104 101 } 105 102 return this; 103 } 104 105 private void enableUndoRedo() { 106 if (!undoRedo) { 107 component.getDocument().addUndoableEditListener(undoEditListener); 108 if (!GraphicsEnvironment.isHeadless()) { 109 component.getInputMap().put( 110 KeyStroke.getKeyStroke(KeyEvent.VK_Z, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), undoAction); 111 component.getInputMap().put( 112 KeyStroke.getKeyStroke(KeyEvent.VK_Y, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx()), redoAction); 113 } 114 undoRedo = true; 115 } 116 } 117 118 private void disableUndoRedo() { 119 if (undoRedo) { 120 if (!GraphicsEnvironment.isHeadless()) { 121 component.getInputMap().remove( 122 KeyStroke.getKeyStroke(KeyEvent.VK_Z, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx())); 123 component.getInputMap().remove( 124 KeyStroke.getKeyStroke(KeyEvent.VK_Y, PlatformManager.getPlatform().getMenuShortcutKeyMaskEx())); 125 } 126 component.getDocument().removeUndoableEditListener(undoEditListener); 127 undoRedo = false; 128 } 106 129 } 107 130 … … 134 157 removeAll(); 135 158 if (undoRedo) { 136 component.getDocument().removeUndoableEditListener(undoEditListener);159 disableUndoRedo(); 137 160 } 138 161 component = null; … … 166 189 component.removeMouseListener(launcher); 167 190 } 191 } 192 193 /** 194 * Empties the internal undo manager. 195 * @since 14977 196 */ 197 public void discardAllUndoableEdits() { 198 undo.discardAllEdits(); 199 updateUndoRedoState(); 168 200 } 169 201 -
trunk/src/org/openstreetmap/josm/spi/preferences/DefaultPreferenceChangeEvent.java
r12882 r14977 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.spi.preferences; 3 4 import java.util.EventObject; 3 5 4 6 /** … … 6 8 * @since 12881 7 9 */ 8 public class DefaultPreferenceChangeEvent implements PreferenceChangeEvent {9 10 public class DefaultPreferenceChangeEvent extends EventObject implements PreferenceChangeEvent { 11 10 12 private final String key; 11 13 private final Setting<?> oldValue; 12 14 private final Setting<?> newValue; 13 15 14 public DefaultPreferenceChangeEvent(String key, Setting<?> oldValue, Setting<?> newValue) { 16 /** 17 * Constructs a new {@code DefaultPreferenceChangeEvent}. 18 * @param source the class source of this event 19 * @param key preference key 20 * @param oldValue preference old value 21 * @param newValue preference new value 22 * @since 14977 23 */ 24 public DefaultPreferenceChangeEvent(Class<?> source, String key, Setting<?> oldValue, Setting<?> newValue) { 25 super(source); 15 26 this.key = key; 16 27 this.oldValue = oldValue; 17 28 this.newValue = newValue; 29 } 30 31 @Override 32 public Class<?> getSource() { 33 return (Class<?>) super.getSource(); 18 34 } 19 35 … … 32 48 return newValue; 33 49 } 34 50 35 51 } -
trunk/src/org/openstreetmap/josm/spi/preferences/PreferenceChangeEvent.java
r12882 r14977 7 7 */ 8 8 public interface PreferenceChangeEvent { 9 10 /** 11 * Returns the class source of this event. 12 * @return The class source of this event 13 * @since 14977 14 */ 15 Class<?> getSource(); 9 16 10 17 /** … … 25 32 */ 26 33 Setting<?> getNewValue(); 27 28 34 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r14535 r14977 30 30 import java.nio.file.attribute.BasicFileAttributes; 31 31 import java.nio.file.attribute.FileTime; 32 import java.security.AccessController;33 32 import java.security.MessageDigest; 34 33 import java.security.NoSuchAlgorithmException; 35 import java.security.PrivilegedAction;36 34 import java.text.Bidi; 37 35 import java.text.DateFormat; … … 1559 1557 * @param objects objects 1560 1558 * @see AccessibleObject#setAccessible 1559 * @deprecated Use {@link ReflectionUtils#setObjectsAccessible(AccessibleObject...)} 1561 1560 * @since 10223 1562 1561 */ 1562 @Deprecated 1563 1563 public static void setObjectsAccessible(final AccessibleObject... objects) { 1564 if (objects != null && objects.length > 0) { 1565 AccessController.doPrivileged((PrivilegedAction<Object>) () -> { 1566 for (AccessibleObject o : objects) { 1567 if (o != null) { 1568 o.setAccessible(true); 1569 } 1570 } 1571 return null; 1572 }); 1573 } 1564 ReflectionUtils.setObjectsAccessible(objects); 1574 1565 } 1575 1566 -
trunk/src/org/openstreetmap/josm/tools/WinRegistry.java
r13672 r14977 63 63 regQueryInfoKey = getDeclaredMethod("WindowsRegQueryInfoKey1", int.class); 64 64 regEnumKeyEx = getDeclaredMethod("WindowsRegEnumKeyEx", int.class, int.class, int.class); 65 Utils.setObjectsAccessible(regOpenKey, regCloseKey, regQueryValueEx, regEnumValue, regQueryInfoKey, regEnumKeyEx);65 ReflectionUtils.setObjectsAccessible(regOpenKey, regCloseKey, regQueryValueEx, regEnumValue, regQueryInfoKey, regEnumKeyEx); 66 66 } 67 67
Note:
See TracChangeset
for help on using the changeset viewer.