Commit 2fe5cd47 authored by Nico Mack's avatar Nico Mack

Added AnimationDelegate

parent 60a0375c
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. 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.event.interaction.delegate;
import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.event.interaction.Interaction;
import lu.list.itis.dkd.tui.event.interaction.delegate.builder.BaseAnimationDelegateBuilder;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.Map;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AnimationDelegate extends Delegate {
private Integer handle;
private BaseWidget target;
private Map<String, Method> doableMethods;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(AnimationDelegate.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public AnimationDelegate(BaseAnimationDelegateBuilder<?> builder) {
super(builder);
this.handle = builder.handle;
this.setupFromProperties();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void setupFromProperties() {
this.doableMethods = Delegate.getDoableMethods(AnimationDelegate.class);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public boolean handle(Interaction action) {
if (target == null) {
this.target = TangibleObjectManager.getWidget(handle);
}
if (this.target != null) {
if (doableMethods.containsKey(this.doable)) {
Runnable doIt = () -> {
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
Thread handlingThread = new Thread(doIt);
handlingThread.start();
return true;
}
LOGGER.warn("Don't know how to do {}!", this.doable); //$NON-NLS-1$
}
return false;
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
@Doable(identifier = "start")
public void startAnimations() {
this.target.startAnimations();
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
@Doable(identifier = "stop")
public void stopAnimations() {
this.target.stopAnimations();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
......@@ -130,8 +130,8 @@ public class AudioDelegate extends MediaDelegate implements Playable, Controller
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
Thread playThread = new Thread(doIt);
playThread.start();
Thread handlingThread = new Thread(doIt);
handlingThread.start();
return true;
}
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. 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.event.interaction.delegate.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.event.interaction.delegate.AnimationDelegate;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AnimationDelegateBuilder extends BaseAnimationDelegateBuilder<AnimationDelegateBuilder> {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public AnimationDelegateBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public AnimationDelegateBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public AnimationDelegate build() {
return new AnimationDelegate(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. 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.event.interaction.delegate.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.event.interaction.delegate.AnimationDelegate;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
* @param <B>
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseAnimationDelegateBuilder<B extends BaseAnimationDelegateBuilder<B>> extends BaseDelegateBuilder<B> {
public Integer handle;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseAnimationDelegateBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseAnimationDelegateBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
handle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.HANDLE_NODE, BootstrappingUtils.MANDATORY, null, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public abstract AnimationDelegate build();
}
......@@ -33,6 +33,7 @@ import lu.list.itis.dkd.tui.utility.CoronaComparator;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.Positionable;
import lu.list.itis.dkd.tui.widget.builder.BaseBuilder;
import lu.list.itis.dkd.tui.widget.corona.AnimatedCorona;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import lu.list.itis.dkd.tui.widget.touch.TouchEvent;
import lu.list.itis.dkd.tui.widget.touch.Touchable;
......@@ -637,6 +638,32 @@ public class BaseWidget implements Positionable, Touchable, Interactive {
return this.clippingRegion;
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void startAnimations() {
for (AnimatedCorona animated : this.getCoronas(AnimatedCorona.class)) {
animated.setActive(true);
animated.start();
}
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void stopAnimations() {
for (AnimatedCorona animated : this.getCoronas(AnimatedCorona.class)) {
animated.stop();
animated.setActive(false);
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
......
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