Changeset 12079 in josm


Ignore:
Timestamp:
2017-05-07T00:16:14+02:00 (23 months ago)
Author:
michael2402
Message:

ScrollViewport: Fix layout computation, natively support mouse wheel

The layout size width/height is set to the one of the inner component if scrolling in that direction is not enabled.
The ScrollViewport now supports the mouse wheel in both horizontal and vertical versions.

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r11885 r12079  
    496496        if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
    497497            final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION);
    498             svp.addMouseWheelListener(e -> svp.scroll(0, e.getUnitsToScroll() * 5));
    499498            sideToolBar = svp;
    500499        }
  • trunk/src/org/openstreetmap/josm/gui/ScrollViewport.java

    r12073 r12079  
    141141        showOrHideButtons();
    142142
     143        if ((direction & VERTICAL_DIRECTION) != 0) {
     144            addMouseWheelListener(e -> scroll(0, e.getUnitsToScroll() * 5));
     145        } else if ((direction & HORIZONTAL_DIRECTION) != 0) {
     146            addMouseWheelListener(e -> scroll(e.getUnitsToScroll() * 5, 0));
     147        }
     148
    143149        timer.setRepeats(true);
    144150        timer.setInitialDelay(400);
     
    248254    @Override
    249255    public Dimension getPreferredSize() {
    250         return vp.getPreferredSize();
     256        if (component == null) {
     257            return vp.getPreferredSize();
     258        } else {
     259            return component.getPreferredSize();
     260        }
    251261    }
    252262
    253263    @Override
    254264    public Dimension getMinimumSize() {
    255         return vp.getMinimumSize();
     265        if (component == null) {
     266            return vp.getMinimumSize();
     267        } else {
     268            Dimension minSize = component.getMinimumSize();
     269            if ((allowedScrollDirections & HORIZONTAL_DIRECTION) != 0) {
     270                minSize = new Dimension(20, minSize.height);
     271            }
     272            if ((allowedScrollDirections & VERTICAL_DIRECTION) != 0) {
     273                minSize = new Dimension(minSize.width, 20);
     274            }
     275            return minSize;
     276        }
    256277    }
    257278
Note: See TracChangeset for help on using the changeset viewer.