r2905 - in branches: . ng-jtimer ng-jtimer/jtimer-client ng-jtimer/jtimer-client/src ng-jtimer/jtimer-client/src/main ng-jtimer/jtimer-client/src/main/java ng-jtimer/jtimer-client/src/main/java/org ng-jtimer/jtimer-client/src/main/java/org/chorem ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/syst
Author: echatellier Date: 2013-07-19 15:36:34 +0200 (Fri, 19 Jul 2013) New Revision: 2905 Url: http://chorem.org/projects/jtimer/repository/revisions/2905 Log: Initial v2 import Added: branches/ng-jtimer/ branches/ng-jtimer/LICENSE.txt branches/ng-jtimer/README.txt branches/ng-jtimer/jtimer-client/ branches/ng-jtimer/jtimer-client/LICENSE.txt branches/ng-jtimer/jtimer-client/README.txt branches/ng-jtimer/jtimer-client/pom.xml branches/ng-jtimer/jtimer-client/src/ branches/ng-jtimer/jtimer-client/src/main/ branches/ng-jtimer/jtimer-client/src/main/java/ branches/ng-jtimer/jtimer-client/src/main/java/org/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/JTimer.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ResourcesServlet.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfo.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/UnsupportedSystemInfoException.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/package-info.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/package-info.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/X11.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/Xss.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/package-info.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/User32.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/package-info.java branches/ng-jtimer/jtimer-client/src/main/resources/ branches/ng-jtimer/jtimer-client/src/test/ branches/ng-jtimer/jtimer-client/src/test/java/ branches/ng-jtimer/jtimer-client/src/test/resources/ branches/ng-jtimer/jtimer-server/ branches/ng-jtimer/jtimer-server/LICENSE.txt branches/ng-jtimer/jtimer-server/README.txt branches/ng-jtimer/jtimer-server/pom.xml branches/ng-jtimer/jtimer-server/src/ branches/ng-jtimer/jtimer-server/src/main/ branches/ng-jtimer/jtimer-server/src/main/config/ branches/ng-jtimer/jtimer-server/src/main/config/wro.properties branches/ng-jtimer/jtimer-server/src/main/config/wro.xml branches/ng-jtimer/jtimer-server/src/main/java/ branches/ng-jtimer/jtimer-server/src/main/java/org/ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ProxyService.java branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerProject.java branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerTask.java branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/StorageException.java branches/ng-jtimer/jtimer-server/src/main/resources/ branches/ng-jtimer/jtimer-server/src/main/webapp/ branches/ng-jtimer/jtimer-server/src/main/webapp/web/ branches/ng-jtimer/jtimer-server/src/main/webapp/web/index.html branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/ branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/app.js branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/controllers.js branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/ branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/jtimer.css branches/ng-jtimer/jtimer-server/src/test/ branches/ng-jtimer/jtimer-server/src/test/java/ branches/ng-jtimer/jtimer-server/src/test/resources/ branches/ng-jtimer/pom.xml Added: branches/ng-jtimer/LICENSE.txt =================================================================== Added: branches/ng-jtimer/README.txt =================================================================== Added: branches/ng-jtimer/jtimer-client/LICENSE.txt =================================================================== Added: branches/ng-jtimer/jtimer-client/README.txt =================================================================== Added: branches/ng-jtimer/jtimer-client/pom.xml =================================================================== --- branches/ng-jtimer/jtimer-client/pom.xml (rev 0) +++ branches/ng-jtimer/jtimer-client/pom.xml 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.chorem</groupId> + <artifactId>jtimer</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.chorem.jtimer</groupId> + <artifactId>jtimer-client</artifactId> + <packaging>jar</packaging> + + <properties> + <maven.jar.main.class>org.chorem.jtimer.JTimer</maven.jar.main.class> + </properties> + + <dependencies> + <dependency> + <groupId>org.chorem.jtimer</groupId> + <artifactId>jtimer-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.nativelibs4java</groupId> + <artifactId>bridj</artifactId> + <classifier>c-only</classifier> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.websocket</groupId> + <artifactId>websocket-server</artifactId> + <version>9.0.4.v20130625</version> +</dependency> +<dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>9.0.4.v20130625</version> +</dependency> +<dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <version>9.0.4.v20130625</version> +</dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>tjws</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_3.0_spec</artifactId> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.oracle</groupId> + <artifactId>javafx</artifactId> + </dependency> + <dependency> + <groupId>javax</groupId> + <artifactId>javaee-api</artifactId> + <version>7.0</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>${maven.jar.main.class}</mainClass> + </manifest> + </archive> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Property changes on: branches/ng-jtimer/jtimer-client/pom.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/JTimer.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/JTimer.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/JTimer.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,122 @@ +package org.chorem.jtimer; + +import java.util.Properties; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; +import javafx.stage.Stage; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; + +import Acme.Serve.Serve; + +public class JTimer extends Application { + + public static final int PORT = 8888; + + protected static Serve server; + + public static void main(String[] args) throws Exception { + + JTimer jtimer = new JTimer(); + int port = jtimer.startLocalServer(args); + jtimer.startClient(port, args); + } + + /** + * Start server, return port. + * + * @param args args + * @return port + */ + protected int startLocalServer(String[] args) throws Exception { + + server = new Serve(); + // properties + Properties properties = new Properties(); + properties.put("port", PORT); + server.arguments = properties; + // resources + server.addDefaultServlets(null); + server.addServlet("/web/*", new ResourcesServlet("")); + server.addServlet("/rest/*", new ProxyService()); + + Thread thread = new Thread() { + public void run() { + System.out.println("Starting server..."); + server.serve(); + server.destroyAllServlets(); + System.out.println("Server stopped, exiting..."); + } + }; + thread.start(); + return PORT; + } + + /** + * Start server, return port. + * + * @param args args + * @return port + */ + protected int startLocalServer2(String[] args) throws Exception { + + Server server = new Server(PORT); + + ServletHandler handler = new ServletHandler(); + server.setHandler(handler); + + handler.addServletWithMapping(ResourcesServlet.class, "/web/*"); + handler.addServletWithMapping(ProxyService.class, "/rest/*"); + + server.start(); + server.join(); + + return PORT; + } + + protected void startClient(int port, String[] args) throws Exception { + if (args.length == 1) { + startChrome(port, args); + } else { + startWebView(port, args); + } + } + + protected void startWebView(int port, String[] args) { + launch(args); + } + + @Override + public void start(Stage stage) throws Exception { + stage.setTitle("jTimer (jfx)"); + WebView browser = new WebView(); + WebEngine webEngine = browser.getEngine(); + webEngine.load("http://localhost:8888/web/index.html"); + + Scene scene = new Scene(browser, 460, 510); + stage.setScene(scene); + stage.show(); + } + + @Override + public void stop() throws Exception { + System.out.println("Stopping server..."); + server.notifyStop(); + } + + protected void startChrome(int port, String[] args) throws Exception { + System.out.println("Starting client"); + ProcessBuilder processBuilder = new ProcessBuilder("chromium", + "-app=http://localhost:" + port + "/web/index.html", + "--user-data-dir=" + System.getProperty("user.home") + "/.jtimer/chrome"); + processBuilder.redirectErrorStream(true); + Process process = processBuilder.start(); + int status = process.waitFor(); + System.out.println("Client stopped with status " + status); + stop(); + } +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/JTimer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ResourcesServlet.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ResourcesServlet.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ResourcesServlet.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,62 @@ +package org.chorem.jtimer; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Static resources servlet. + * + * @author Eric Chatellier + */ +public class ResourcesServlet extends HttpServlet { + + /** serialVersionUID. */ + private static final long serialVersionUID = -7599418973752605746L; + + protected String classPathPrefix; + + public ResourcesServlet(String classPathPrefix) { + if (classPathPrefix.endsWith("/")) { + classPathPrefix += "/"; + } + this.classPathPrefix = classPathPrefix; + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String contextPath = req.getContextPath(); + String requestUri = req.getRequestURI(); + + System.out.println("contextPath = " + contextPath); + System.out.println("Request uri = " + requestUri); + + InputStream is = ResourcesServlet.class.getResourceAsStream(classPathPrefix + requestUri); + + if (is == null) { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + OutputStream out = resp.getOutputStream(); + copyLarge(is, out, new byte[4096]); + } + } + + /** + * {@link IOUtils#copyLarge(InputStream, OutputStream)}. + */ + protected long copyLarge(InputStream input, OutputStream output, byte[] buffer) + throws IOException { + long count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + count += n; + } + return count; + } +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/ResourcesServlet.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfo.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfo.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfo.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,45 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system; + +/** + * System info interface for all systems. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface SystemInfo { + + /** + * Get system idle time in milliseconds. + * + * @return system idle time in milliseconds + */ + public long getIdleTime(); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfo.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,94 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.bridj.Platform; +import org.chorem.jtimer.system.macos.MacOSSystemInfo; +import org.chorem.jtimer.system.unix.UnixSystemInfo; +import org.chorem.jtimer.system.win32.Win32SystemInfo; + +/** + * Build system info determined from system. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SystemInfoFactory { + + /** log */ + private static Log log = LogFactory.getLog(SystemInfoFactory.class); + + /** Single instance */ + protected static SystemInfo instance; + + /** + * SystemInfoFactory Constructor. + */ + protected SystemInfoFactory() { + + } + + /** + * Return system info depending on system. + * + * @return SystemInfo instance + * @see SystemInfo + * @throws UnsupportedSystemInfoException if system info is not supported + * for system + */ + public static SystemInfo getSystemInfo() + throws UnsupportedSystemInfoException { + + if (instance == null) { + String os = System.getProperty("os.name"); + + // log it + if (log.isInfoEnabled()) { + log.info("Try do build system info for system : " + os); + } + + // try windows + if (Platform.isWindows()) { + instance = new Win32SystemInfo(); + } else if (Platform.isLinux()) { + instance = new UnixSystemInfo(); + } else if (Platform.isMacOSX()) { + instance = new MacOSSystemInfo(); + } else { + // system unknown + throw new UnsupportedSystemInfoException( + "Can't get system info for " + os); + } + } + + return instance; + } +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/UnsupportedSystemInfoException.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/UnsupportedSystemInfoException.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/UnsupportedSystemInfoException.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,69 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system; + +/** + * Exception thrown when system info is not available. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class UnsupportedSystemInfoException extends Exception { + + /** serialVersionUID. */ + private static final long serialVersionUID = 138458861335881500L; + + /** + * Constructor. + * + * @param message message + * @param cause cause + */ + public UnsupportedSystemInfoException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor. + * + * @param message message + */ + public UnsupportedSystemInfoException(String message) { + super(message); + } + + /** + * Constructor. + * + * @param cause cause. + */ + public UnsupportedSystemInfoException(Throwable cause) { + super(cause); + } +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/UnsupportedSystemInfoException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,66 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.macos; + +import org.bridj.BridJ; +import org.bridj.ann.Library; + +/** + * Mac OS X Bridj library. + * + * @author chatellier + * @version $Revision$ + * @since 1.3.2 + * + * Last update : $Date$ + * By : $Author$ + */ +@Library("ApplicationServices") +public class ApplicationServices { + static { + BridJ.register(); + } + + /** Constants that specify an input event. */ + public static final int kCGAnyInputEventType = ~0; + /** Specifies that an event source should use a private event state table. */ + public static final int kCGEventSourceStatePrivate = -1; + /** Specifies that an event source should use the event state table that reflects the combined state of all event sources posting to the current user login session. */ + public static final int kCGEventSourceStateCombinedSessionState = 0; + /** Specifies that an event source should use the event state table that reflects the combined state of all hardware event sources posting from the HID system. */ + public static final int kCGEventSourceStateHIDSystemState = 1; + + /** + * Returns the elapsed time since the last event for a Quartz event source. + * + * @param sourceStateId The source state to access + * @param eventType The event type to access + * @return the time in seconds since the previous input event of the specified type + * + * @see <a href="http://developer.apple.com/mac/library/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventSourceSecondsSinceLastEventType">Quartz API</a> + */ + public static native double CGEventSourceSecondsSinceLastEventType(int source, int eventType); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,56 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.macos; + +import org.chorem.jtimer.system.SystemInfo; + +/** + * MacOSSystemInfo + * + * Source : http://ochafik.free.fr/blog/?p=98#comment-17694 + * + * @author chatellier + * @version $Revision$ + * @since 1.3.2 + * + * Last update : $Date$ + * By : $Author$ + */ +public class MacOSSystemInfo implements SystemInfo { + + /* + * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() + */ + @Override + public long getIdleTime() { + double idleTimeSeconds = ApplicationServices + .CGEventSourceSecondsSinceLastEventType( + ApplicationServices.kCGEventSourceStateCombinedSessionState, + ApplicationServices.kCGAnyInputEventType); + return (long) (idleTimeSeconds * 1000); + } + +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/package-info.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/package-info.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/package-info.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,28 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * Mac OS specific system info implementation. + */ +package org.chorem.jtimer.system.macos; Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/macos/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/package-info.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/package-info.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/package-info.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,28 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * System interface using Bridj to get system information. + */ +package org.chorem.jtimer.system; Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,111 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.unix; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.bridj.Pointer; +import org.chorem.jtimer.system.SystemInfo; + +/** + * Linux system info. + * + * Based on + * http://java.net/projects/jdic/sources/svn/content/trunk/src/incubator/system... source code. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class UnixSystemInfo implements SystemInfo { + + /** log. */ + private static Log log = LogFactory.getLog(UnixSystemInfo.class); + + /* + * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() + */ + @Override + public long getIdleTime() { + + long idleTime = 0; + + try { + idleTime = getXssIdleTime(); + } catch (Exception e) { + // TODO catch more specific exception + if (log.isErrorEnabled()) { + log.error("Can't detect idle time : ", e); + } + idleTime = 0; + } + + return idleTime; + } + + /** + * Get idle time via Xss. + * + * @return idle time + */ + protected long getXssIdleTime() { + + long idleTime = 0; + + // get X11 display + X11.Display display = X11.XOpenDisplay(null); + if (display == null) { + log.error("Can't open X11 display"); + } else { + // Display is opened + Pointer<Xss.XScreenSaverInfo> screenSaverInfo = Xss.XScreenSaverAllocInfo(); + + if (screenSaverInfo == null) { + log.error("Could not alloc screen saver info"); + } else { + // get root window + X11.Window rootWindow = X11.XDefaultRootWindow(display); + int flag = Xss.XScreenSaverQueryInfo(display, rootWindow, screenSaverInfo); + if (flag == 0) { + log.error("Can't get user idle time"); + } else { + idleTime = screenSaverInfo.get().idle(); + } + + // free resources + X11.XFree(screenSaverInfo); + } + + // free resources + X11.XCloseDisplay(display); + } + + return idleTime; + } + +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/X11.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/X11.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/X11.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,60 @@ +package org.chorem.jtimer.system.unix; + +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.TypedPointer; +import org.bridj.ann.Library; + +/** + * Unix X11 Bridj library. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Library("X11") +public class X11 { + static { + BridJ.register(); + } + + public static class Drawable extends TypedPointer { + public Drawable(long peer) { + super(peer); + } + + public Drawable(Pointer<?> ptr) { + super(ptr); + } + } + + public static class Window extends Drawable { + public Window(long peer) { + super(peer); + } + + public Window(Pointer<?> ptr) { + super(ptr); + } + } + + public static class Display extends TypedPointer { + public Display(long peer) { + super(peer); + } + + public Display(Pointer<?> ptr) { + super(ptr); + } + } + + public static native Display XOpenDisplay(Pointer<Byte> name); + + public static native Window XDefaultRootWindow(Display display); + + public static native int XFree(Pointer data); + + public static native int XCloseDisplay(Display display); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/X11.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/Xss.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/Xss.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/Xss.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,156 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.unix; + +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.StructObject; +import org.bridj.ann.Field; +import org.bridj.ann.Library; +import org.bridj.ann.Ptr; + +/** + * Unix Xss Bridj library. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Library("Xss") +public class Xss { + static { + BridJ.register(); + } + + public static class XScreenSaverInfo extends StructObject { + public XScreenSaverInfo() { + super(); + } + + public XScreenSaverInfo(Pointer pointer) { + super(pointer); + } + + /** + * screen saver window<br> + * C type : Window + */ + @Ptr + @Field(0) + public long window() { + return this.io.getSizeTField(this, 0); + } + + /** + * screen saver window<br> + * C type : Window + */ + @Ptr + @Field(0) + public XScreenSaverInfo window(long window) { + this.io.setSizeTField(this, 0, window); + return this; + } + + // ScreenSaver{Off,On,Disabled} + @Field(1) + public int state() { + return this.io.getIntField(this, 1); + } + + // ScreenSaver{Off,On,Disabled} + @Field(1) + public XScreenSaverInfo state(int state) { + this.io.setIntField(this, 1, state); + return this; + } + + // ScreenSaver{Blanked,Internal,External} + @Field(2) + public int kind() { + return this.io.getIntField(this, 2); + } + + // ScreenSaver{Blanked,Internal,External} + @Field(2) + public XScreenSaverInfo kind(int kind) { + this.io.setIntField(this, 2, kind); + return this; + } + + // milliseconds + @org.bridj.ann.CLong + @Field(3) + public long til_or_since() { + return this.io.getCLongField(this, 3); + } + + // milliseconds + @org.bridj.ann.CLong + @Field(3) + public XScreenSaverInfo til_or_since(long til_or_since) { + this.io.setCLongField(this, 3, til_or_since); + return this; + } + + // milliseconds + @org.bridj.ann.CLong + @Field(4) + public long idle() { + return this.io.getCLongField(this, 4); + } + + // milliseconds + @org.bridj.ann.CLong + @Field(4) + public XScreenSaverInfo idle(long idle) { + this.io.setCLongField(this, 4, idle); + return this; + } + + // events + @org.bridj.ann.CLong + @Field(5) + public long event_mask() { + return this.io.getCLongField(this, 5); + } + + // events + @org.bridj.ann.CLong + @Field(5) + public XScreenSaverInfo event_mask(long event_mask) { + this.io.setCLongField(this, 5, event_mask); + return this; + } + } + + public static native Pointer<XScreenSaverInfo> XScreenSaverAllocInfo(); + + public static native int XScreenSaverQueryInfo(X11.Display dpy, + X11.Drawable drawable, Pointer<XScreenSaverInfo> saver_info); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/Xss.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/package-info.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/package-info.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/package-info.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,28 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * Linux specific system info implementation. + */ +package org.chorem.jtimer.system.unix; Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/unix/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,58 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.win32; + +import org.bridj.*; +import org.bridj.ann.*; + +/** + * Win Kernel32 Bridj library. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Convention(Convention.Style.StdCall) +@Library("kernel32") +public class Kernel32 { + static { + BridJ.register(); + } + + /** + * Retrieves the number of milliseconds that have elapsed since the system + * was started. + * + * @see <a + * href="http://msdn2.microsoft.com/en-us/library/ms724408.aspx">MSDN + * GetTickCount function</a> + * @return number of milliseconds that have elapsed since the system was + * started. + */ + public static native int GetTickCount(); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/User32.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/User32.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/User32.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,80 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.win32; + +import org.bridj.BridJ; +import org.bridj.Pointer; +import org.bridj.StructObject; +import org.bridj.ann.Convention; +import org.bridj.ann.Field; +import org.bridj.ann.Library; + +/** + * Win User32 Bridj library. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Convention(Convention.Style.StdCall) +@Library("user32") +public class User32 { + static { + BridJ.register(); + } + + /** + * Contains the time of the last input. + * + * @see <a + * href="http://msdn.microsoft.com/en-us/library/ms646272">MSDN + * LASTINPUTINFO structure</a> + */ + public static class LASTINPUTINFO extends StructObject { + @Field(0) + public int cbSize() { + return this.io.getIntField(this, 0); + } + + // / Tick count of when the last input event was received. + @Field(1) + public int dwTime() { + return this.io.getIntField(this, 1); + } + } + + /** + * Retrieves the time of the last input event. + * + * @see <a + * href="http://msdn.microsoft.com/en-us/library/ms646272">MSDN + * GetLastInputInfo function</a> + * @return time of the last input event, in milliseconds + */ + public static native boolean GetLastInputInfo(Pointer<LASTINPUTINFO> result); +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/User32.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,76 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.system.win32; + +import org.bridj.Pointer; +import org.chorem.jtimer.system.SystemInfo; + +/** + * Win32 System info. + * + * From https://github.com/ochafik/nativelibs4java. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class Win32SystemInfo implements SystemInfo { + + /** {@link User32.LASTINPUTINFO}. */ + protected User32.LASTINPUTINFO lastInputInfo; + + /** + * Constructor. + * + * Package visibility + */ + public Win32SystemInfo() { + lastInputInfo = new User32.LASTINPUTINFO(); + } + + /** + * Get the amount of milliseconds that have elapsed since the last input + * event (mouse or keyboard) + * + * @return idle time in milliseconds + */ + public int getIdleTimeMillisWin32() { + User32.LASTINPUTINFO lastInputInfo = new User32.LASTINPUTINFO(); + User32.GetLastInputInfo(Pointer.pointerTo(lastInputInfo)); + return Kernel32.GetTickCount() - lastInputInfo.dwTime(); + } + + /* + * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() + */ + @Override + public long getIdleTime() { + long millisTime = getIdleTimeMillisWin32(); + return millisTime; + } +} Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/package-info.java =================================================================== --- branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/package-info.java (rev 0) +++ branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/package-info.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,28 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * Windows specific system info implementation. + */ +package org.chorem.jtimer.system.win32; Property changes on: branches/ng-jtimer/jtimer-client/src/main/java/org/chorem/jtimer/system/win32/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/LICENSE.txt =================================================================== Added: branches/ng-jtimer/jtimer-server/README.txt =================================================================== Added: branches/ng-jtimer/jtimer-server/pom.xml =================================================================== --- branches/ng-jtimer/jtimer-server/pom.xml (rev 0) +++ branches/ng-jtimer/jtimer-server/pom.xml 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.chorem</groupId> + <artifactId>jtimer</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.chorem.jtimer</groupId> + <artifactId>jtimer-server</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.2.4</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_3.0_spec</artifactId> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <directory>src/main/webapp</directory> + <includes> + <include>web/*.html</include> + </includes> + </resource> + </resources> + + <plugins> + <plugin> + <groupId>ro.isdc.wro4j</groupId> + <artifactId>wro4j-maven-plugin</artifactId> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + + <configuration> + <targetGroups>jtimer</targetGroups> + <contextFolder>${basedir}/src/main/webapp/web/</contextFolder> + <cssDestinationFolder>${basedir}/target/classes/web/css</cssDestinationFolder> + <jsDestinationFolder>${basedir}/target/classes/web/js</jsDestinationFolder> + <wroManagerFactory>org.nuiton.js.wro.NuitonJsMavenWroManagerFactory</wroManagerFactory> + <wroFile>${basedir}/src/main/config/wro.xml</wroFile> + <extraConfigFile>${basedir}/src/main/config/wro.properties</extraConfigFile> + </configuration> + </plugin> + </plugins> + </build> +</project> Property changes on: branches/ng-jtimer/jtimer-server/pom.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/config/wro.properties =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/config/wro.properties (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/config/wro.properties 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,3 @@ +preProcessors=cssVariables,forceCssDataUri,cssUrlRewriting,cssImport,semicolonAppender +postProcessors= +#cssMinJawr,jsMin Property changes on: branches/ng-jtimer/jtimer-server/src/main/config/wro.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/config/wro.xml =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/config/wro.xml (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/config/wro.xml 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,9 @@ +<groups xmlns="http://www.isdc.ro/wro"> + <group name='jtimer'> + <group-ref>angular</group-ref> + <group-ref>jquery</group-ref> + <group-ref>bootstrap</group-ref> + <css>/styles/*.css</css> + <js>/scripts/*.js</js> + </group> +</groups> Property changes on: branches/ng-jtimer/jtimer-server/src/main/config/wro.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ProxyService.java =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ProxyService.java (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ProxyService.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,85 @@ +package org.chorem.jtimer; + +import java.io.IOException; +import java.lang.reflect.Method; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.chorem.jtimer.storage.Storage; + +import com.google.gson.Gson; + +public class ProxyService extends HttpServlet { + + /** serialVersionUID. */ + private static final long serialVersionUID = -5180281013629027617L; + + protected Storage storage; + + protected Gson gson; + + public ProxyService() { + storage = new Storage(); + gson = new Gson(); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + callMethod("get", req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + callMethod("get", req, resp); + } + + @Override + protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + callMethod("get", req, resp); + } + + @Override + protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + callMethod("get", req, resp); + } + + protected void callMethod(String prefix, HttpServletRequest req, HttpServletResponse resp) throws IOException { + + String contextPath = req.getContextPath(); + String requestUri = req.getRequestURI(); + + String query = requestUri; + System.out.println("requestUri = " + requestUri); + if (query.startsWith("/rest/")) { + query = query.substring("/rest/".length()); + } + + String methodName = prefix + Character.toTitleCase(query.charAt(0)) + query.substring(1); + System.out.println("Callling method " + methodName); + Method[] methods = Storage.class.getMethods(); + Method method = null; + for (Method m : methods) { + if (m.getName().equalsIgnoreCase(methodName)) { + method = m; + } + } + + if (method == null) { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + try { + Object result = method.invoke(storage); + String json = gson.toJson(result); + resp.setContentType("application/json"); + ServletOutputStream out = resp.getOutputStream(); + out.print(json); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} Property changes on: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/ProxyService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerProject.java =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerProject.java (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerProject.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,56 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.entities; + +/** + * Represent a project. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class TimerProject extends TimerTask { + + /** serialVersionUID. */ + private static final long serialVersionUID = -8953488997256237790L; + + /** + * Constructor. + */ + public TimerProject() { + } + + /** + * Constructor with name. + * + * @param name project name + */ + public TimerProject(String name) { + super(name); + } +} Property changes on: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerProject.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerTask.java =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerTask.java (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,288 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.jtimer.entities; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * Represents a task. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class TimerTask implements Serializable { + + /** serialVersionUID */ + private static final long serialVersionUID = -7590755569706702695L; + + /** Task number. */ + protected long number; + + /** Parent task number. */ + protected long parent; + + /** Task name. */ + protected String name; + + /** Creation date. */ + protected Date creationDate; + + /** Closed task. */ + protected boolean closed; + + /** + * Map calendar of day -> time (ms). (ordered on keys) + */ + protected SortedMap<Date, Long> allDaysTimes; + + /** + * Map date -> annotation text. + */ + protected SortedMap<Date, String> allDaysAnnotations; + + /** + * Sub tasks. + */ + protected List<TimerTask> subTasks; + + /** + * Constructor. + */ + public TimerTask() { + //allDaysTimes = new DailySortedMap<Long>(); + // les annoation sont à la seconde pres + allDaysAnnotations = new TreeMap<Date, String>(); + subTasks = new ArrayList<TimerTask>(); + + // wrong value to detect bug + number = -1; + } + + /** + * Constructor with name. + * + * @param name task name + */ + public TimerTask(String name) { + this(); + this.name = name; + } + + /** + * Get task number. + * + * @return the number + */ + public long getNumber() { + return number; + } + + /** + * Set task number. + * + * @param number the number to set + */ + public void setNumber(long number) { + this.number = number; + } + + public long getParent() { + return parent; + } + + public void setParent(long parent) { + this.parent = parent; + } + + /** + * Get task name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Set task name. + * + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get task creation date. + * + * @return task creation date + */ + public Date getCreationDate() { + return creationDate; + } + + /** + * Set task creation date. + * + * @param creationDate creation date + */ + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + /** + * Get closed task state. + * + * @return <tt>true</tt> if task is closed + */ + public boolean isClosed() { + return closed; + } + + /** + * Set closed. + * + * @param closed closed + */ + public void setClosed(boolean closed) { + this.closed = closed; + } + + /** + * Get task's subtasks. + * + * @return the subTasks + */ + public List<TimerTask> getSubTasks() { + return subTasks; + } + + /** + * Add task's subtask. + * + * Also add parent reference. + * + * @param t the task to add + * @return success flag + */ + public boolean addTask(TimerTask t) { + boolean result = subTasks.add(t); + return result; + } + + /** + * Add time. + * + * @param date date + * @param time time in ms + */ + public void setTime(Date date, Long time) { + allDaysTimes.put(date, time); + } + + /** + * Get time at date. + * + * @param date date + * @return time at specified date in ms + */ + public long getTime(Date date) { + long result = 0; + + Long t = allDaysTimes.get(date); + if (t != null) { + result = t.longValue(); + } + + return result; + } + + /** + * Return all data. Sorted on date. + * + * @return total duration of all projects + */ + public SortedMap<Date, Long> getAllDaysAndTimes() { + return allDaysTimes; + } + + /** + * Add annotation. + * + * @param date date + * @param note note text + */ + public void addAnnotation(Date date, String note) { + allDaysAnnotations.put(date, note); + } + + /** + * Return all annotation, sorted on date. + * + * @return annotations + */ + public SortedMap<Date, String> getAllDaysAnnotations() { + return allDaysAnnotations; + } + + /* + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return name + subTasks.toString(); + } + + /* + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int result = (int)(number % 31); + return result; + } + + /* + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + + if (!(o instanceof TimerTask)) { + return false; + } + + return number == ((TimerTask)o).getNumber(); + } +} \ No newline at end of file Property changes on: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/entities/TimerTask.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/Storage.java =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/Storage.java (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/Storage.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,453 @@ +package org.chorem.jtimer.storage; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; + +/** + * Implementation du stockage des taches en base de données basée sur h2. + * + * Le schema est composé des tables: + * <ul> + * <li>Task + * <li>TaskTime + * <li>Version (contenant la version du schema en cas de migration)</li> + * </ul> + * + * @author echatellier + */ +public class Storage { + + private static final Log log = LogFactory.getLog(Storage.class); + + protected static final String TABLE_TASK = "task"; + protected static final String TABLE_TIME = "tasktime"; + protected static final String TABLE_VERSION = "version"; + + protected Connection connection; + + public Storage() { + + try { + if (log.isDebugEnabled()) { + log.debug("Registering jdbc driver"); + } + Class.forName("org.h2.Driver"); + } catch (ClassNotFoundException e) { + if (log.isErrorEnabled()) { + log.fatal("Can't find h2 driver"); + } + } + + try { + connection = getConnection(); + } catch (SQLException ex) { + throw new StorageException("Can't open database", ex); + } + + if (getProjectsCount() == 0) { + addProject(new TimerProject("Test1")); + addProject(new TimerProject("Test2")); + addProject(new TimerProject("Test3")); + addProject(new TimerProject("Test4")); + } + } + + @Override + protected void finalize() throws Throwable { + connection.close(); + } + + protected Connection getConnection() throws SQLException { + + String url = "/tmp/jtimer/jtimer"; + if (log.isInfoEnabled()) { + log.info("Opening connection to database : " + url); + } + Connection conn = DriverManager.getConnection("jdbc:h2:" + url, "sa", + ""); + conn.setAutoCommit(true); + + // test to create schema if it not already exists + boolean schemaExists = schemaExists(conn); + if (!schemaExists) { + if (log.isInfoEnabled()) { + log.info("Creating new database schema"); + } + createSchema(conn); + + // set new version in schema + Statement statement = conn.createStatement(); + statement.executeUpdate("INSERT INTO VERSION VALUES('2.0')"); + } + + return conn; + } + + protected void closeConnection(Connection conn) throws SQLException { + if (conn != null) { + conn.close(); + } + } + + protected void closeStatement(Statement stmt) { + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException ex) { + throw new StorageException("Can't close statement", ex); + } + } + } + + /** + * Test if table "version" exists in database list. + * + * @param conn sql connection + * @return schema exists + */ + protected boolean schemaExists(Connection conn) { + boolean found = false; + Statement statement = null; + try { + statement = conn.createStatement(); + ResultSet rs = statement.executeQuery("SELECT table_name FROM information_schema.tables;"); + while (rs.next()) { + String name = rs.getString(1); + if (TABLE_VERSION.equalsIgnoreCase(name)) { + found = true; + } + } + } catch (SQLException ex) { + throw new StorageException("Can't test schema", ex); + } finally { + closeStatement(statement); + } + + return found; + } + + protected void createSchema(Connection conn) { + Statement statement = null; + try { + statement = conn.createStatement(); + statement.executeUpdate("CREATE TABLE " + TABLE_VERSION + + "(version VARCHAR(10))"); + statement.executeUpdate("CREATE TABLE " + TABLE_TASK + + "(id LONG NOT NULL AUTO_INCREMENT PRIMARY KEY," + + " name VARCHAR(255) NOT NULL," + + " parent LONG DEFAULT 0," + + " hidden BOOLEAN," + + " note TEXT)"); + statement.executeUpdate("CREATE TABLE " + TABLE_TIME + + "(taskid LONG NOT NULL REFERENCES " + TABLE_TASK + "(id)," + + " date DATE," + + " duration LONG," + + " PRIMARY KEY (taskid, date))"); + } catch (SQLException ex) { + throw new StorageException("Can't create schema", ex); + } finally { + closeStatement(statement); + } + + } + + /** + * Find all project. (task with no parent, parent = 0). + * + * @return all projects + */ + public int getProjectsCount() { + int result = 0; + Statement statement = null; + try { + statement = connection.createStatement(); + ResultSet rs = statement.executeQuery("SELECT count(*) FROM " + TABLE_TASK + + " WHERE parent = 0"); + if (rs.next()) { + result = rs.getInt(1); + } + } catch (SQLException ex) { + throw new StorageException("Can't get project count", ex); + } finally { + closeStatement(statement); + } + return result; + } + + /** + * Find all project. (task with no parent, parent = 0). + * + * @return all projects + */ + public List<TimerProject> getProjects() { + List<TimerProject> projects = new ArrayList<TimerProject>(); + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + + " WHERE parent = 0 ORDER BY id"); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + TimerProject project = new TimerProject(); + project.setNumber(rs.getInt("id")); + project.setName(rs.getString("name")); + projects.add(project); + } + } catch (SQLException ex) { + throw new StorageException("Can't get project", ex); + } finally { + closeStatement(statement); + } + return projects; + } + + /** + * Find all project. (task with no parent, parent = 0). + * + * @return all projects + */ + public TimerProject getProject(int offset) { + TimerProject project = null; + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + + " WHERE parent = 0 ORDER BY id LIMIT 1 OFFSET ?"); + statement.setInt(1, offset); + ResultSet rs = statement.executeQuery(); + if (rs.next()) { + project = new TimerProject(); + project.setNumber(rs.getInt("id")); + project.setName(rs.getString("name")); + } + } catch (SQLException ex) { + throw new StorageException("Can't get project", ex); + } finally { + closeStatement(statement); + } + return project; + } + + /** + * Find all project. (task with no parent, parent = 0). + * + * @return all projects + */ + public int getTasksCount(TimerTask parent) { + int result = 0; + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("SELECT count(*) FROM " + TABLE_TASK + + " WHERE parent = ?"); + statement.setLong(1, parent.getNumber()); + ResultSet rs = statement.executeQuery(); + if (rs.next()) { + result = rs.getInt(1); + } + } catch (SQLException ex) { + throw new StorageException("Can't get task count", ex); + } finally { + closeStatement(statement); + } + return result; + } + + public TimerTask getTasks(TimerTask parent, int offset) { + TimerTask task = null; + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + + " WHERE parent = ? ORDER BY id LIMIT 1 OFFSET ?"); + statement.setLong(1, parent.getNumber()); + statement.setLong(2, offset); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + task = new TimerTask(); + task.setNumber(rs.getInt("id")); + task.setName(rs.getString("name")); + } + } catch (SQLException ex) { + throw new StorageException("Can't get task", ex); + } finally { + closeStatement(statement); + } + return task; + } + + /** + * Find sub tasks.. + * + * @param parent parent task + * @return all sub tasks + */ + public List<TimerTask> getTasks(TimerTask parent) { + List<TimerTask> tasks = new ArrayList<TimerTask>(); + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + + " WHERE parent = ? ORDER BY id"); + statement.setLong(1, parent.getNumber()); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + TimerTask task = new TimerTask(); + task.setNumber(rs.getInt("id")); + task.setName(rs.getString("name")); + tasks.add(task); + } + } catch (SQLException ex) { + throw new StorageException("Can't get task", ex); + } finally { + closeStatement(statement); + } + return tasks; + } + + public void addProject(TimerProject project) { + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("INSERT INTO " + + TABLE_TASK + "(name, parent, hidden, note)" + + " VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + statement.setString(1, project.getName()); + statement.setLong(2, 0); + statement.setBoolean(3, project.isClosed()); + statement.setString(4, null /*project.getNote()*/); + statement.executeUpdate(); + + // get generated id + ResultSet rs = statement.getGeneratedKeys(); + if (rs.next()) { + project.setNumber(rs.getInt(1)); + } + } catch (SQLException ex) { + throw new StorageException("Can't add project", ex); + } finally { + closeStatement(statement); + } + } + + public void addTask(TimerTask task) { + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("INSERT INTO " + + TABLE_TASK + "(name, parent, hidden, note)" + + " VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + statement.setString(1, task.getName()); + statement.setLong(2, task.getParent()); + statement.setBoolean(3, task.isClosed()); + statement.setString(4, null /*project.getNote()*/); + statement.executeUpdate(); + + // get generated id + ResultSet rs = statement.getGeneratedKeys(); + if (rs.next()) { + task.setNumber(rs.getInt(1)); + } + } catch (SQLException ex) { + throw new StorageException("Can't add project", ex); + } finally { + closeStatement(statement); + } + } + + public void modifyProject(TimerProject project) { + modifyTask(project); + } + + public void modifyTask(TimerTask task) { + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("UPDATE " + + TABLE_TASK + " SET name=?, parent=?, hidden=?, note=?" + + " WHERE id = ?"); + statement.setString(1, task.getName()); + if (task.getParent() > 0) { + statement.setLong(2, 0); + } else { + statement.setLong(2, task.getParent()); + } + statement.setBoolean(3, task.isClosed()); + statement.setString(4, null /*project.getNote()*/); + statement.setLong(5, task.getNumber()); + statement.executeUpdate(); + } catch (SQLException ex) { + throw new StorageException("Can't modify task", ex); + } finally { + closeStatement(statement); + } + } + + protected void saveTaskTimes(TimerTask task) throws SQLException { + + // delete all + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("DELETE " + TABLE_TIME + + " WHERE TASKID = ?"); + statement.setLong(1, task.getNumber()); + statement.executeUpdate(); + } finally { + closeStatement(statement); + } + + // add new + try { + statement = connection.prepareStatement("INSERT INTO " + TABLE_TIME + + "(taskid, date, duration)" + + " VALUES(?, ?, ?)"); + SortedMap<Date, Long> taskTimes = task.getAllDaysAndTimes(); + for (Map.Entry<Date, Long> taskTime : taskTimes.entrySet()) { + statement.setLong(1, task.getNumber()); + statement.setDate(2, new java.sql.Date(taskTime.getKey().getTime())); + statement.setLong(3, taskTime.getValue()); + + statement.executeUpdate(); + } + } finally { + closeStatement(statement); + } + } + + public void deleteProject(TimerProject project) { + deleteTask(project); + } + + public void deleteTask(TimerTask task) { + PreparedStatement statement = null; + try { + statement = connection.prepareStatement("DELETE FROM " + + TABLE_TASK + " WHERE id = ?"); + statement.setLong(1, task.getNumber()); + statement.executeUpdate(); + } catch (SQLException ex) { + throw new StorageException("Can't delete project", ex); + } finally { + closeStatement(statement); + } + } + + public void setAnnotation(TimerTask task, Date date, String annotation) { + + } + + public void setTaskTime(TimerTask task, Date date, Long time) { + try { + saveTaskTimes(task); + } catch (SQLException ex) { + throw new StorageException("Can't set task time", ex); + } + } + +} \ No newline at end of file Property changes on: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/Storage.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/StorageException.java =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/StorageException.java (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/StorageException.java 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,15 @@ +package org.chorem.jtimer.storage; + +public class StorageException extends RuntimeException { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6544441950983775434L; + + public StorageException(String message, Throwable cause) { + super(message, cause); + } + + public StorageException(String message) { + super(message); + } +} \ No newline at end of file Property changes on: branches/ng-jtimer/jtimer-server/src/main/java/org/chorem/jtimer/storage/StorageException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/jtimer-server/src/main/webapp/web/index.html =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/web/index.html (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/web/index.html 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,103 @@ +<!doctype html> +<html ng-app="JTimerModule"> + <head> + <title>jTimer (browser)</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + + <!-- <link type="text/css" rel="stylesheet" href="styles/jtimer.css" /> + <link type="text/css" rel="stylesheet" href="//twitter.github.io/bootstrap/assets/css/bootstrap.css" /> + <script type="text/javascript" src="//code.jquery.com/jquery-2.0.3.min.js"></script> + <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script> + <script type="text/javascript" src="scripts/app.js"></script> + <script type="text/javascript" src="scripts/controllers.js"></script> --> + + <link type="text/css" rel="stylesheet" href="css/jtimer.css" /> + <script type="text/javascript" src="js/jtimer.js"></script> + <script type="text/javascript" src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.4.0.js"></script> + + <script type="text/ng-template" id="tree_item_renderer_name.html"> + <span class="badge" ng-class="{sync:'badge-success'}">T</span> {{project.name}} + </script> + + <script type="text/ng-template" id="tree_item_renderer_details.html"> + {{project.todayTime|time}} - {{project2.totalTime|time}} + </script> + </head> + + <body ng-controller="JTimerController"> + <div class="container-fluid"> + <div class="row-fluid"> + <div class="span8 names"> + <ul class="mainTree"> + <li class="title"> + <div>Name</div> + </li> + + <li class="task" ng-repeat="project in projects| orderBy: 'name'" ng-animate="'maintree'" + ng-include="'tree_item_renderer_name.html'"></li> + </ul> + </div> + + <div class="span2 details"> + <ul class="time today"> + <li class="title"> + <div>Total</div> + </li> + + <li class="task" ng-repeat="project in projects| orderBy: 'name'" ng-animate="'maintree'" + ng-animate="'filtering'" + ng-include="'tree_item_renderer_details.html'"></li> + </ul> + </div> + <div class="span2 details"> + <ul class="time total"> + <li class="title"> + <div>Total</div> + </li> + + <li class="task" ng-repeat="project in projects| orderBy: 'name'" ng-animate="'maintree'" + ng-animate="'filtering'" + ng-include="'tree_item_renderer_details.html'"></li> + </ul> + </div> + </div> + </div> + + <div ng-controller="NewProjectCtrl"> + <button class="btn" ng-click="open()">Nouveau projet</button> + <div modal="shouldBeOpen" close="close()" options="opts"> + <div class="modal-header"> + <h3>Nouveau projet</h3> + </div> + <div class="modal-body" ng-form="projectForm"> + <label> + Nouveau projet : <input type="text" ng-model="name" placeholder="Name" required /></label> + <label class="checkbox"> + <input type="checkbox" ng-model="sync" /> + Synchroniser le projet sur chorem</label> + </div> + <div class="modal-footer"> + <button class="btn" ng-click="cancel()">Annuler</button> + <button class="btn btn-primary" ng-click="valid()" ng-disabled="!projectForm.$valid">Valider</button> + </div> + </div> + </div> + + <div ng-controller="NewProjectCtrl"> + <button class="btn" ng-click="open()">Nouveau task</button> + <div modal="shouldBeOpen" close="close()" options="opts"> + <div class="modal-header"> + <h3>Nouvelle tâche</h3> + </div> + <div class="modal-body" ng-form="taskForm"> + <label> + Nouvelle tâche : <input type="text" ng-model="name" placeholder="Name"/></label> + </div> + <div class="modal-footer"> + <button class="btn" ng-click="cancel()">Annuler</button> + <button class="btn btn-primary" ng-click="valid()" ng-disabled="!taskForm.$valid">Valider</button> + </div> + </div> + </div> + </body> +</html> \ No newline at end of file Added: branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/app.js =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/app.js (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/app.js 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,25 @@ +var JTimerModule = angular.module('JTimerModule', ['ui.bootstrap']); + +function toHHMMSS(sec_num) { + //var sec_num = parseInt(this, 10); // don't forget the second parm + var hours = Math.floor(sec_num / 3600); + var minutes = Math.floor((sec_num - (hours * 3600)) / 60); + var seconds = sec_num - (hours * 3600) - (minutes * 60); + + if (hours < 10) {hours = "0"+hours;} + if (minutes < 10) {minutes = "0"+minutes;} + if (seconds < 10) {seconds = "0"+seconds;} + var time = hours+':'+minutes+':'+seconds; + return time; +} + +JTimerModule.filter('time', function() { + return function(input) { + /*var date = new Date(input); + return date.getUTCHours() + + ":" + date.getUTCMinutes() + + ":" + date.getUTCSeconds() + + "." + date.getUTCMilliseconds();*/ + return toHHMMSS(input); + }; +}); Added: branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/controllers.js =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/controllers.js (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/web/scripts/controllers.js 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,55 @@ +JTimerModule.controller('JTimerController', ['$scope', '$http', '$timeout', + function JTimerController($scope, $http, $timeout) { + $scope.projects; + + $http.post("http://localhost:8888/rest/projects"). + success(function(data, status, headers, config) { + $scope.projects = data; + }); + } +]); + +JTimerModule.controller('NewProjectCtrl', ['$scope', '$http', '$timeout', + function NewProjectCtrl($scope, $http, $timeout) { + $scope.open = function () { + $scope.shouldBeOpen = true; + }; + + $scope.cancel = function () { + $scope.shouldBeOpen = false; + }; + + $scope.valid = function () { + $scope.cancel(); + $scope.projects.push({name: $scope.name, sync: $scope.sync}); + }; + + $scope.items = ['item1', 'item2']; + + $scope.opts = { + backdropFade: true, + dialogFade:true + }; +}]); + +JTimerModule.controller('NewTaskCtrl', ['$scope', '$http', '$timeout', + function NewTaskCtrl($scope, $http, $timeout) { + $scope.open = function () { + $scope.shouldBeOpen = true; + }; + + $scope.cancel = function () { + $scope.shouldBeOpen = false; + }; + + $scope.valid = function () { + $scope.shouldBeOpen = false; + }; + + $scope.items = ['item1', 'item2']; + + $scope.opts = { + backdropFade: true, + dialogFade:true + }; + }]); Added: branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/jtimer.css =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/jtimer.css (rev 0) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/jtimer.css 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,42 @@ +ul.mainTree, ul.time { + list-style: none outside none; + +} + +ul.mainTree .title, ul.time .title { + font-weight: bold; + border-bottom:1px black dotted; +} + + + + + + + +/* Angular animations */ +.maintree-enter, +.maintree-leave +{ + -webkit-transition: 425ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -moz-transition: 425ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -ms-transition: 425ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + -o-transition: 425ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + transition: 425ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; + position: relative; + display: block; +} + +.maintree-enter.maintree-enter-active, +.maintree-leave { + opacity: 1; + top: 0; + height: 30px; +} + +.maintree-leave.maintree-leave-active, +.maintree-enter { + opacity: 0; + top: -50px; + height: 0px; +} Property changes on: branches/ng-jtimer/jtimer-server/src/main/webapp/web/styles/jtimer.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: branches/ng-jtimer/pom.xml =================================================================== --- branches/ng-jtimer/pom.xml (rev 0) +++ branches/ng-jtimer/pom.xml 2013-07-19 13:36:34 UTC (rev 2905) @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>mavenpom4redmine</artifactId> + <version>3.4.13</version> + </parent> + + <groupId>org.chorem</groupId> + <artifactId>jtimer</artifactId> + <version>2.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>jTimer</name> + <description>jTimer - Time tracking tool.</description> + <url>http://maven-site.chorem.org/jtimer</url> + <inceptionYear>2007</inceptionYear> + + <modules> + <module>jtimer-server</module> + <module>jtimer-client</module> + </modules> + + <licenses> + <license> + <name>General Public License (GPL)</name> + <url>http://www.gnu.org/licenses/gpl.html</url> + <distribution>repo</distribution> + </license> + </licenses> + + <properties> + <platform>chorem.org</platform> + <license.licenseName>gpl_v3</license.licenseName> + <javaVersion>1.7</javaVersion> + </properties> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>ro.isdc.wro4j</groupId> + <artifactId>wro4j-maven-plugin</artifactId> + <version>1.7.0</version> + <dependencies> + <dependency> + <groupId>org.nuiton.js</groupId> + <artifactId>nuiton-js-wro</artifactId> + <version>1.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.nuiton.js</groupId> + <artifactId>nuiton-js-angular</artifactId> + <version>1.1.5-1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.nuiton.js</groupId> + <artifactId>nuiton-js-jquery</artifactId> + <version>2.0.2-1</version> + </dependency> + <dependency> + <groupId>org.nuiton.js</groupId> + <artifactId>nuiton-js-bootstrap</artifactId> + <version>2.3.2-1</version> + </dependency> + <dependency> + <groupId>ro.isdc.wro4j</groupId> + <artifactId>wro4j-extensions</artifactId> + <version>1.7.0</version> + </dependency> + <dependency> + <groupId>com.google.javascript</groupId> + <artifactId>closure-compiler</artifactId> + <version>v20130603</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </pluginManagement> + </build> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>tjws</artifactId> + <version>1.104</version> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.3.172</version> + </dependency> + <dependency> + <groupId>com.nativelibs4java</groupId> + <artifactId>bridj</artifactId> + <classifier>c-only</classifier> + <version>0.6.2</version> + <exclusions> + <exclusion> + <artifactId>dx</artifactId> + <groupId>com.google.android.tools</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_3.0_spec</artifactId> + <version>1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.oracle</groupId> + <artifactId>javafx</artifactId> + <version>2.2.3</version> + <scope>system</scope> + <systemPath>${java.home}/lib/jfxrt.jar</systemPath> + </dependency> + </dependencies> + </dependencyManagement> +</project> Property changes on: branches/ng-jtimer/pom.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
echatellier@users.chorem.org