PDA

View Full Version : Problem with Slider and Events.OnMouseUp



aminef
8 Dec 2010, 9:32 AM
I am trying to have the value of the slider only when the mouse is release, this event is fired if I click and release the slider bar itself but not when I drag and release the slider cursor.




Slider pageSlider = new Slider();
pageSlider.addListener(Events.OnMouseUp, new Listener<SliderEvent>() {

@Override
public void handleEvent(SliderEvent be) {
//do stuff...
}
});

I am using google Chrome as a browser and gxt 2.2.0

sven
8 Dec 2010, 9:45 AM
Why do you think this is a bug? If themouse up happens outside of the component, than this code would not get it, because you only listen to the mouseup within the component.

You need to use native event preview for example.

aminef
8 Dec 2010, 9:52 AM
It doesn't happen in both cases (inside or outside the slider) so I figured it might be a bug, sorry for the confusion anyway. But it doesn't catch the OnMouseUp when you use the slider control, but it does when you use the slider bar

sven
8 Dec 2010, 9:59 AM
I would use a completly different approach.

1) You can use the change event with a Timer. If the Change event fires two times within a given amount of time, cancel the timer and reschedule it.

2) Extend Slider and override onDragEnd and add your custom logic.

aminef
8 Dec 2010, 10:04 AM
That was exactly what I was trying to do ( solution 1 ) by adding this inside the handleEvent


DelayedTask delay = new DelayedTask(this);
delay.delay(1000);

sven
8 Dec 2010, 10:06 AM
This would always recreate the task, meaning you have it still fire all the time, just one second later. You need to cancel the previes one (do not revreate DelayedTask)

aminef
8 Dec 2010, 10:46 AM
It's funny but it seems impossible to create the delayTask outside the listener (it needs a listener to create it, and not null one). Do you have any tips for how to create this delayTask please?

sven
8 Dec 2010, 4:22 PM
slider.addListener(Events.Change, new Listener<SliderEvent>() {

DelayedTask t = new DelayedTask(new Listener<BaseEvent>() {

public void handleEvent(BaseEvent be) {
System.out.println("test");

}
});

public void handleEvent(SliderEvent be) {
t.delay(1000);
}
});

aminef
9 Dec 2010, 7:42 AM
Thank you sven!
It works perfectly

aminef
9 Dec 2010, 8:06 AM
I also have just one question if you don't mind:
What the difference between events that start with "on" like "Events.onChange" and the events that are without like "Events.Change"?

sven
9 Dec 2010, 8:33 AM
OnChange is a wrapper around a native browser event, while Change is some custom event fired by GXT.

aminef
9 Dec 2010, 8:33 AM
Thank you!

DamionS
10 Sep 2012, 4:20 AM
I have written a music player that uses the slider to show how much of the track has been played. As the slider is updated by the player with the played time of the track, I have to stop this update from happening if the user grabs the slider control or clicks the slider. In the case of the user clicking elsewhere on the slider the Change event is fine but if the user grabs the slider control then the change fires as the control is moved. This means that the process that updates the slider for the played time is turned on, hence causing multiple position updates and major confusion. Therefore the correct place for me to turn back on the played process is when the user releases the mouse button i.e. onMouseUp.

I have tried the dragEnd and this does not fire. I have check the event sequence and when you click on the slider the event sequence is Slider onMouseDown, Slider OnMouseUp, main widget onMouseUp and then the Slider change event. However when you grab the slider control (i.e. the little knob) you get Slider onMouseDown and the Changed event. The onMouseUp event does not fire for the slider or the widget it is contained in. I have been really careful to ensure that the mouse is released whilst still over the slider. Also VERY strangely if you grab the slider control using the right mouse button then the even sequence is correct i.e. Slider onMouseDown, Slider OnMouseUp, main widget onMouseUp and then the Slider change event.

This is causing me a major issue, can somebody please help.