Java:如何获取OS X Lion中的滚动方法?
由于 OS X 支持“自然滚动”,因此我的应用程序无法正常工作。自然滚动是为滚动窗格设计的,我真的很喜欢。但是,当我想放大/缩小时,它就出错了。所以,我想做的是检查 OS X 的滚动方法。
如果它是“自然”的,我将从 MouseWheelEvent.getWheelRotation()
中获取相反的滚动值,以使我的放大/缩小行为感觉正确。
简而言之:如何知道 OS X 是否使用自然滚动?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到了解决方案。
首先,您需要一个库来读取 .plist 文件。我使用了这个。
您可以轻松地在 GlobalPreferneces.plist 中读取(使用 fseventer 检查在更改滚动选项时更改了哪个文件)以找出启用了哪种滚动,如下所示:
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:
看看 Mike Swingler 关于 java- 的答案开发者邮件列表。有一个完整的线索。
Take a look at Mike Swingler's answer on the java-dev mailing list. There is a whole thread about it.
由于 Apple 已经放弃了 Java,我认为没有内置方法来检测是否启用了自然滚动。但是,您可以读入用于配置鼠标/触摸板行为的 .plist 文件(这是一个基本的 xml 文件),并查找将启用自然滚动的属性设置为 true 或 false。
您可以在此处找到所需的 .plist 文件:
User/Library/Preferences/ <- 此文件夹隐藏在 Lion 中!
com.apple.driver.AppleBluetoothMultitouch.mouse.plist
com.apple.driver.AppleHIDMouse.plist
编辑:
您无法使用标准 Java 框架读取 plist 文件,因为从 Mac OS 10.4 开始,所有 .plist 都以二进制格式保存。请参阅我的另一个答案以获得正确的解决方案。
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.