Changeset 18018 in josm


Ignore:
Timestamp:
2021-07-14T18:30:55+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21104 - see #20659 - Image viewer: fix tooltips and icon size, hide layer-specific visibility checkbox

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java

    r17760 r18018  
    2020import java.util.Hashtable;
    2121import java.util.List;
     22import java.util.Objects;
    2223import java.util.function.Supplier;
    2324import java.util.stream.Collectors;
     
    4344import org.openstreetmap.josm.gui.dialogs.IEnabledStateUpdating;
    4445import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
    45 import org.openstreetmap.josm.gui.layer.GpxLayer;
    4646import org.openstreetmap.josm.gui.layer.ImageryLayer;
    4747import org.openstreetmap.josm.gui.layer.Layer;
     
    5656 *
    5757 * @author Michael Zangl
     58 * @since 10144
    5859 */
    5960public final class LayerVisibilityAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
     
    7778     * The real content, just to add a border
    7879     */
    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<>();
    8282
    8383    /**
     
    107107
    108108        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."));
    110110
    111111        addContentEntry(new VisibilityCheckbox());
    112112
    113         addContentEntry(opacitySlider);
     113        addContentEntry(new OpacitySlider());
    114114        addContentEntry(new ColorfulnessSlider());
    115115        addContentEntry(new GammaFilterSlider());
     
    118118    }
    119119
    120     private void addContentEntry(LayerVisibilityMenuEntry slider) {
     120    private void addContentEntry(VisibilityMenuEntry slider) {
    121121        content.add(slider.getPanel(), GBC.eop().fill(GBC.HORIZONTAL));
    122122        sliders.add(slider);
     
    148148
    149149    void updateValues() {
    150         for (LayerVisibilityMenuEntry slider : sliders) {
    151             slider.updateLayers();
     150        for (VisibilityMenuEntry slider : sliders) {
     151            slider.updateValue();
    152152        }
    153153    }
     
    180180     * @author Michael Zangl
    181181     */
    182     private interface LayerVisibilityMenuEntry {
    183 
    184         /**
    185          * Update the displayed value depending on the current layers
    186          */
    187         void updateLayers();
     182    protected interface VisibilityMenuEntry {
     183
     184        /**
     185         * Update the displayed value
     186         */
     187        void updateValue();
    188188
    189189        /**
     
    194194    }
    195195
    196     private class VisibilityCheckbox extends JCheckBox implements LayerVisibilityMenuEntry {
     196    private class VisibilityCheckbox extends JCheckBox implements VisibilityMenuEntry {
    197197
    198198        VisibilityCheckbox() {
     
    207207
    208208        @Override
    209         public void updateLayers() {
     209        public void updateValue() {
    210210            Collection<Layer> layers = layerSupplier.get();
    211211            boolean allVisible = layers.stream().allMatch(Layer::isVisible);
    212212            boolean allHidden = layers.stream().noneMatch(Layer::isVisible);
    213213
    214             setEnabled(!layers.isEmpty());
     214            setVisible(!layers.isEmpty());
    215215            // TODO: Indicate tristate.
    216216            setSelected(allVisible && !allHidden);
     
    227227     * @author Michael Zangl
    228228     */
    229     private abstract static class AbstractFilterSlider extends JPanel implements LayerVisibilityMenuEntry {
     229    private abstract static class AbstractFilterSlider extends JPanel implements VisibilityMenuEntry {
    230230        private final double minValue;
    231231        private final double maxValue;
     
    264264                }
    265265            });
    266 
    267             //final NumberFormat format = DecimalFormat.getInstance();
    268             //setLabels(format.format(minValue), format.format((minValue + maxValue) / 2), format.format(maxValue));
    269266        }
    270267
     
    369366
    370367        @Override
    371         public void updateLayers() {
     368        public void updateValue() {
    372369            Collection<Layer> usedLayers = layerSupplier.get();
    373370            setVisible(!usedLayers.isEmpty());
     
    405402
    406403    /**
    407      * This slider allows you to change the gamma value of a layer.
     404     * This slider allows you to change the gamma value.
    408405     *
    409406     * @author Michael Zangl
     
    418415            super(-1, 1, DEFAULT_GAMMA_VALUE);
    419416            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 updateLayers() {
     417            slider.setToolTipText(tr("Adjust gamma value.") + " " + tr("Double click to reset."));
     418        }
     419
     420        @Override
     421        public void updateValue() {
    425422            Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get();
    426423            setVisible(!settings.isEmpty());
     
    471468
    472469    /**
    473      * This slider allows you to change the sharpness of a layer.
     470     * This slider allows you to change the sharpness.
    474471     *
    475472     * @author Michael Zangl
     
    484481            super(0, MAX_SHARPNESS_FACTOR, DEFAULT_SHARPNESS_FACTOR);
    485482            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 updateLayers() {
     483            slider.setToolTipText(tr("Adjust sharpness/blur value.") + " " + tr("Double click to reset."));
     484        }
     485
     486        @Override
     487        public void updateValue() {
    491488            Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get();
    492489            setVisible(!settings.isEmpty());
     
    515512
    516513    /**
    517      * This slider allows you to change the colorfulness of a layer.
     514     * This slider allows you to change the colorfulness.
    518515     *
    519516     * @author Michael Zangl
     
    528525            super(0, MAX_COLORFUL_FACTOR, DEFAULT_COLORFUL_FACTOR);
    529526            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 updateLayers() {
     527            slider.setToolTipText(tr("Adjust colorfulness.") + " " + tr("Double click to reset."));
     528        }
     529
     530        @Override
     531        public void updateValue() {
    535532            Collection<ImageryFilterSettings> settings = filterSettingsSupplier.get();
    536533            setVisible(!settings.isEmpty());
     
    559556
    560557    /**
    561      * Allows to select the color for the GPX layer
     558     * Allows to select the color of a layer
    562559     * @author Michael Zangl
    563560     */
    564     private class ColorSelector extends JPanel implements LayerVisibilityMenuEntry {
     561    private class ColorSelector extends JPanel implements VisibilityMenuEntry {
    565562
    566563        private final Border NORMAL_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2);
     
    600597                    Collection<Layer> layers = layerSupplier.get();
    601598                    for (Layer l : layers) {
    602                         if (l instanceof GpxLayer) {
    603                             l.setColor(color);
    604                         }
     599                        l.setColor(color);
    605600                    }
    606601                    highlightColor(color);
     
    618613        private List<Color> getColors() {
    619614            return layerSupplier.get().stream()
    620                     .filter(layer -> layer instanceof GpxLayer)
    621615                    .map(Layer::getColor)
     616                    .filter(Objects::nonNull)
    622617                    .distinct()
    623618                    .collect(Collectors.toList());
     
    625620
    626621        @Override
    627         public void updateLayers() {
     622        public void updateValue() {
    628623            List<Color> colors = getColors();
    629624            if (colors.size() == 1) {
     
    634629                highlightColor(null);
    635630            } else {
    636                 // no GPX layer
    637631                setVisible(false);
    638632            }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r17983 r18018  
    4444 *
    4545 * Offers basic mouse interaction (zoom, drag) and on-screen text.
     46 * @since 2566
    4647 */
    4748public class ImageDisplay extends JComponent implements Destroyable, PreferenceChangedListener, FilterChangeListener {
     
    103104    private static final BooleanProperty ERROR_MESSAGE_BACKGROUND = new BooleanProperty("geoimage.message.error.background", false);
    104105
    105     private updateImageThread updateImageThreadInstance;
    106 
    107     private class updateImageThread extends Thread {
     106    private UpdateImageThread updateImageThreadInstance;
     107
     108    private class UpdateImageThread extends Thread {
    108109        private boolean restart;
    109110
     
    121122            if (!isAlive()) {
    122123                restart = false;
    123                 updateImageThreadInstance = new updateImageThread();
     124                updateImageThreadInstance = new UpdateImageThread();
    124125                updateImageThreadInstance.start();
    125126            }
     
    597598
    598599    /**
    599      * Constructs a new {@code ImageDisplay}.
     600     * Constructs a new {@code ImageDisplay} with no image processor.
    600601     */
    601602    public ImageDisplay() {
     
    603604    }
    604605
     606    /**
     607     * Constructs a new {@code ImageDisplay} with a given image processor.
     608     * @param imageProcessor image processor
     609     * @since 17740
     610     */
    605611    public ImageDisplay(ImageProcessor imageProcessor) {
    606612        addMouseListener(imgMouseListener);
     
    679685            updateImageThreadInstance.restart();
    680686        } else {
    681             updateImageThreadInstance = new updateImageThread();
     687            updateImageThreadInstance = new UpdateImageThread();
    682688            updateImageThreadInstance.start();
    683689        }
     
    732738                g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
    733739            }
    734             if (errorLoading) {
     740            if (errorLoading && entry != null) {
    735741                String loadingStr = tr("Error on file {0}", entry.getDisplayName());
    736742                Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(loadingStr, g);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18012 r18018  
    2020import java.util.Optional;
    2121
     22import javax.swing.AbstractAction;
    2223import javax.swing.Box;
    2324import javax.swing.JButton;
     
    116117    }
    117118
    118     private static JButton createNavigationButton(JosmAction action, Dimension buttonDim) {
     119    private static JButton createButton(AbstractAction action, Dimension buttonDim) {
    119120        JButton btn = new JButton(action);
    120121        btn.setPreferredSize(buttonDim);
     122        return btn;
     123    }
     124
     125    private static JButton createNavigationButton(AbstractAction action, Dimension buttonDim) {
     126        JButton btn = createButton(action, buttonDim);
    121127        btn.setEnabled(false);
    122128        return btn;
     
    133139        btnPrevious = createNavigationButton(imagePreviousAction, buttonDim);
    134140
    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);
    143144
    144145        btnNext = createNavigationButton(imageNextAction, buttonDim);
     
    151152        btnZoomBestFit.setPreferredSize(buttonDim);
    152153
    153         btnCollapse = new JButton(imageCollapseAction);
    154         btnCollapse.setPreferredSize(new Dimension(20, 20));
     154        btnCollapse = createButton(imageCollapseAction, new Dimension(20, 20));
    155155        btnCollapse.setAlignmentY(Component.TOP_ALIGNMENT);
    156156
     
    169169        buttons.add(btnCopyPath);
    170170        buttons.add(Box.createRigidArea(new Dimension(7, 0)));
    171         buttons.add(new JButton(visibilityAction));
     171        buttons.add(createButton(visibilityAction, buttonDim));
    172172
    173173        JPanel bottomPane = new JPanel(new GridBagLayout());
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ImageryFilterSettings.java

    r17740 r18018  
    1010
    1111/**
    12  * This class holds the filter settings for an imagery layer.
     12 * This class holds the filter settings for an imagery.
    1313 * @author Michael Zangl
    1414 * @since 10547
     
    4747
    4848    /**
    49      * Sets the sharpen level for the layer.
     49     * Sets the sharpen level for the imagery.
    5050     * <code>1</code> means no change in sharpness.
    5151     * Values in range 0..1 blur the image.
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java

    r17275 r18018  
    66import static org.junit.jupiter.api.Assertions.assertTrue;
    77
     8import org.junit.jupiter.api.Test;
    89import org.junit.jupiter.api.extension.RegisterExtension;
    9 import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.MainApplication;
    1111import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    1212import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
     13import org.openstreetmap.josm.gui.dialogs.layer.LayerVisibilityAction.OpacitySlider;
    1314import org.openstreetmap.josm.gui.layer.TMSLayer;
    1415import org.openstreetmap.josm.gui.layer.TMSLayerTest;
     
    5253        // now check values
    5354        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();
    5657
    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);
    5862        action.updateValues();
    5963
    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());
    6266
    6367        action.setVisibleFlag(false);
     
    7074
    7175        // 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);
    7478        assertEquals(0, layer.getOpacity(), 1e-15);
    7579        layer.setOpacity(.1); // to make layer.isVisible work
     
    7781        layer.setOpacity(0);
    7882
    79         action.opacitySlider.slider.setValueIsAdjusting(false);
    80         action.opacitySlider.setRealValue(0);
     83        opacitySlider.slider.setValueIsAdjusting(false);
     84        opacitySlider.setRealValue(0);
    8185        assertEquals(0, layer.getOpacity(), 1e-15);
    8286        layer.setOpacity(.1); // to make layer.isVisible work
     
    8892        action.setVisibleFlag(true);
    8993        action.updateValues();
    90         assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
     94        assertEquals(1.0, opacitySlider.getRealValue(), 1e-15);
    9195        assertEquals(1.0, layer.getOpacity(), 1e-15);
    9296    }
Note: See TracChangeset for help on using the changeset viewer.