Commit b2a0da11 authored by Nico Mack's avatar Nico Mack

Fixed ConcurrentModificationException in StateManager. Fixed Layout

issue in Splashscreen
parent 610af114
......@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Image;
import java.awt.image.BufferedImage;
......@@ -80,6 +81,7 @@ public class SplashScreen extends JPanel implements LogListener {
logo = this.getImage(TangibleApplication.class, LOGO_PATH);
this.setLayout(new FormLayout(COLUMN_SPECS, ROW_SPECS));
this.setBackground(Color.BLACK);
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
CellConstraints constraints = new CellConstraints();
......
......@@ -23,8 +23,12 @@ package lu.list.itis.dkd.tui.widget.state;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.utility.Calibration;
import lu.list.itis.dkd.tui.utility.CameraCoordinates;
import lu.list.itis.dkd.tui.utility.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class used to compensate jitter before transitioning to another widget state. The class also
* features a timer to be used to set attenuation timers for blocking state transitions before a
......@@ -38,8 +42,12 @@ import lu.list.itis.dkd.tui.utility.Point;
public class Attenuator {
private static final float ROTATION_THRESHOLD = Calibration.getRotationThreshold(); // 0.1f
private static final float MOVEMENT_THRESHOLD = Calibration.getMovementThreshold(); // 0.01f;
private static final int MOVEMENT_COOLDOWN = 500;
private static final int ROTATION_COOLDOWN = 500;
private static final int MOVEMENT_COOLDOWN = 1000;
private static final int ROTATION_COOLDOWN = 1000;
private static final double TWO_PI = 2 * Math.PI;
private static final Logger LOGGER = LoggerFactory.getLogger(Attenuator.class.getSimpleName());
/**
* Simple getter method for movementCooldown.
......@@ -97,8 +105,12 @@ public class Attenuator {
if (base == null)
return allowRotation;
float delta = (float) (Math.abs(base.getAngle() - current.getAngle()) % (2 * Math.PI));
allowRotation = Float.compare((float) (delta > Math.PI ? 2 * Math.PI - delta : delta), ROTATION_THRESHOLD) >= 0;
float delta = (float) (Math.abs(base.getAngle() - current.getAngle()) % TWO_PI);
allowRotation = Float.compare((float) (delta > Math.PI ? TWO_PI - delta : delta), ROTATION_THRESHOLD) >= 0;
// if (LOGGER.isTraceEnabled())
// LOGGER.trace("Delta {} >= Threshold {} ? [{}]", delta, ROTATION_THRESHOLD,
// allowRotation); //$NON-NLS-1$
return allowRotation;
}
......@@ -117,15 +129,19 @@ public class Attenuator {
*/
public static boolean allowMovement(@Nullable Point base, Point current) {
boolean allowMovement = true;
if (base == null)
if ((base == null) || (current == null))
return allowMovement;
Point _base = base.clone();
Point _current = current.clone();
double distance = _base.toCameraCoordinates().distance(_current.toCameraCoordinates());
Point _base = base.clone().toCoordinates(CameraCoordinates.class);
Point _current = current.clone().toCoordinates(CameraCoordinates.class);
double distance = _base.distance(_current);
allowMovement = Double.compare(distance, MOVEMENT_THRESHOLD) >= 0;
// if (LOGGER.isTraceEnabled())
// LOGGER.trace("Distance {} >= Threshold {} ? [{}]", distance, ROTATION_THRESHOLD,
// allowMovement); //$NON-NLS-1$
return allowMovement;
// return Double.compare(base.getDistance(current), MOVEMENT_THRESHOLD) >= 0;
}
}
\ No newline at end of file
......@@ -88,7 +88,7 @@ public class MovementState extends NuiState {
/**
* This is a possible rotation as this state has no notion of any existing rotation states.
*/
return new Transition(null, new RotationState(position));
return new Transition(this, new RotationState(position));
}
/**
......
......@@ -74,7 +74,7 @@ public class RotationState extends NuiState {
@Override
public Transition move(@NonNull Point position) {
/** This is a possible movement as this state has no means to check for the threshold. */
return new Transition(null, new MovementState(position));
return new Transition(this, new MovementState(position));
}
/**
......
......@@ -68,4 +68,15 @@ public class Transition extends java.util.AbstractMap.SimpleEntry<NuiState, NuiS
assert result != null;
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder("Transition : ["); //$NON-NLS-1$
NuiState from = getFrom();
NuiState to = getTo();
builder.append((from != null) ? from.toString() : "null").append("] => ["); //$NON-NLS-1$ //$NON-NLS-2$
builder.append((to != null) ? to.toString() : "null").append("]"); //$NON-NLS-1$ //$NON-NLS-2$
return builder.toString();
}
}
\ No newline at end of file
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