From 621a5d32dfd5d9387fe8938c1bbf7ba90c171a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Wed, 30 Mar 2016 15:22:21 +0200 Subject: [PATCH 1/3] Updated loggers. --- .../utbm/rngames/keyboard/KeyboardWriter.java | 12 ++++++------ .../fr/utbm/rngames/mouse/MouseWriter.java | 18 +++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java b/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java index b946eff..9dc27e3 100644 --- a/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java +++ b/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java @@ -39,7 +39,7 @@ public class KeyboardWriter extends KeyboardListener { CSV_SEPARATOR = Locale.getString("keyboard.csv.separator"); //$NON-NLS-1$ } - private final Logger logger = Logger.getLogger(KeyboardWriter.class.getName()); + private static final Logger LOG = Logger.getLogger(KeyboardWriter.class.getName()); private final List keysPressed = new ArrayList<>(); private final long startTime; @@ -67,19 +67,19 @@ protected void close() { try { this.writer.close(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); + LOG.severe(exception.getMessage()); } } @Override public void nativeKeyPressed(NativeKeyEvent evt) { - if (!this.keysPressed.contains(evt.getKeyCode())) { - this.keysPressed.add(evt.getKeyCode()); + if (!this.keysPressed.contains(new Integer(evt.getKeyCode()))) { + this.keysPressed.add(new Integer(evt.getKeyCode())); try { this.writer.write(generateFileEntry("Key Down", evt)); //$NON-NLS-1$ this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); + LOG.severe(exception.getMessage()); } } } @@ -91,7 +91,7 @@ public void nativeKeyReleased(NativeKeyEvent evt) { this.writer.write(generateFileEntry("Key Up", evt)); //$NON-NLS-1$ this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); + LOG.severe(exception.getMessage()); } } diff --git a/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java b/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java index a6ea57b..aaa0f82 100644 --- a/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java +++ b/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java @@ -33,13 +33,13 @@ public class MouseWriter extends MouseListener { private static final String CSV_SEPARATOR; + private static final Logger LOG; static { CSV_SEPARATOR = Locale.getString("mouse.csv.separator"); //$NON-NLS-1$ + LOG = Logger.getLogger(MouseWriter.class.getName()); } - private final Logger logger = Logger.getLogger(MouseWriter.class.getName()); - private final long startTime; private final URL fileLocation; private final BufferedWriter writer; @@ -65,7 +65,7 @@ public void close() { try { this.writer.close(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); + LOG.severe(exception.getMessage()); } } @@ -80,8 +80,7 @@ public void nativeMousePressed(NativeMouseEvent evt) { this.writer.write(generateMouseButtonEntry(Locale.getString("mouse.event.pressed"), evt)); this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); - // System.exit(-1); + LOG.severe(exception.getMessage()); } } @@ -91,8 +90,7 @@ public void nativeMouseReleased(NativeMouseEvent evt) { this.writer.write(generateMouseButtonEntry(Locale.getString("mouse.event.released"), evt)); this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); - // System.exit(-1); + LOG.severe(exception.getMessage()); } } @@ -102,8 +100,7 @@ public void nativeMouseMoved(NativeMouseEvent evt) { this.writer.write(generateMouseMoveEntry(evt)); this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); - // System.exit(-1); + LOG.severe(exception.getMessage()); } } @@ -119,8 +116,7 @@ public void nativeMouseWheelMoved(NativeMouseWheelEvent evt) { this.writer.write(generateMouseButtonEntry(evt)); this.writer.newLine(); } catch (IOException exception) { - this.logger.severe(exception.getMessage()); - // System.exit(-1); + LOG.severe(exception.getMessage()); } } From 35c9a36d5220b2a742a14229ab909165d0f4f53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Wed, 30 Mar 2016 16:14:10 +0200 Subject: [PATCH 2/3] Externalized strings. --- .../utbm/rngames/keyboard/KeyboardWriter.java | 14 +++++++--- .../fr/utbm/rngames/mouse/MouseWriter.java | 27 +++++++++++++------ .../keyboard/KeyboardWriter.properties | 3 +++ .../utbm/rngames/mouse/MouseWriter.properties | 3 +++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java b/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java index 9dc27e3..de68fa8 100644 --- a/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java +++ b/src/main/java/fr/utbm/rngames/keyboard/KeyboardWriter.java @@ -33,13 +33,21 @@ import java.util.logging.Logger; public class KeyboardWriter extends KeyboardListener { + private static final Logger LOG; + private static final String CSV_SEPARATOR; + private static final String EVENT_NAME; + private static final String PRESSED_EVENT; + private static final String RELEASED_EVENT; static { CSV_SEPARATOR = Locale.getString("keyboard.csv.separator"); //$NON-NLS-1$ + LOG = Logger.getLogger(KeyboardWriter.class.getName()); + EVENT_NAME = Locale.getString("keyboard.event.name"); //$NON-NLS-1$ + PRESSED_EVENT = Locale.getString("keyboard.event.pressed"); //$NON-NLS-1$ + RELEASED_EVENT = Locale.getString("keyboard.event.released"); //$NON-NLS-1$ } - private static final Logger LOG = Logger.getLogger(KeyboardWriter.class.getName()); private final List keysPressed = new ArrayList<>(); private final long startTime; @@ -76,7 +84,7 @@ public void nativeKeyPressed(NativeKeyEvent evt) { if (!this.keysPressed.contains(new Integer(evt.getKeyCode()))) { this.keysPressed.add(new Integer(evt.getKeyCode())); try { - this.writer.write(generateFileEntry("Key Down", evt)); //$NON-NLS-1$ + this.writer.write(generateFileEntry(EVENT_NAME + " " + PRESSED_EVENT, evt)); //$NON-NLS-1$ this.writer.newLine(); } catch (IOException exception) { LOG.severe(exception.getMessage()); @@ -88,7 +96,7 @@ public void nativeKeyPressed(NativeKeyEvent evt) { public void nativeKeyReleased(NativeKeyEvent evt) { this.keysPressed.remove(new Integer(evt.getKeyCode())); try { - this.writer.write(generateFileEntry("Key Up", evt)); //$NON-NLS-1$ + this.writer.write(generateFileEntry(EVENT_NAME + " " + RELEASED_EVENT, evt)); //$NON-NLS-1$ this.writer.newLine(); } catch (IOException exception) { LOG.severe(exception.getMessage()); diff --git a/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java b/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java index aaa0f82..6e3dcc5 100644 --- a/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java +++ b/src/main/java/fr/utbm/rngames/mouse/MouseWriter.java @@ -32,12 +32,23 @@ import java.util.logging.Logger; public class MouseWriter extends MouseListener { - private static final String CSV_SEPARATOR; private static final Logger LOG; + private static final String CSV_SEPARATOR; + private static final String EVENT_NAME; + private static final String PRESSED_EVENT; + private static final String RELEASED_EVENT; + private static final String SCROLLED_EVENT; + private static final String MOVED_EVENT; + static { CSV_SEPARATOR = Locale.getString("mouse.csv.separator"); //$NON-NLS-1$ LOG = Logger.getLogger(MouseWriter.class.getName()); + EVENT_NAME = Locale.getString("mouse.event.name"); //$NON-NLS-1$ + PRESSED_EVENT = Locale.getString("mouse.event.pressed"); //$NON-NLS-1$ + RELEASED_EVENT = Locale.getString("mouse.event.released"); //$NON-NLS-1$ + SCROLLED_EVENT = Locale.getString("mouse.event.scrolled"); //$NON-NLS-1$ + MOVED_EVENT = Locale.getString("mouse.event.moved"); //$NON-NLS-1$ } private final long startTime; @@ -56,7 +67,7 @@ public MouseWriter(URL fileLocation) throws IOException { this.writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); - this.writer.write(Locale.getString("mouse.file.header")); + this.writer.write(Locale.getString("mouse.file.header")); //$NON-NLS-1$ this.writer.newLine(); } @@ -77,7 +88,7 @@ public void nativeMouseClicked(NativeMouseEvent evt) { @Override public void nativeMousePressed(NativeMouseEvent evt) { try { - this.writer.write(generateMouseButtonEntry(Locale.getString("mouse.event.pressed"), evt)); + this.writer.write(generateMouseButtonEntry(PRESSED_EVENT, evt)); this.writer.newLine(); } catch (IOException exception) { LOG.severe(exception.getMessage()); @@ -87,7 +98,7 @@ public void nativeMousePressed(NativeMouseEvent evt) { @Override public void nativeMouseReleased(NativeMouseEvent evt) { try { - this.writer.write(generateMouseButtonEntry(Locale.getString("mouse.event.released"), evt)); + this.writer.write(generateMouseButtonEntry(RELEASED_EVENT, evt)); this.writer.newLine(); } catch (IOException exception) { LOG.severe(exception.getMessage()); @@ -125,7 +136,7 @@ public final URL getFileLocation() { } private String generateMouseButtonEntry(String eventType, NativeMouseEvent evt) { - return "mouse " + evt.getButton() + " " + eventType + CSV_SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + return EVENT_NAME + " " + evt.getButton() + " " + eventType + CSV_SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + evt.getX() + CSV_SEPARATOR + evt.getY() + CSV_SEPARATOR + (evt.getWhen() - this.startTime); @@ -133,20 +144,20 @@ private String generateMouseButtonEntry(String eventType, NativeMouseEvent evt) private String generateMouseButtonEntry(NativeMouseWheelEvent evt) { if (evt.getWheelRotation() > 0) { - return "mouse scroll down" + CSV_SEPARATOR //$NON-NLS-1$ + return EVENT_NAME + " " + SCROLLED_EVENT + " " + PRESSED_EVENT + CSV_SEPARATOR //$NON-NLS-1$ + evt.getX() + CSV_SEPARATOR + evt.getY() + CSV_SEPARATOR + (evt.getWhen() - this.startTime); } - return "mouse scroll up" + CSV_SEPARATOR //$NON-NLS-1$ + return EVENT_NAME + " " + SCROLLED_EVENT + " " + RELEASED_EVENT + CSV_SEPARATOR //$NON-NLS-1$ + evt.getX() + CSV_SEPARATOR + evt.getY() + CSV_SEPARATOR + (evt.getWhen() - this.startTime); } private String generateMouseMoveEntry(NativeMouseEvent evt) { - return "mouse move" + CSV_SEPARATOR //$NON-NLS-1$ + return EVENT_NAME + " " + MOVED_EVENT + CSV_SEPARATOR //$NON-NLS-1$ + evt.getX() + CSV_SEPARATOR + evt.getY() + CSV_SEPARATOR + (evt.getWhen() - this.startTime); diff --git a/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties b/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties index 87fd231..8a55290 100644 --- a/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties +++ b/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties @@ -1,3 +1,6 @@ keyboard.file.header = Event;Key;Time keyboard.csv.separator = ; keyboard.file.name = rngamestmp.keyboard.csv +keyboard.event.name=Key +keyboard.event.pressed=Down +keyboard.event.released=Up diff --git a/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties b/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties index 3747729..2291dd9 100644 --- a/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties +++ b/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties @@ -1,5 +1,8 @@ mouse.file.header = Event;X;Y;Time mouse.csv.separator = ; mouse.file.name = nrgamestmp.mouse.csv +mouse.event.name=mouse mouse.event.pressed=down mouse.event.released=up +mouse.event.scrolled=scroll +mouse.event.moved=move \ No newline at end of file From f69e62bbc51b0f1c027e1598ad71c6bc55e99ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Wed, 30 Mar 2016 16:17:29 +0200 Subject: [PATCH 3/3] Clean-up properties. --- .../fr/utbm/rngames/keyboard/KeyboardWriter.properties | 6 +++--- .../fr/utbm/rngames/mouse/MouseWriter.properties | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties b/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties index 8a55290..5c9f7cc 100644 --- a/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties +++ b/src/main/resources/fr/utbm/rngames/keyboard/KeyboardWriter.properties @@ -1,6 +1,6 @@ keyboard.file.header = Event;Key;Time keyboard.csv.separator = ; keyboard.file.name = rngamestmp.keyboard.csv -keyboard.event.name=Key -keyboard.event.pressed=Down -keyboard.event.released=Up +keyboard.event.name = Key +keyboard.event.pressed = Down +keyboard.event.released = Up diff --git a/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties b/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties index 2291dd9..3eb98c4 100644 --- a/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties +++ b/src/main/resources/fr/utbm/rngames/mouse/MouseWriter.properties @@ -1,8 +1,8 @@ mouse.file.header = Event;X;Y;Time mouse.csv.separator = ; mouse.file.name = nrgamestmp.mouse.csv -mouse.event.name=mouse -mouse.event.pressed=down -mouse.event.released=up -mouse.event.scrolled=scroll -mouse.event.moved=move \ No newline at end of file +mouse.event.name = mouse +mouse.event.pressed = down +mouse.event.released = up +mouse.event.scrolled = scroll +mouse.event.moved = move \ No newline at end of file