piccolo2d / piccolo2d.java

Structured 2D Graphics Framework
http://piccolo2d.org
Other
51 stars 14 forks source link

PScrollPane does not use setInteracting() on the canvas #131

Closed mro closed 9 years ago

mro commented 9 years ago

Originally reported on Google Code with ID 131

What steps will reproduce the problem?
1. Use the ScrollingExemple class from teh official samples
2. click/drag the canvas : when moving, PDragSequenceEventHandler changes
the rendering quality as expected
3. click/drag either the vertical or the horizontal scrollbar : the
redering quality is the best by default... does not change when interacting.

What is the expected output?
using scroll bars should set the isInteracting flag on the canvas.

I'm using trunk 

I've tried to add the following code in teh PScrollPane construction. It
works but I believe there are far better ways to do this...
Indeed, if one uses setVerticalScrollBar on the PScrollPane patched with
the code below, it would lead to a memory leak as the old scrollbar would
still be linked to the PScrollPane through the notification/callback
mechanism...

I can try to propose other patches if someone guides me to a better idea !

verticalScrollBar.addAdjustmentListener(new AdjustmentListener() {
  private boolean lastAdjustingState = verticalScrollBar.getValueIsAdjusting();

  public void adjustmentValueChanged(AdjustmentEvent e) {
    final boolean isAdjusting = verticalScrollBar.getValueIsAdjusting();

    if (isAdjusting != lastAdjustingState) {
      Component c = getViewport().getView();
      if (c instanceof PCanvas) {
        final PCanvas canvas = (PCanvas)c;
        canvas.setInteracting(isAdjusting);
        final boolean isInteracting = canvas.getInteracting();
      }
      lastAdjustingState = isAdjusting;
    }
  }
});

Reported by lionel.victor on 2009-10-10 18:07:37

mro commented 9 years ago
This issue was closed by revision r877.

Reported by allain.lalonde on 2009-10-30 21:10:06

mro commented 9 years ago
I like this approach a lot. 

I've implemented it with a couple changes in  r877:
- I've modified the adjustment listener to be an instance field of the PViewport
- It doesn't hold a reference to its scrollbar
- I've made setVerticalScrollbar and setHorizontalScrollbar install and uninstall the
listener appropriately.

Thank you for pointing this out lionel. :)

Reported by allain.lalonde on 2009-10-30 21:11:42

mro commented 9 years ago
The ScrollingExample looks good to me on several platforms.

Reported by heuermh on 2009-11-04 07:25:55