Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Knob Grabbing #2

Merged
merged 1 commit into from
Dec 18, 2015
Merged

Improve Knob Grabbing #2

merged 1 commit into from
Dec 18, 2015

Conversation

smasher816
Copy link
Contributor

Thanks for this neat little library. I wanted to use a RangeSlider but JIDE was too big of a dependency for just one item and https://ernienotes.wordpress.com/2010/12/27/creating-a-java-swing-range-slider/ lacked features like ticks because of the custom ui. Yours fit the bill nicely. It's a shame more people have not found it 👍

Unfortunately in my testing I found that grabbing the knobs was very awkward. With the default parameters the range was way too small, forcing you to put your cursor towards the inside of the handles. If you put it in the middle or towards the outside your grabs would be ignored. I tried tweaking the constants in mouseMoved but ended up with strange results. With larger values you could grab the knobs past their rendered image on the outer sides, yet still not be able to grab the very inner images. It was clear there was some issue with the math/scaling not centering around the knobs correctly.

On a hunt for clues I looked at BasicSliderUI to see how they determined if a knob was grabbed. It turns out that they use rectangle clipping detection to check if the mouse is over the image. Unfortunately the rectangles it was using were protected and unable to be accessed from your code. However, by using a custom subclass of BasicSliderUI I made a public function to access the protected variable. With access to these variables checking for the various states became trivial.

With these changes grabbing the knobs works perfectly both horizontally and vertically. In my mind not using magic constants is a good thing; what if swing changed their images to a larger one? Suddenly the old acceptable range of '3' would be even more broken. With the rectangle clipping this issue is no longer present.

I hope this change helps you (future) others.

Uses calculateThumbLocation from the underlying BasicSliderUI to get an accurate location of the slider knobs, making them much easier to grab.
andronix3 added a commit that referenced this pull request Dec 18, 2015
@andronix3 andronix3 merged commit b802a95 into andronix3:master Dec 18, 2015
@andronix3
Copy link
Owner

Hi Rowan,

at first, thank you for your help,I really appretiate it.

Unfortunately your changes broke thumb rendering (since RangeSliderUI extends BasicSliderUI).

We must seach another solution.

Best regards

Andrey

@smasher816
Copy link
Contributor Author

Hi Andrey,

could you post an image of the issue? I have tested both Metal and GTK UI's and the thumbs render fine. If you want you could try my latest commit that simplifies the paint call a lot. smasher816@24d10c5

This is what it looks like for me:
http://imgur.com/a/wHeXb

@andronix3
Copy link
Owner

Hi Rowan,

screenshot attached.

I tried to debug it - it uses painting method from BasicSliderUI.

Best regards

Andrey

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 20:35
An: andronix3/SwingHacks SwingHacks@noreply.github.com
Cc: Andrey Kuznetsov andronix@gmx.net
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Hi Andrey,

could you post an image of the issue? I have tested both Metal and GTK UI's and the thumbs render fine. If you want you could try my latest commit that simplifies the paint call a lot. smasher816@ smasher816@24d10c5 24d10c5

This is what it looks like for me:
http://imgur.com/a/wHeXb


Reply to this email directly or view it on GitHub #2 (comment) . https://github.com/notifications/beacon/AMFsujEsQ66OJCjMvgbBDsIsNLqX5avTks5pRFdtgaJpZM4G3-qp.gif

@smasher816
Copy link
Contributor Author

Unfortunately I can't seem to find an attached image. I'm not sure if
github supports email attachments as these replies are also displayed
through the website.

On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov notifications@github.com
wrote:

Hi Rowan,

screenshot attached.

I tried to debug it - it uses painting method from BasicSliderUI.

Best regards

Andrey

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 20:35
An: andronix3/SwingHacks SwingHacks@noreply.github.com
Cc: Andrey Kuznetsov andronix@gmx.net
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Hi Andrey,

could you post an image of the issue? I have tested both Metal and GTK
UI's and the thumbs render fine. If you want you could try my latest commit
that simplifies the paint call a lot. smasher816@ <
smasher816@24d10c558267393b2ddc0a102f44ff22121cb480>
24d10c5

This is what it looks like for me:
http://imgur.com/a/wHeXb


Reply to this email directly or view it on GitHub <
https://github.com/andronix3/SwingHacks/pull/2#issuecomment-165878613> . <
https://github.com/notifications/beacon/AMFsujEsQ66OJCjMvgbBDsIsNLqX5avTks5pRFdtgaJpZM4G3-qp.gif>


Reply to this email directly or view it on GitHub
#2 (comment).

@andronix3
Copy link
Owner

http://imgur.com/Zfv4OXY

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 22:47
An: andronix3/SwingHacks SwingHacks@noreply.github.com
Cc: Andrey Kuznetsov andronix@gmx.net
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Unfortunately I can't seem to find an attached image. I'm not sure if
github supports email attachments as these replies are also displayed
through the website.

On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov <notifications@github.com mailto:notifications@github.com >
wrote:

Hi Rowan,

screenshot attached.

I tried to debug it - it uses painting method from BasicSliderUI.

Best regards

Andrey

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 20:35
An: andronix3/SwingHacks <SwingHacks@noreply.github.com mailto:SwingHacks@noreply.github.com >
Cc: Andrey Kuznetsov <andronix@gmx.net mailto:andronix@gmx.net >
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Hi Andrey,

could you post an image of the issue? I have tested both Metal and GTK
UI's and the thumbs render fine. If you want you could try my latest commit
that simplifies the paint call a lot. smasher816@ <
smasher816@24d10c558267393b2ddc0a102f44ff22121cb480>
24d10c5

This is what it looks like for me:
http://imgur.com/a/wHeXb


Reply to this email directly or view it on GitHub <
https://github.com/andronix3/SwingHacks/pull/2#issuecomment-165878613> . <
https://github.com/notifications/beacon/AMFsujEsQ66OJCjMvgbBDsIsNLqX5avTks5pRFdtgaJpZM4G3-qp.gif>


Reply to this email directly or view it on GitHub
#2 (comment).


Reply to this email directly or view it on GitHub #2 (comment) . https://github.com/notifications/beacon/AMFsuoAZ67tRiBHyL7X_D54TfjkVg_L3ks5pRHY2gaJpZM4G3-qp.gif

@andronix3
Copy link
Owner

Hi Rowan,

I found the solution.

We need RangeSliderUI just for thumb calculations.

So instead of slider.setUI() we call installUI(slider) and keep reference on it.

Best regards

Andrey

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 22:47
An: andronix3/SwingHacks SwingHacks@noreply.github.com
Cc: Andrey Kuznetsov andronix@gmx.net
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Unfortunately I can't seem to find an attached image. I'm not sure if
github supports email attachments as these replies are also displayed
through the website.

On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov <notifications@github.com mailto:notifications@github.com >
wrote:

Hi Rowan,

screenshot attached.

I tried to debug it - it uses painting method from BasicSliderUI.

Best regards

Andrey

Von: Rowan Decker [mailto:notifications@github.com]
Gesendet: Freitag, 18. Dezember 2015 20:35
An: andronix3/SwingHacks <SwingHacks@noreply.github.com mailto:SwingHacks@noreply.github.com >
Cc: Andrey Kuznetsov <andronix@gmx.net mailto:andronix@gmx.net >
Betreff: Re: [SwingHacks] Improve Knob Grabbing (#2)

Hi Andrey,

could you post an image of the issue? I have tested both Metal and GTK
UI's and the thumbs render fine. If you want you could try my latest commit
that simplifies the paint call a lot. smasher816@ <
smasher816@24d10c558267393b2ddc0a102f44ff22121cb480>
24d10c5

This is what it looks like for me:
http://imgur.com/a/wHeXb


Reply to this email directly or view it on GitHub <
https://github.com/andronix3/SwingHacks/pull/2#issuecomment-165878613> . <
https://github.com/notifications/beacon/AMFsujEsQ66OJCjMvgbBDsIsNLqX5avTks5pRFdtgaJpZM4G3-qp.gif>


Reply to this email directly or view it on GitHub
#2 (comment).


Reply to this email directly or view it on GitHub #2 (comment) . https://github.com/notifications/beacon/AMFsuoAZ67tRiBHyL7X_D54TfjkVg_L3ks5pRHY2gaJpZM4G3-qp.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants