Changeset 11206 in josm for trunk


Ignore:
Timestamp:
2016-11-01T11:17:36+01:00 (8 years ago)
Author:
michael2402
Message:

Fix #13703: Layer visibility popup: Improve mouse wheel hit boxes and make visibility slider more intuitive.

File:
1 edited

Legend:

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

    r11055 r11206  
    6161        this.model = model;
    6262        popup = new JPopupMenu();
     63        // prevent popup close on mouse wheel move
     64        popup.addMouseWheelListener(MouseWheelEvent::consume);
    6365
    6466        // just to add a border
     
    8284
    8385    private void addSlider(JPanel content, FilterSlider<?> slider) {
    84         content.add(new JLabel(slider.getIcon()), GBC.std().span(1, 2).insets(0, 0, 5, 0));
    85         content.add(new JLabel(slider.getLabel()), GBC.eol());
    86         content.add(slider, GBC.eop());
     86        // wrap to a common content pane to allow for mouse wheel listener on label.
     87        JPanel container = new JPanel(new GridBagLayout());
     88        container.add(new JLabel(slider.getIcon()), GBC.std().span(1, 2).insets(0, 0, 5, 0));
     89        container.add(new JLabel(slider.getLabel()), GBC.eol());
     90        container.add(slider, GBC.eol());
     91        content.add(container, GBC.eop());
     92
     93        container.addMouseWheelListener(slider::mouseWheelMoved);
    8794        sliders.add(slider);
    8895    }
     
    177184
    178185            addChangeListener(e -> onStateChanged());
    179             addMouseWheelListener(this::mouseWheelMoved);
    180186        }
    181187
     
    193199
    194200        protected void mouseWheelMoved(MouseWheelEvent e) {
     201            e.consume();
     202            if (!isEnabled()) {
     203                // ignore mouse wheel in disabled state.
     204                return;
     205            }
    195206            double rotation = e.getPreciseWheelRotation();
    196207            double destinationValue = getValue() + rotation * SLIDER_WHEEL_INCREMENT;
     
    201212            }
    202213            setValue(Utils.clamp((int) destinationValue, getMinimum(), getMaximum()));
    203             e.consume();
    204214        }
    205215
     
    271281
    272282        @Override
     283        protected void mouseWheelMoved(MouseWheelEvent e) {
     284            if (!isEnabled() && !filterLayers(model.getSelectedLayers()).isEmpty() && e.getPreciseWheelRotation() > 0) {
     285                // make layer visible and set the value.
     286                // this allows users to use the mouse wheel to make the layer visible if it was hidden previously.
     287                e.consume();
     288                setVisibleFlag(true);
     289                setRealValue(0.05);
     290            } else {
     291                super.mouseWheelMoved(e);
     292            }
     293        }
     294
     295        @Override
    273296        protected void applyValueToLayer(Layer layer) {
    274297            layer.setOpacity(getRealValue());
Note: See TracChangeset for help on using the changeset viewer.