- Timestamp:
- 2021-07-14T18:30:55+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java
r17760 r18018 20 20 import java.util.Hashtable; 21 21 import java.util.List; 22 import java.util.Objects; 22 23 import java.util.function.Supplier; 23 24 import java.util.stream.Collectors; … … 43 44 import org.openstreetmap.josm.gui.dialogs.IEnabledStateUpdating; 44 45 import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel; 45 import org.openstreetmap.josm.gui.layer.GpxLayer;46 46 import org.openstreetmap.josm.gui.layer.ImageryLayer; 47 47 import org.openstreetmap.josm.gui.layer.Layer; … … 56 56 * 57 57 * @author Michael Zangl 58 * @since 10144 58 59 */ 59 60 public final class LayerVisibilityAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { … … 77 78 * The real content, just to add a border 78 79 */ 79 private final JPanel content = new JPanel(); 80 final OpacitySlider opacitySlider = new OpacitySlider(); 81 private final ArrayList<LayerVisibilityMenuEntry> sliders = new ArrayList<>(); 80 protected final JPanel content = new JPanel(); 81 protected final List<VisibilityMenuEntry> sliders = new ArrayList<>(); 82 82 83 83 /** … … 107 107 108 108 new ImageProvider(DIALOGS_LAYERLIST, "visibility").getResource().attachImageIcon(this, true); 109 putValue(SHORT_DESCRIPTION, tr("Change visibility of the selected layer."));109 putValue(SHORT_DESCRIPTION, tr("Change visibility.")); 110 110 111 111 addContentEntry(new VisibilityCheckbox()); 112 112 113 addContentEntry( opacitySlider);113 addContentEntry(new OpacitySlider()); 114 114 addContentEntry(new ColorfulnessSlider()); 115 115 addContentEntry(new GammaFilterSlider()); … … 118 118 } 119 119 120 private void addContentEntry( LayerVisibilityMenuEntry slider) {120 private void addContentEntry(VisibilityMenuEntry slider) { 121 121 content.add(slider.getPanel(), GBC.eop().fill(GBC.HORIZONTAL)); 122 122 sliders.add(slider); … … 148 148 149 149 void updateValues() { 150 for ( LayerVisibilityMenuEntry slider : sliders) {151 slider.update Layers();150 for (VisibilityMenuEntry slider : sliders) { 151 slider.updateValue(); 152 152 } 153 153 } … … 180 180 * @author Michael Zangl 181 181 */ 182 pr ivateinterfaceLayerVisibilityMenuEntry {183 184 /** 185 * Update the displayed value depending on the current layers186 */ 187 void update Layers();182 protected interface VisibilityMenuEntry { 183 184 /** 185 * Update the displayed value 186 */ 187 void updateValue(); 188 188 189 189 /** … … 194 194 } 195 195 196 private class VisibilityCheckbox extends JCheckBox implements LayerVisibilityMenuEntry {196 private class VisibilityCheckbox extends JCheckBox implements VisibilityMenuEntry { 197 197 198 198 VisibilityCheckbox() { … … 207 207 208 208 @Override 209 public void update Layers() {209 public void updateValue() { 210 210 Collection<Layer> layers = layerSupplier.get(); 211 211 boolean allVisible = layers.stream().allMatch(Layer::isVisible); 212 212 boolean allHidden = layers.stream().noneMatch(Layer::isVisible); 213 213 214 set Enabled(!layers.isEmpty());214 setVisible(!layers.isEmpty()); 215 215 // TODO: Indicate tristate. 216 216 setSelected(allVisible && !allHidden); … … 227 227 * @author Michael Zangl 228 228 */ 229 private abstract static class AbstractFilterSlider extends JPanel implements LayerVisibilityMenuEntry {229 private abstract static class AbstractFilterSlider extends JPanel implements VisibilityMenuEntry { 230 230 private final double minValue; 231 231 private final double maxValue; … … 264 264 } 265 265 }); 266 267 //final NumberFormat format = DecimalFormat.getInstance();268 //setLabels(format.format(minValue), format.format((minValue + maxValue) / 2), format.format(maxValue));269 266 } 270 267 … … 369 366 370 367 @Override 371 public void update Layers() {368 public void updateValue() { 372 369 Collection<Layer> usedLayers = layerSupplier.get(); 373 370 setVisible(!usedLayers.isEmpty()); … … 405 402 406 403 /** 407 * This slider allows you to change the gamma value of a layer.404 * This slider allows you to change the gamma value. 408 405 * 409 406 * @author Michael Zangl … … 418 415 super(-1, 1, DEFAULT_GAMMA_VALUE); 419 416 setLabels("0", "1", "∞"); 420 slider.setToolTipText(tr("Adjust gamma value of the layer.") + " " + tr("Double click to reset."));421 } 422 423 @Override 424 public void update Layers() {417 slider.setToolTipText(tr("Adjust gamma value.") + " " + tr("Double click to reset.")); 418 } 419 420 @Override 421 public void updateValue() { 425 422 Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get(); 426 423 setVisible(!settings.isEmpty()); … … 471 468 472 469 /** 473 * This slider allows you to change the sharpness of a layer.470 * This slider allows you to change the sharpness. 474 471 * 475 472 * @author Michael Zangl … … 484 481 super(0, MAX_SHARPNESS_FACTOR, DEFAULT_SHARPNESS_FACTOR); 485 482 setLabels(trc("image sharpness", "blurred"), trc("image sharpness", "normal"), trc("image sharpness", "sharp")); 486 slider.setToolTipText(tr("Adjust sharpness/blur value of the layer.") + " " + tr("Double click to reset."));487 } 488 489 @Override 490 public void update Layers() {483 slider.setToolTipText(tr("Adjust sharpness/blur value.") + " " + tr("Double click to reset.")); 484 } 485 486 @Override 487 public void updateValue() { 491 488 Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get(); 492 489 setVisible(!settings.isEmpty()); … … 515 512 516 513 /** 517 * This slider allows you to change the colorfulness of a layer.514 * This slider allows you to change the colorfulness. 518 515 * 519 516 * @author Michael Zangl … … 528 525 super(0, MAX_COLORFUL_FACTOR, DEFAULT_COLORFUL_FACTOR); 529 526 setLabels(trc("image colorfulness", "less"), trc("image colorfulness", "normal"), trc("image colorfulness", "more")); 530 slider.setToolTipText(tr("Adjust colorfulness of the layer.") + " " + tr("Double click to reset."));531 } 532 533 @Override 534 public void update Layers() {527 slider.setToolTipText(tr("Adjust colorfulness.") + " " + tr("Double click to reset.")); 528 } 529 530 @Override 531 public void updateValue() { 535 532 Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get(); 536 533 setVisible(!settings.isEmpty()); … … 559 556 560 557 /** 561 * Allows to select the color for the GPXlayer558 * Allows to select the color of a layer 562 559 * @author Michael Zangl 563 560 */ 564 private class ColorSelector extends JPanel implements LayerVisibilityMenuEntry {561 private class ColorSelector extends JPanel implements VisibilityMenuEntry { 565 562 566 563 private final Border NORMAL_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2); … … 600 597 Collection<Layer> layers = layerSupplier.get(); 601 598 for (Layer l : layers) { 602 if (l instanceof GpxLayer) { 603 l.setColor(color); 604 } 599 l.setColor(color); 605 600 } 606 601 highlightColor(color); … … 618 613 private List<Color> getColors() { 619 614 return layerSupplier.get().stream() 620 .filter(layer -> layer instanceof GpxLayer)621 615 .map(Layer::getColor) 616 .filter(Objects::nonNull) 622 617 .distinct() 623 618 .collect(Collectors.toList()); … … 625 620 626 621 @Override 627 public void update Layers() {622 public void updateValue() { 628 623 List<Color> colors = getColors(); 629 624 if (colors.size() == 1) { … … 634 629 highlightColor(null); 635 630 } else { 636 // no GPX layer637 631 setVisible(false); 638 632 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r17983 r18018 44 44 * 45 45 * Offers basic mouse interaction (zoom, drag) and on-screen text. 46 * @since 2566 46 47 */ 47 48 public class ImageDisplay extends JComponent implements Destroyable, PreferenceChangedListener, FilterChangeListener { … … 103 104 private static final BooleanProperty ERROR_MESSAGE_BACKGROUND = new BooleanProperty("geoimage.message.error.background", false); 104 105 105 private updateImageThread updateImageThreadInstance;106 107 private class updateImageThread extends Thread {106 private UpdateImageThread updateImageThreadInstance; 107 108 private class UpdateImageThread extends Thread { 108 109 private boolean restart; 109 110 … … 121 122 if (!isAlive()) { 122 123 restart = false; 123 updateImageThreadInstance = new updateImageThread();124 updateImageThreadInstance = new UpdateImageThread(); 124 125 updateImageThreadInstance.start(); 125 126 } … … 597 598 598 599 /** 599 * Constructs a new {@code ImageDisplay}. 600 * Constructs a new {@code ImageDisplay} with no image processor. 600 601 */ 601 602 public ImageDisplay() { … … 603 604 } 604 605 606 /** 607 * Constructs a new {@code ImageDisplay} with a given image processor. 608 * @param imageProcessor image processor 609 * @since 17740 610 */ 605 611 public ImageDisplay(ImageProcessor imageProcessor) { 606 612 addMouseListener(imgMouseListener); … … 679 685 updateImageThreadInstance.restart(); 680 686 } else { 681 updateImageThreadInstance = new updateImageThread();687 updateImageThreadInstance = new UpdateImageThread(); 682 688 updateImageThreadInstance.start(); 683 689 } … … 732 738 g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); 733 739 } 734 if (errorLoading) { 740 if (errorLoading && entry != null) { 735 741 String loadingStr = tr("Error on file {0}", entry.getDisplayName()); 736 742 Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(loadingStr, g); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r18012 r18018 20 20 import java.util.Optional; 21 21 22 import javax.swing.AbstractAction; 22 23 import javax.swing.Box; 23 24 import javax.swing.JButton; … … 116 117 } 117 118 118 private static JButton create NavigationButton(JosmAction action, Dimension buttonDim) {119 private static JButton createButton(AbstractAction action, Dimension buttonDim) { 119 120 JButton btn = new JButton(action); 120 121 btn.setPreferredSize(buttonDim); 122 return btn; 123 } 124 125 private static JButton createNavigationButton(AbstractAction action, Dimension buttonDim) { 126 JButton btn = createButton(action, buttonDim); 121 127 btn.setEnabled(false); 122 128 return btn; … … 133 139 btnPrevious = createNavigationButton(imagePreviousAction, buttonDim); 134 140 135 btnDelete = new JButton(imageRemoveAction); 136 btnDelete.setPreferredSize(buttonDim); 137 138 btnDeleteFromDisk = new JButton(imageRemoveFromDiskAction); 139 btnDeleteFromDisk.setPreferredSize(buttonDim); 140 141 btnCopyPath = new JButton(imageCopyPathAction); 142 btnCopyPath.setPreferredSize(buttonDim); 141 btnDelete = createButton(imageRemoveAction, buttonDim); 142 btnDeleteFromDisk = createButton(imageRemoveFromDiskAction, buttonDim); 143 btnCopyPath = createButton(imageCopyPathAction, buttonDim); 143 144 144 145 btnNext = createNavigationButton(imageNextAction, buttonDim); … … 151 152 btnZoomBestFit.setPreferredSize(buttonDim); 152 153 153 btnCollapse = new JButton(imageCollapseAction); 154 btnCollapse.setPreferredSize(new Dimension(20, 20)); 154 btnCollapse = createButton(imageCollapseAction, new Dimension(20, 20)); 155 155 btnCollapse.setAlignmentY(Component.TOP_ALIGNMENT); 156 156 … … 169 169 buttons.add(btnCopyPath); 170 170 buttons.add(Box.createRigidArea(new Dimension(7, 0))); 171 buttons.add( new JButton(visibilityAction));171 buttons.add(createButton(visibilityAction, buttonDim)); 172 172 173 173 JPanel bottomPane = new JPanel(new GridBagLayout()); -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/ImageryFilterSettings.java
r17740 r18018 10 10 11 11 /** 12 * This class holds the filter settings for an imagery layer.12 * This class holds the filter settings for an imagery. 13 13 * @author Michael Zangl 14 14 * @since 10547 … … 47 47 48 48 /** 49 * Sets the sharpen level for the layer.49 * Sets the sharpen level for the imagery. 50 50 * <code>1</code> means no change in sharpness. 51 51 * Values in range 0..1 blur the image. -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java
r17275 r18018 6 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 import org.junit.jupiter.api.Test; 8 9 import org.junit.jupiter.api.extension.RegisterExtension; 9 import org.junit.jupiter.api.Test;10 10 import org.openstreetmap.josm.gui.MainApplication; 11 11 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 12 12 import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel; 13 import org.openstreetmap.josm.gui.dialogs.layer.LayerVisibilityAction.OpacitySlider; 13 14 import org.openstreetmap.josm.gui.layer.TMSLayer; 14 15 import org.openstreetmap.josm.gui.layer.TMSLayerTest; … … 52 53 // now check values 53 54 action.updateValues(); 54 assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);55 assertEquals("OpacitySlider[getRealValue()=1.0]", action.opacitySlider.toString());55 OpacitySlider opacitySlider = action.sliders.stream() 56 .filter(x -> x instanceof OpacitySlider).map(x -> (OpacitySlider) x).findFirst().get(); 56 57 57 action.opacitySlider.setRealValue(.5); 58 assertEquals(1.0, opacitySlider.getRealValue(), 1e-15); 59 assertEquals("OpacitySlider [getRealValue()=1.0]", opacitySlider.toString()); 60 61 opacitySlider.setRealValue(.5); 58 62 action.updateValues(); 59 63 60 assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);61 assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());64 assertEquals(0.5, opacitySlider.getRealValue(), 1e-15); 65 assertEquals("OpacitySlider [getRealValue()=0.5]", opacitySlider.toString()); 62 66 63 67 action.setVisibleFlag(false); … … 70 74 71 75 // layer stays visible during adjust 72 action.opacitySlider.slider.setValueIsAdjusting(true);73 action.opacitySlider.setRealValue(0);76 opacitySlider.slider.setValueIsAdjusting(true); 77 opacitySlider.setRealValue(0); 74 78 assertEquals(0, layer.getOpacity(), 1e-15); 75 79 layer.setOpacity(.1); // to make layer.isVisible work … … 77 81 layer.setOpacity(0); 78 82 79 action.opacitySlider.slider.setValueIsAdjusting(false);80 action.opacitySlider.setRealValue(0);83 opacitySlider.slider.setValueIsAdjusting(false); 84 opacitySlider.setRealValue(0); 81 85 assertEquals(0, layer.getOpacity(), 1e-15); 82 86 layer.setOpacity(.1); // to make layer.isVisible work … … 88 92 action.setVisibleFlag(true); 89 93 action.updateValues(); 90 assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);94 assertEquals(1.0, opacitySlider.getRealValue(), 1e-15); 91 95 assertEquals(1.0, layer.getOpacity(), 1e-15); 92 96 }
Note:
See TracChangeset
for help on using the changeset viewer.