Java: How to get the scrolling method in OS X Lion?
Asked Answered
M

3

6

Since OS X supports the "natural scrolling", my applications works wrong. The natural scrolling is made for scroll panes, which I really like. But, when I want to zoom in/out, it works wrong. So, what I want to do is check the scroll method for OS X.
If it is "natural" I'll take the opposite of the scroll values from MouseWheelEvent.getWheelRotation() to make my zoom in/out behavior feel correct.

So, in short: How to know if OS X uses natural scrolling or not?

Marabelle answered 16/8, 2011 at 7:30 Comment(2)
please can you clarify what is un-natural scrolling is made for scroll panes, what/how is different int value from ScrollableUnitXxx and ScrollableTracksXxx against/to comparing with another native OSChacon
OS X provides a setting "natural scrolling". If you enable it and scroll, the content will follow your fingers. If it is not enabled, the scrollbars will follow your fingers, which makes the content move into the other direction.Marabelle
B
3

Found a solution.

First, you need a library to read .plist files. I used this one.

Than you can easily read in the GlobalPreferneces.plist (checked with fseventer which file is changed when changing the scroll option) to find out which kind of scrolling is enabled like this:

try {
    File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist");
    NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref);

    NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection");

    if(pref.boolValue()) {
        //natural scrolling is enabled
    }  
} catch (Exception ex) {
    System.out.println("Faild to parse plist: " + ex.getMessage());
}
Biogenesis answered 16/8, 2011 at 17:53 Comment(1)
That's indeed it. I've found the file and the value changes as I modify the setting. Thanks!Marabelle
B
1

As Apple has dropped Java, I don't think that there is built in method to detect if natural scrolling is enabled. However, you could read in in the .plist files for configuring mouse/touchpad behaviour (which is a basic xml file) and look for the property to enable natural scrolling is set to true or false.

You can find the required .plist files here:

User/Library/Preferences/ <- This folder is hidden in Lion!

com.apple.driver.AppleBluetoothMultitouch.mouse.plist

com.apple.driver.AppleHIDMouse.plist

Edit:

You can't read in a plist file with the standard Java Framework, as since Mac OS 10.4 all .plists are saved in binary format. See my other answer for a correct solution.

Biogenesis answered 16/8, 2011 at 7:44 Comment(5)
I found the folder, but the files you mentioned are not in there.Marabelle
That is very strange. Have you ever made changes to your mouse settings? Also you need to replace User with your own username :)Biogenesis
Yes, I made changes. Only using the GUI provided by Apple. The file shouldn't be gone because of the changes.Marabelle
Currently not sitting on a mac, but will try to figure this out this evening.Biogenesis
Hmmm... Your edit. Are you sure? I could open the file with a plain text editor...Marabelle
N
1

Take a look at Mike Swingler's answer on the java-dev mailing list. There is a whole thread about it.

Nessie answered 16/8, 2011 at 9:41 Comment(1)
Thanks for the topic, but there is still no answer at the mailing list.Marabelle

© 2022 - 2024 — McMap. All rights reserved.