Commit 57b3321b authored by Nico Mack's avatar Nico Mack

Added logging capabilities to StatefulWidget to log activity

parent b6c2841b
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
<OnScreenLog name="SplashScreen" size="1000"> <OnScreenLog name="SplashScreen" size="1000">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</OnScreenLog> </OnScreenLog>
<TangibleLog name="Tangibles">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</TangibleLog>
</Appenders> </Appenders>
<Loggers> <Loggers>
...@@ -15,5 +18,9 @@ ...@@ -15,5 +18,9 @@
<AppenderRef ref="SplashScreen"/> <AppenderRef ref="SplashScreen"/>
</Root> </Root>
<Logger name="lu.list.itis.dkd.tui" level="info"/> <Logger name="lu.list.itis.dkd.tui" level="info"/>
<Logger name="lu.list.itis.dkd.tui.widget.StatefulWidget" level="info">
<AppenderRef ref="Tangibles"/>
</Logger>
</Loggers> </Loggers>
</Configuration> </Configuration>
\ No newline at end of file
...@@ -38,7 +38,6 @@ import java.util.List; ...@@ -38,7 +38,6 @@ import java.util.List;
*/ */
@Plugin(name = "OnScreenLog", category = "Core", elementType = "appender", printObject = true) @Plugin(name = "OnScreenLog", category = "Core", elementType = "appender", printObject = true)
public final class OnScreenLogAppender extends AbstractAppender { public final class OnScreenLogAppender extends AbstractAppender {
// private CircularFifoQueue<String> logBuffer;
private int capacity; private int capacity;
private int size; private int size;
private Layout<? extends Serializable> layout; private Layout<? extends Serializable> layout;
...@@ -57,7 +56,6 @@ public final class OnScreenLogAppender extends AbstractAppender { ...@@ -57,7 +56,6 @@ public final class OnScreenLogAppender extends AbstractAppender {
this.capacity = size; this.capacity = size;
this.size = 0; this.size = 0;
this.layout = layout; this.layout = layout;
// logBuffer = new CircularFifoQueue<>(size);
logListeners = new ArrayList<>(); logListeners = new ArrayList<>();
} }
...@@ -65,7 +63,6 @@ public final class OnScreenLogAppender extends AbstractAppender { ...@@ -65,7 +63,6 @@ public final class OnScreenLogAppender extends AbstractAppender {
@Override @Override
public void append(LogEvent event) { public void append(LogEvent event) {
String entry = new String(this.layout.toByteArray(event)); String entry = new String(this.layout.toByteArray(event));
// logBuffer.add(entry);
this.size += (this.size < this.capacity) ? 1 : 0; this.size += (this.size < this.capacity) ? 1 : 0;
notifyLogListeners(entry); notifyLogListeners(entry);
} }
...@@ -109,8 +106,8 @@ public final class OnScreenLogAppender extends AbstractAppender { ...@@ -109,8 +106,8 @@ public final class OnScreenLogAppender extends AbstractAppender {
LOGGER.error("No name provided for OnScreenLogAppender"); //$NON-NLS-1$ LOGGER.error("No name provided for OnScreenLogAppender"); //$NON-NLS-1$
return null; return null;
} }
Layout<? extends Serializable> _layout = (layout == null) ? PatternLayout.createDefaultLayout() : layout; Layout<? extends Serializable> loggerLayout = (layout == null) ? PatternLayout.createDefaultLayout() : layout;
instances.put(name, new OnScreenLogAppender(name, filter, _layout, size)); instances.put(name, new OnScreenLogAppender(name, filter, loggerLayout, size));
return instances.get(name); return instances.get(name);
} }
......
...@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.widget; ...@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.adapter.TangibleObject; import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.logging.TangibleLogger;
import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BaseStatefulBuilder; import lu.list.itis.dkd.tui.widget.builder.BaseStatefulBuilder;
import lu.list.itis.dkd.tui.widget.corona.FadingCorona; import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
...@@ -41,7 +42,7 @@ import java.util.stream.Stream; ...@@ -41,7 +42,7 @@ import java.util.stream.Stream;
* *
* @author Nico Mack [nico.mack@list.lu] * @author Nico Mack [nico.mack@list.lu]
* @author Eric Tobias [eric.tobias@list.lu] * @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0 * @since 2.5
* @version 2.5.0 * @version 2.5.0
*/ */
// *************************************************************************** // ***************************************************************************
...@@ -53,6 +54,10 @@ public class StatefulWidget extends BaseWidget { ...@@ -53,6 +54,10 @@ public class StatefulWidget extends BaseWidget {
/** The coalesced NuiState instances per handle. */ /** The coalesced NuiState instances per handle. */
protected ConcurrentHashMap<Integer, StateManager> states; protected ConcurrentHashMap<Integer, StateManager> states;
// ***************************************************************************
// * Constants
// ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Constructor(s) // * Constructor(s)
...@@ -64,6 +69,8 @@ public class StatefulWidget extends BaseWidget { ...@@ -64,6 +69,8 @@ public class StatefulWidget extends BaseWidget {
* @param builder * @param builder
* The builder instance defining all parameters. * The builder instance defining all parameters.
*/ */
// ---------------------------------------------------------------------------
public StatefulWidget(BaseStatefulBuilder<?> builder) { public StatefulWidget(BaseStatefulBuilder<?> builder) {
super(builder); super(builder);
Preconditions.checkState(builder.states != null); Preconditions.checkState(builder.states != null);
...@@ -89,6 +96,12 @@ public class StatefulWidget extends BaseWidget { ...@@ -89,6 +96,12 @@ public class StatefulWidget extends BaseWidget {
} }
} }
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives
// ***************************************************************************
// ---------------------------------------------------------------------------
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body // * Class Body
...@@ -122,7 +135,11 @@ public class StatefulWidget extends BaseWidget { ...@@ -122,7 +135,11 @@ public class StatefulWidget extends BaseWidget {
@Override @Override
public void actionMove(TangibleObject tangibleObject) { public void actionMove(TangibleObject tangibleObject) {
StateManager manager = states.get(tangibleObject.getObjectId()); StateManager manager = states.get(tangibleObject.getObjectId());
boolean wasStill = manager.isStill();
boolean wasMoving = manager.isMoving() || manager.isRotating();
super.actionMove(tangibleObject); super.actionMove(tangibleObject);
Point position = getPosition(tangibleObject.getObjectId()); Point position = getPosition(tangibleObject.getObjectId());
...@@ -135,6 +152,16 @@ public class StatefulWidget extends BaseWidget { ...@@ -135,6 +152,16 @@ public class StatefulWidget extends BaseWidget {
Stream<FadingCorona> autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle()); Stream<FadingCorona> autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle());
autoFading.forEach(corona -> corona.fadeIn()); autoFading.forEach(corona -> corona.fadeIn());
} }
if (wasStill) {
if (manager.isMoving()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.TRANSLATED);
} else if (manager.isRotating()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.ROTATED);
}
} else if (wasMoving && manager.isStill()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.STOPPED);
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -152,6 +179,7 @@ public class StatefulWidget extends BaseWidget { ...@@ -152,6 +179,7 @@ public class StatefulWidget extends BaseWidget {
public void actionDrop(TangibleObject tangibleObject) { public void actionDrop(TangibleObject tangibleObject) {
super.actionDrop(tangibleObject); super.actionDrop(tangibleObject);
states.get(tangibleObject.getObjectId()).drop(new Point(tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle())); states.get(tangibleObject.getObjectId()).drop(new Point(tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle()));
TangibleLogger.logWidget(tangibleObject.getObjectId(), getPosition(tangibleObject.getObjectId()), TangibleLogger.DROPPED);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -167,6 +195,7 @@ public class StatefulWidget extends BaseWidget { ...@@ -167,6 +195,7 @@ public class StatefulWidget extends BaseWidget {
@Override @Override
public void actionLift(TangibleObject tangibleObject) { public void actionLift(TangibleObject tangibleObject) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), getPosition(tangibleObject.getObjectId()), TangibleLogger.LIFTED);
states.get(tangibleObject.getObjectId()).lift(new Point(tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle())); states.get(tangibleObject.getObjectId()).lift(new Point(tangibleObject.getX(), tangibleObject.getY(), tangibleObject.getAngle()));
super.actionLift(tangibleObject); super.actionLift(tangibleObject);
} }
......
...@@ -70,10 +70,10 @@ public class StateManager { ...@@ -70,10 +70,10 @@ public class StateManager {
protected Timer movementTimer = new Timer(Attenuator.getMovementCooldown(), new MovementTimerListener()); protected Timer movementTimer = new Timer(Attenuator.getMovementCooldown(), new MovementTimerListener());
/** Flag raised by ActionListener of rotationTimer */ /** Flag raised by ActionListener of rotationTimer */
protected boolean rotationTimerExpired = false; protected volatile boolean rotationTimerExpired = false;
/** Flag raised by ActionListener of movementTimer */ /** Flag raised by ActionListener of movementTimer */
protected boolean movementTimerExpired = false; protected volatile boolean movementTimerExpired = false;
/** The last position change managed by the {@link StateManager}. */ /** The last position change managed by the {@link StateManager}. */
private Point lastPosition; private Point lastPosition;
...@@ -82,12 +82,12 @@ public class StateManager { ...@@ -82,12 +82,12 @@ public class StateManager {
* Field indicating whether the tangible the manager is attributed to was rotating. Once read * Field indicating whether the tangible the manager is attributed to was rotating. Once read
* the field toggles to false; * the field toggles to false;
*/ */
protected boolean wasRotating = false; protected volatile boolean wasRotating = false;
/** /**
* Field indicating whether the tangible the manager is attributed to was moving. Once read the * Field indicating whether the tangible the manager is attributed to was moving. Once read the
* field toggles to false; * field toggles to false;
*/ */
protected boolean wasMoving = false; protected volatile boolean wasMoving = false;
/** /**
* Field indicating whether lifting of widget should entail logically removing the widget or * Field indicating whether lifting of widget should entail logically removing the widget or
...@@ -158,6 +158,7 @@ public class StateManager { ...@@ -158,6 +158,7 @@ public class StateManager {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private synchronized void updateStates(Transition transition) { private synchronized void updateStates(Transition transition) {
if (transition.getTo().isOfKind(MovementState.class)) { if (transition.getTo().isOfKind(MovementState.class)) {
handleMovement(transition); handleMovement(transition);
return; return;
...@@ -169,6 +170,9 @@ public class StateManager { ...@@ -169,6 +170,9 @@ public class StateManager {
} }
if (transition.getFrom() != null) { if (transition.getFrom() != null) {
// wasMoving = transition.getFrom().isOfKind(MovementState.class);
// wasRotating = transition.getFrom().isOfKind(RotationState.class);
states.remove(transition.getFrom().getKey(), transition.getFrom()); states.remove(transition.getFrom().getKey(), transition.getFrom());
} }
states.put(transition.getTo().getKey(), transition.getTo()); states.put(transition.getTo().getKey(), transition.getTo());
...@@ -662,6 +666,18 @@ public class StateManager { ...@@ -662,6 +666,18 @@ public class StateManager {
return this.isPersistent; return this.isPersistent;
} }
// ---------------------------------------------------------------------------
/**
* Simple getter method to check whether previous state was still or not.
*
* @return <code>True</code> if previous state was still, <code>false</code> otherwise
*/
// ---------------------------------------------------------------------------
public boolean wasStill() {
return (!wasRotating && !wasMoving);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** /**
* Simple getter method for wasRotating. This call will cause the field to toggle to false if it * Simple getter method for wasRotating. This call will cause the field to toggle to false if it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment