Changeset 11055 in josm
- Timestamp:
- 2016-09-27T00:28:57+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java
r10763 r11055 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.event.ActionEvent; 9 import java.awt.event.MouseWheelEvent; 9 10 import java.util.ArrayList; 10 11 import java.util.Collection; … … 40 41 public final class LayerVisibilityAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 41 42 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; 42 47 private static final double MAX_SHARPNESS_FACTOR = 2; 43 48 private static final double MAX_COLORFUL_FACTOR = 2; … … 172 177 173 178 addChangeListener(e -> onStateChanged()); 179 addMouseWheelListener(this::mouseWheelMoved); 174 180 } 175 181 … … 186 192 } 187 193 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 188 206 protected void applyValueToLayer(T layer) { 189 207 } … … 204 222 protected int convertFromRealValue(double value) { 205 223 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()); 213 225 } 214 226 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10972 r11055 1502 1502 } 1503 1503 } 1504 1505 /** 1506 * Clamp a integer value to the given range 1507 * @param val The value 1508 * @param min minimum value 1509 * @param max maximum value 1510 * @return the value 1511 * @since 11053 1512 */ 1513 public static int clamp(int val, int min, int max) { 1514 if (val < min) { 1515 return min; 1516 } else if (val > max) { 1517 return max; 1518 } else { 1519 return val; 1520 } 1521 } 1504 1522 }
Note:
See TracChangeset
for help on using the changeset viewer.