Ignore:
Timestamp:
2016-09-27T00:28:57+02:00 (8 years ago)
Author:
michael2402
Message:

Fix #13703: Allow mouse wheel to change visibility slider value.

File:
1 edited

Legend:

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

    r10763 r11055  
    77import java.awt.GridBagLayout;
    88import java.awt.event.ActionEvent;
     9import java.awt.event.MouseWheelEvent;
    910import java.util.ArrayList;
    1011import java.util.Collection;
     
    4041public final class LayerVisibilityAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
    4142    private static final int SLIDER_STEPS = 100;
     43    /**
     44     * Steps the value is changed by a mouse wheel change (one full click)
     45     */
     46    private static final int SLIDER_WHEEL_INCREMENT = 5;
    4247    private static final double MAX_SHARPNESS_FACTOR = 2;
    4348    private static final double MAX_COLORFUL_FACTOR = 2;
     
    172177
    173178            addChangeListener(e -> onStateChanged());
     179            addMouseWheelListener(this::mouseWheelMoved);
    174180        }
    175181
     
    186192        }
    187193
     194        protected void mouseWheelMoved(MouseWheelEvent e) {
     195            double rotation = e.getPreciseWheelRotation();
     196            double destinationValue = getValue() + rotation * SLIDER_WHEEL_INCREMENT;
     197            if (rotation < 0) {
     198                destinationValue = Math.floor(destinationValue);
     199            } else {
     200                destinationValue = Math.ceil(destinationValue);
     201            }
     202            setValue(Utils.clamp((int) destinationValue, getMinimum(), getMaximum()));
     203            e.consume();
     204        }
     205
    188206        protected void applyValueToLayer(T layer) {
    189207        }
     
    204222        protected int convertFromRealValue(double value) {
    205223            int i = (int) ((value - minValue) / (maxValue - minValue) * SLIDER_STEPS + .5);
    206             if (i < getMinimum()) {
    207                 return getMinimum();
    208             } else if (i > getMaximum()) {
    209                 return getMaximum();
    210             } else {
    211                 return i;
    212             }
     224            return Utils.clamp(i, getMinimum(), getMaximum());
    213225        }
    214226
Note: See TracChangeset for help on using the changeset viewer.