Changeset 18705 in josm
- Timestamp:
- 2023-04-19T19:48:17+02:00 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r18686 r18705 176 176 registerOnLayer(l); 177 177 } 178 // This listener gets called _prior to_ the reorder event. If we do not delay the execution of the 179 // model update, then the image will change instead of remaining the same. 180 this.layers.getModel().addChangeListener(l -> MainApplication.worker.execute(() -> GuiHelper.runInEDT(() -> { 181 Component selected = this.layers.getSelectedComponent(); 182 if (selected instanceof MoveImgDisplayPanel) { 183 ((MoveImgDisplayPanel<?>) selected).fireModelUpdate(); 184 } 185 }))); 178 186 } 179 187 … … 298 306 private void addButtonsForImageLayers() { 299 307 List<MoveImgDisplayPanel<?>> alreadyAdded = this.getImageTabs().collect(Collectors.toList()); 300 // Avoid the setVisible call recursively calling this method and adding duplicates301 alreadyAdded.forEach(m -> m.finishedAddingButtons = false);302 308 List<Layer> availableLayers = MainApplication.getLayerManager().getLayers(); 303 309 List<IGeoImageLayer> geoImageLayers = availableLayers.stream() … … 323 329 int index = layers.indexOfTabComponent(source); 324 330 if (index >= 0) { 325 getImageTabs().forEach(m -> m.finishedAddingButtons = false);326 331 removeImageTab(((MoveImgDisplayPanel<?>) layers.getComponentAt(index)).layer); 327 getImageTabs().forEach(m -> m.finishedAddingButtons = true);328 332 getImageTabs().forEach(m -> m.setVisible(m.isVisible())); 329 333 return; … … 343 347 .collect(Collectors.toList()).forEach(this::removeImageTab); 344 348 345 // This is need to avoid the first button becoming visible, and then recalling this method.346 this.getImageTabs().forEach(m -> m.finishedAddingButtons = true);347 349 // After that, trigger the visibility set code 348 350 this.getImageTabs().forEach(m -> m.setVisible(m.isVisible())); … … 765 767 private final ImageDisplay imgDisplay; 766 768 767 /**768 * The purpose of this field is to avoid having the same tab added to the dialog multiple times. This is only a problem when the dialog769 * has multiple tabs on initialization (like from a session).770 */771 boolean finishedAddingButtons;772 769 MoveImgDisplayPanel(ImageDisplay imgDisplay, T layer) { 773 770 super(new BorderLayout()); … … 776 773 } 777 774 778 @Override 779 public void setVisible(boolean visible) { 780 super.setVisible(visible); 775 /** 776 * Call when the selection model updates 777 */ 778 void fireModelUpdate() { 781 779 JTabbedPane layers = ImageViewerDialog.getInstance().layers; 782 780 int index = layers.indexOfComponent(this); 783 if ( visible && this.finishedAddingButtons) {781 if (this == layers.getSelectedComponent()) { 784 782 if (!this.layer.getSelection().isEmpty() && !this.layer.getSelection().contains(ImageViewerDialog.getCurrentImage())) { 785 783 ImageViewerDialog.getInstance().displayImages(this.layer.getSelection());
Note:
See TracChangeset
for help on using the changeset viewer.