Commit 1aff8bec authored by Nico Mack's avatar Nico Mack

Addition of Animated Coronas

Streamlining (and homogenization) of corona painting
parent df3d0734
......@@ -50,6 +50,7 @@ NETWORK_ADAPTER_NODE=networkAdapter
OBJECT_NODE=object
OBJECTS_NODE=objects
RADIUS_NODE=radius
ACTIVATE_WITH_HANDLE_NODE=activateWithHandle
ROTATE_WITH_HANDLE_NODE=rotateWithHandle
ROTATION_DIRECTION_NODE=rotationDirection
SCALE_NODE=scale
......@@ -128,6 +129,7 @@ CORNER_RADIUS_NODE=cornerRadius
CIRCLE_SIZE_NODE=circleSize
SQUARE_SIZE_NODE=squareSize
TRIANGLE_SIZE_NODE=triangleSize
OPACITY_NODE=opacity
LABEL_SHAPE_NODE=labelShape
NAME_ATTRIBUTE=name
REPEAT_ATTRIBUTE=repeat
......@@ -137,6 +139,16 @@ SHADE_ATTRIBUTE=shade
SHADE_DARKER_VALUE=darker
SHADE_BRIGHTER_VALUE=brighter
MAGNIFIER_SHAPE_NODE=magnifierShape
MAGNIFICATION_NODE=magnification
ANIMATED_PROPERTIES_ELEMENT=animatedProperties
ANIMATED_PROPERTY_ELEMENT=animatedProperty
PROPERTY_NODE=property
LOOPING_NODE=looping
REVERSING_NODE=reversing
DURATION_NODE=duration
DELAY_NODE=delay
MARKER_NODE=marker
MARKERS_NODE=markers
MARKER_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.marker.builder
......
......@@ -86,6 +86,7 @@ public class Externalization extends NLS {
public static String OBJECT_NODE;
public static String OBJECTS_NODE;
public static String RADIUS_NODE;
public static String ACTIVATE_WITH_HANDLE_NODE;
public static String ROTATE_WITH_HANDLE_NODE;
public static String ROTATION_DIRECTION_NODE;
public static String SCALE_NODE;
......@@ -177,6 +178,19 @@ public class Externalization extends NLS {
public static String CIRCLE_SIZE_NODE;
public static String SQUARE_SIZE_NODE;
public static String TRIANGLE_SIZE_NODE;
public static String OPACITY_NODE;
public static String MAGNIFIER_SHAPE_NODE;
public static String MAGNIFICATION_NODE;
public static String ANIMATED_PROPERTIES_ELEMENT;
public static String ANIMATED_PROPERTY_ELEMENT;
public static String PROPERTY_NODE;
public static String DURATION_NODE;
public static String DELAY_NODE;
public static String LOOPING_NODE;
public static String REVERSING_NODE;
public static String MARKER_NODE;
public static String MARKERS_NODE;
......
......@@ -65,7 +65,7 @@ public class StatefulWidget extends BaseWidget {
* Allows checking wether this stateful widget is persistent or not. Persistent widgets remain
* logically active even though they are physically removed (lifted) from the table
*
* @param tangibleObject
* @param objectId
* specifies the object to check the persistence state of
* @return <code>true</code> if specified object is persistent, <code>false</code> if not.
*/
......
......@@ -30,8 +30,6 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BaseZoomBuilder;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -169,25 +167,39 @@ public class ZoomWidget extends StatefulWidget implements TimerEventListener {
/** {@inheritDoc} */
@Override
public void stoppedMoving(TimerEvent event) {/**
* The widget recentres synchronously, no need to
* do anything here!
*/
public void stoppedMoving(TimerEvent event) {
// Preconditions.checkState(((StateManager) event.getSource()).getLastMovement() != null,
// "The last movement may not be null!"); //$NON-NLS-1$
for (Zoomable resource : resources.values()) {
resource.stoppedMoving();
}
if (logger.isTraceEnabled()) {
logger.trace("Stopped moving! Displacement: {}", ((StateManager) event.getSource()).getLastMovement()); //$NON-NLS-1$
}
}
/** {@inheritDoc} */
@Override
public void stoppedRotating(TimerEvent event) {
Preconditions.checkState(((StateManager) event.getSource()).getLastRotation() != null, "The provided rotation may not be null!"); //$NON-NLS-1$
// Preconditions.checkState(((StateManager) event.getSource()).getLastRotation() != null,
// "The last rotation may not be null!"); //$NON-NLS-1$
for (Zoomable resource : resources.values()) {
resource.stoppedZooming();
}
logger.trace("Stopped rotating! Zooming: {} | Direction: {}", ((StateManager) event.getSource()).getLastRotation().getAngle(), (((StateManager) event.getSource()).getLastRotation().getRotationDirection() < 0 ? " Right" : " Left")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (logger.isTraceEnabled()) {
Point lastRotation = ((StateManager) event.getSource()).getLastRotation();
if (lastRotation != null) {
logger.trace("Stopped rotating! Angle: {} | Direction: {}", lastRotation.getAngle(), (lastRotation.getRotationDirection() < 0 ? " Right" : " Left")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
logger.trace("Stopped rotating!"); //$NON-NLS-1$
}
}
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.animation;
import java.util.List;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Interface Definition and Members *
// ***************************************************************************
public interface Animated {
/**
*
*/
public void resetAnimatedProperties();
/**
* @return
*/
public List<AnimationProperty<?>> getAnimationProperties();
/**
*
*/
public void start();
/**
*
*/
public void stop();
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.animation;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AnimationEvent {
private AnimationProperty<?> origin;
private AnimationState state;
private int keyFrame;
// ***************************************************************************
// * Constants *
// ***************************************************************************
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public enum AnimationState {
/** The property animation has been started */
STARTED,
/** The (looping) property animation is currently playing in forward direction */
PLAYING_FORWARD,
/** The property animation is currently has reached the designated keyframe */
KEYFRAME,
/** The (looping) property animation is currently playing in reverse direction */
PLAYING_REVERSE,
/** The property animation has been stopped explicitly */
STOPPED,
/** The (non-looping) property animation has reached its end */
DONE
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param origin
* @param state
*/
// ---------------------------------------------------------------------------
public AnimationEvent(AnimationProperty<?> origin, AnimationState state) {
this.origin = origin;
this.state = state;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public AnimationProperty<?> getOrigin() {
return origin;
}
// ---------------------------------------------------------------------------
/**
* @param origin
*/
// ---------------------------------------------------------------------------
public void setOrigin(AnimationProperty<?> origin) {
this.origin = origin;
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public AnimationState getState() {
return state;
}
// ---------------------------------------------------------------------------
/**
* @param state
*/
// ---------------------------------------------------------------------------
public void setState(AnimationState state) {
this.state = state;
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public int getKeyFrame() {
return keyFrame;
}
// ---------------------------------------------------------------------------
/**
* @param keyFrame
*/
// ---------------------------------------------------------------------------
public void setKeyFrame(int keyFrame) {
this.keyFrame = keyFrame;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.animation;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class AnimationEventSource {
private ArrayList<AnimationListener> listeners;
private Multimap<Integer, AnimationListener> keyframes;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
public AnimationEventSource() {
listeners = new ArrayList<>();
keyframes = TreeMultimap.create();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
public List<Integer> getKeyFrames() {
return new ArrayList<>(keyframes.keySet());
}
// ---------------------------------------------------------------------------
/**
* @param listener
* @param keyFrame
*/
public void addAnimationListenerAtKeyFrame(AnimationListener listener, int keyFrame) {
listeners.add(listener);
keyframes.put(keyFrame, listener);
}
// ---------------------------------------------------------------------------
/**
* @param listener
*/
public void addAnimationListener(AnimationListener listener) {
listeners.add(listener);
}
// ---------------------------------------------------------------------------
/**
* @param listener
*/
public void removeAnimationListener(AnimationListener listener) {
listeners.remove(listener);
}
// ---------------------------------------------------------------------------
/**
* @param event
*/
public void notifyAnimationListener(AnimationEvent event) {
for (AnimationListener listener : listeners) {
listener.animationStateChanged(event);
}
}
// ---------------------------------------------------------------------------
/**
* @param event
*/
public void notifyAnimationListener(AnimationEvent event, int keyFrame) {
Collection<AnimationListener> keyFrameListeners = keyframes.get(keyFrame);
if (keyFrameListeners == null)
return;
event.setKeyFrame(keyFrame);
for (AnimationListener listener : keyFrameListeners) {
listener.animationStateChanged(event);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.animation;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Interface Definition and Members *
// ***************************************************************************
public interface AnimationListener extends Comparable<Object> {
/**
* @param event
*/
public void animationStateChanged(AnimationEvent event);
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.widget.animation.Animated;
import lu.list.itis.dkd.tui.widget.animation.AnimationProperty;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseAnimatedCoronaBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Graphics2D;
import java.util.List;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class AnimatedCorona extends Corona implements Animated {
protected List<AnimationProperty<?>> animationProperties;
private static final Logger logger = LoggerFactory.getLogger(AnimatedCorona.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
public AnimatedCorona(BaseAnimatedCoronaBuilder<?> builder) {
super(builder);
animationProperties = builder.animationProperties;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public List<AnimationProperty<?>> getAnimationProperties() {
return animationProperties;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
// TODO Auto-generated method stub
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public void start() {
for (AnimationProperty<?> property : animationProperties) {
property.setAnimatedObject(this);
property.start();
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public void stop() {
for (AnimationProperty<?> property : animationProperties) {
property.stop();
}
this.resetAnimatedProperties();
}
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.widget.animation.AnimationProperty;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseAnimatedShapeCoronaBuilder;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseShapeCoronaBuilder;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.util.List;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.3.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AnimatedShapeCorona extends AnimatedCorona {
private Color fillColour = Color.GRAY;
private Color strokeColour = Color.GRAY;
private float angle;
private float opacity;
private double scale;
private Stroke borderStroke;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor building all fields and calling the implicit super constructor using a
* {@link BaseShapeCoronaBuilder} instance holding all values.
*
* @param builder
* The {@link BaseShapeCoronaBuilder} instance holding all values.
*/
// ---------------------------------------------------------------------------
public AnimatedShapeCorona(BaseAnimatedShapeCoronaBuilder<?> builder) {
super(builder);
fillColour = builder.fillColour;
strokeColour = builder.strokeColour;
opacity = builder.opacity;
scale = 1.0;
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
@Override
public void resetAnimatedProperties() {
List<AnimationProperty<?>> properties = this.getAnimationProperties();
for (AnimationProperty<?> property : properties) {