-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
285 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/************************************************************************** | ||
* RNGames, a software to record your inputs while playing. | ||
* Copyright (C) 2016 CORTIER Benoît, BOULMIER Jérôme | ||
* | ||
* 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/>. | ||
*************************************************************************/ | ||
|
||
package fr.utbm.rngames.screen; | ||
|
||
import fr.utbm.rngames.event.Event; | ||
|
||
public class ScreenEvent implements Event<ScreenEventListener> { | ||
private final double newWidth; | ||
|
||
private final double newHeight; | ||
|
||
public ScreenEvent(double newWidth, double newHeight) { | ||
this.newWidth = newWidth; | ||
this.newHeight = newHeight; | ||
} | ||
|
||
@Override | ||
public void notify(ScreenEventListener listener) { | ||
listener.handleScreenResizeEvent(newWidth, newHeight); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/fr/utbm/rngames/screen/ScreenEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/************************************************************************** | ||
* RNGames, a software to record your inputs while playing. | ||
* Copyright (C) 2016 CORTIER Benoît, BOULMIER Jérôme | ||
* | ||
* 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/>. | ||
*************************************************************************/ | ||
|
||
package fr.utbm.rngames.screen; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface ScreenEventListener extends EventListener { | ||
void handleScreenResizeEvent(double newWidth, double newHeight); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/************************************************************************** | ||
* RNGames, a software to record your inputs while playing. | ||
* Copyright (C) 2016 CORTIER Benoît, BOULMIER Jérôme | ||
* | ||
* 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/>. | ||
*************************************************************************/ | ||
|
||
package fr.utbm.rngames.screen; | ||
|
||
import fr.utbm.rngames.controller.CloseEvent; | ||
import fr.utbm.rngames.controller.CloseEventListener; | ||
import fr.utbm.rngames.event.EventDispatcher; | ||
import javafx.stage.Screen; | ||
|
||
import java.util.logging.Logger; | ||
|
||
public class ScreenMonitor implements CloseEventListener, Runnable { | ||
private static final Logger LOG = Logger.getLogger(ScreenMonitor.class.getName()); | ||
|
||
private boolean running; | ||
|
||
@Override | ||
public void run() { | ||
EventDispatcher.getInstance().addListener(CloseEvent.class, this); | ||
|
||
double lastWidth = 0; | ||
double lastHeight = 0; | ||
double newWidth; | ||
double newHeight; | ||
|
||
this.running = true; | ||
while (this.running) { | ||
Screen screen = Screen.getPrimary(); | ||
newWidth = screen.getBounds().getWidth(); | ||
newHeight = screen.getBounds().getHeight(); | ||
if (newWidth != lastWidth || newHeight != lastHeight) { | ||
EventDispatcher.getInstance().fire(new ScreenEvent(newWidth, newHeight)); | ||
lastWidth = newWidth; | ||
lastHeight = newHeight; | ||
} | ||
|
||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
LOG.severe(e.getMessage()); | ||
} | ||
} | ||
|
||
EventDispatcher.getInstance().removeListener(CloseEvent.class, this); | ||
} | ||
|
||
/** | ||
* Stop the screen monitor. | ||
*/ | ||
public void stop() { | ||
this.running = false; | ||
} | ||
|
||
public void handleCloseEvent() { | ||
this.running = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/************************************************************************** | ||
* RNGames, a software to record your inputs while playing. | ||
* Copyright (C) 2016 CORTIER Benoît, BOULMIER Jérôme | ||
* | ||
* 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/>. | ||
*************************************************************************/ | ||
|
||
package fr.utbm.rngames.screen; | ||
|
||
import fr.utbm.rngames.event.EventDispatcher; | ||
import fr.utbm.rngames.mouse.MouseWriter; | ||
import org.arakhne.afc.vmutil.locale.Locale; | ||
import org.jnativehook.GlobalScreen; | ||
import org.jnativehook.mouse.NativeMouseEvent; | ||
import org.jnativehook.mouse.NativeMouseWheelEvent; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.logging.Logger; | ||
|
||
public class ScreenWriter implements ScreenEventListener { | ||
private static final String CSV_SEPARATOR; | ||
|
||
static { | ||
CSV_SEPARATOR = Locale.getString("screen.csv.separator"); //$NON-NLS-1$ | ||
} | ||
|
||
private static final Logger LOG = Logger.getLogger(MouseWriter.class.getName()); | ||
|
||
private final long startTime; | ||
private final URL fileLocation; | ||
private final BufferedWriter writer; | ||
|
||
public ScreenWriter(URL fileLocation) throws IOException { | ||
this.startTime = System.currentTimeMillis(); | ||
this.fileLocation = fileLocation; | ||
File file = new File(getFileLocation().getPath()); | ||
|
||
if (file.createNewFile()) { | ||
file.deleteOnExit(); | ||
} | ||
|
||
this.writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), | ||
StandardCharsets.UTF_8)); | ||
|
||
this.writer.write(Locale.getString("screen.file.header")); | ||
this.writer.newLine(); | ||
} | ||
|
||
private void register() { | ||
EventDispatcher.getInstance().addListener(ScreenEvent.class, this); | ||
} | ||
|
||
private void unregister() { | ||
EventDispatcher.getInstance().removeListener(ScreenEvent.class, this); | ||
} | ||
|
||
public final void start() { | ||
register(); | ||
} | ||
|
||
public final void stop() { | ||
unregister(); | ||
close(); | ||
} | ||
|
||
public final URL getFileLocation() { | ||
return this.fileLocation; | ||
} | ||
|
||
@Override | ||
public void handleScreenResizeEvent(double newWidth, double newHeight) { | ||
try { | ||
this.writer.write(generateScreenResize(newWidth, newHeight, System.currentTimeMillis())); | ||
this.writer.newLine(); | ||
} catch (IOException exception) { | ||
LOG.severe(exception.getMessage()); | ||
} | ||
} | ||
|
||
private String generateScreenResize(double newWidth, double newHeight, long timestampMillis) { | ||
return Locale.getString("screen.event.resize") + CSV_SEPARATOR //$NON-NLS-1$ | ||
+ newWidth + CSV_SEPARATOR | ||
+ newHeight + CSV_SEPARATOR | ||
+ (timestampMillis - this.startTime); | ||
} | ||
|
||
private void close() { | ||
try { | ||
this.writer.close(); | ||
} catch (IOException exception) { | ||
LOG.severe(exception.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/resources/fr/utbm/rngames/screen/ScreenWriter.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
screen.file.header = Event;Width;Height;Time | ||
screen.csv.separator = ; | ||
screen.file.name = nrgamestmp.screen.csv | ||
screen.event.resize = screen resize |