r2710 - trunk/src/main/java/org/chorem/jtimer/ui/system/win32
Author: echatellier Date: 2009-12-09 17:29:16 +0100 (Wed, 09 Dec 2009) New Revision: 2710 Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java Log: Refactor to be more compliant with jna convention. Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java 2009-12-08 16:30:21 UTC (rev 2709) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java 2009-12-09 16:29:16 UTC (rev 2710) @@ -18,6 +18,7 @@ package org.chorem.jtimer.ui.system.win32; +import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary; /** @@ -31,6 +32,9 @@ */ public interface Kernel32 extends StdCallLibrary { + /** Instance. */ + Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class); + /** * Retrieves the number of milliseconds that have elapsed since the system * was started. Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2009-12-08 16:30:21 UTC (rev 2709) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2009-12-09 16:29:16 UTC (rev 2710) @@ -18,6 +18,7 @@ package org.chorem.jtimer.ui.system.win32; +import com.sun.jna.Native; import com.sun.jna.Structure; import com.sun.jna.win32.StdCallLibrary; @@ -34,6 +35,9 @@ */ public interface User32 extends StdCallLibrary { + /** Instance. */ + User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); + /** * Contains the time of the last input. */ Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java 2009-12-08 16:30:21 UTC (rev 2709) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java 2009-12-09 16:29:16 UTC (rev 2710) @@ -20,8 +20,6 @@ import org.chorem.jtimer.ui.system.SystemInfo; -import com.sun.jna.Native; - /** * Win32 System info. * @@ -35,10 +33,7 @@ */ public class Win32SystemInfo implements SystemInfo { - protected Kernel32 k32Instance; - - protected User32 u32Instance; - + /** User32 {@link lastInputInfo}. */ protected User32.LASTINPUTINFO lastInputInfo; /** @@ -47,8 +42,6 @@ * Package visibility */ public Win32SystemInfo() { - k32Instance = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class); - u32Instance = (User32) Native.loadLibrary("user32", User32.class); lastInputInfo = new User32.LASTINPUTINFO(); } @@ -59,8 +52,8 @@ * @return idle time in milliseconds */ public int getIdleTimeMillisWin32() { - u32Instance.GetLastInputInfo(lastInputInfo); - return k32Instance.GetTickCount() - lastInputInfo.dwTime; + User32.INSTANCE.GetLastInputInfo(lastInputInfo); + return Kernel32.INSTANCE.GetTickCount() - lastInputInfo.dwTime; } /*
participants (1)
-
echatellier@users.chorem.org