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

Added logging capabilities to StatefulWidget to log activity

parent b6c2841b
......@@ -7,6 +7,9 @@
<OnScreenLog name="SplashScreen" size="1000">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</OnScreenLog>
<TangibleLog name="Tangibles">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</TangibleLog>
</Appenders>
<Loggers>
......@@ -15,5 +18,9 @@
<AppenderRef ref="SplashScreen"/>
</Root>
<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>
</Configuration>
\ No newline at end of file
......@@ -38,7 +38,6 @@ import java.util.List;
*/
@Plugin(name = "OnScreenLog", category = "Core", elementType = "appender", printObject = true)
public final class OnScreenLogAppender extends AbstractAppender {
// private CircularFifoQueue<String> logBuffer;
private int capacity;
private int size;
private Layout<? extends Serializable> layout;
......@@ -57,7 +56,6 @@ public final class OnScreenLogAppender extends AbstractAppender {
this.capacity = size;
this.size = 0;
this.layout = layout;
// logBuffer = new CircularFifoQueue<>(size);
logListeners = new ArrayList<>();
}
......@@ -65,7 +63,6 @@ public final class OnScreenLogAppender extends AbstractAppender {
@Override
public void append(LogEvent event) {
String entry = new String(this.layout.toByteArray(event));
// logBuffer.add(entry);
this.size += (this.size < this.capacity) ? 1 : 0;
notifyLogListeners(entry);
}
......@@ -109,8 +106,8 @@ public final class OnScreenLogAppender extends AbstractAppender {
LOGGER.error("No name provided for OnScreenLogAppender"); //$NON-NLS-1$
return null;
}
Layout<? extends Serializable> _layout = (layout == null) ? PatternLayout.createDefaultLayout() : layout;
instances.put(name, new OnScreenLogAppender(name, filter, _layout, size));
Layout<? extends Serializable> loggerLayout = (layout == null) ? PatternLayout.createDefaultLayout() : layout;
instances.put(name, new OnScreenLogAppender(name, filter, loggerLayout, size));
return instances.get(name);
}
......
......@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
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.widget.builder.BaseStatefulBuilder;
import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
......@@ -41,7 +42,7 @@ import java.util.stream.Stream;
*
* @author Nico Mack [nico.mack@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @since 2.5
* @version 2.5.0
*/
// ***************************************************************************
......@@ -53,6 +54,10 @@ public class StatefulWidget extends BaseWidget {
/** The coalesced NuiState instances per handle. */
protected ConcurrentHashMap<Integer, StateManager> states;
// ***************************************************************************
// * Constants
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
......@@ -64,6 +69,8 @@ public class StatefulWidget extends BaseWidget {
* @param builder
* The builder instance defining all parameters.
*/
// ---------------------------------------------------------------------------
public StatefulWidget(BaseStatefulBuilder<?> builder) {
super(builder);
Preconditions.checkState(builder.states != null);
......@@ -89,6 +96,12 @@ public class StatefulWidget extends BaseWidget {
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
......@@ -122,7 +135,11 @@ public class StatefulWidget extends BaseWidget {
@Override
public void actionMove(TangibleObject tangibleObject) {
StateManager manager = states.get(tangibleObject.getObjectId());
boolean wasStill = manager.isStill();
boolean wasMoving = manager.isMoving() || manager.isRotating();
super.actionMove(tangibleObject);
Point position = getPosition(tangibleObject.getObjectId());
......@@ -135,6 +152,16 @@ public class StatefulWidget extends BaseWidget {
Stream<FadingCorona> autoFading = this.getCoronas(FadingCorona.class).stream().filter(corona -> corona.fadesWithHandle());
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 {
public void actionDrop(TangibleObject tangibleObject) {
super.actionDrop(tangibleObject);
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 {
@Override
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()));
super.actionLift(tangibleObject);
}
......
......@@ -70,10 +70,10 @@ public class StateManager {
protected Timer movementTimer = new Timer(Attenuator.getMovementCooldown(), new MovementTimerListener());
/** Flag raised by ActionListener of rotationTimer */
protected boolean rotationTimerExpired = false;
protected volatile boolean rotationTimerExpired = false;
/** Flag raised by ActionListener of movementTimer */
protected boolean movementTimerExpired = false;
protected volatile boolean movementTimerExpired = false;
/** The last position change managed by the {@link StateManager}. */
private Point lastPosition;
......@@ -82,12 +82,12 @@ public class StateManager {
* Field indicating whether the tangible the manager is attributed to was rotating. Once read
* 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 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
......@@ -158,6 +158,7 @@ public class StateManager {
// ---------------------------------------------------------------------------
private synchronized void updateStates(Transition transition) {
if (transition.getTo().isOfKind(MovementState.class)) {
handleMovement(transition);
return;
......@@ -169,6 +170,9 @@ public class StateManager {
}
if (transition.getFrom() != null) {
// wasMoving = transition.getFrom().isOfKind(MovementState.class);
// wasRotating = transition.getFrom().isOfKind(RotationState.class);
states.remove(transition.getFrom().getKey(), transition.getFrom());
}
states.put(transition.getTo().getKey(), transition.getTo());
......@@ -662,6 +666,18 @@ public class StateManager {
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
......
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