Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit 264c6d34 authored by Nico Mack's avatar Nico Mack

Implemented Bootstrapping of Interactions and Delegates

parent 0abfd332
ABOUT_NODE=about
ACTION_ATTRIBUTE=action
ACTIVATE_WITH_HANDLE_NODE=activateWithHandle
ALPHA_NODE=alpha
ANIMATED_PROPERTIES_ELEMENT=animatedProperties
......@@ -41,6 +42,9 @@ CURSORS_NODE=cursors
DEFAULT_NODE=default
DEFINING_SHAPE_NODE=definingShape
DELAY_NODE=delay
DELEGATE=delegate
DELEGATES=delegates
DELEGATE_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.event.interaction.delegate.builder
DESCRIPTION_NODE=description
DESELECTED_ELEMENT=deselected
DISPLAY_NAME_NODE=displayName
......@@ -89,6 +93,9 @@ INFORMATION=information
INITIAL_ROTATION_NODE=initialRotation
INITIAL_TRANSLATION_NODE=initialTranslation
INNER_RADIUS_NODE=innerRadius
INTERACTIONS_NODE=interactions
INTERACTION_NODE=interaction
INTERACTION_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.event.interaction.builder
INSET_BORDER_NODE=insetBorder
JAVA_AWT_COLOR_NAMESPACE=java.awt.Color
LABEL_COLOUR_ELEMENT=labelColour
......@@ -113,6 +120,7 @@ MARKER_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.marker.builder
MARKER_NODE=marker
MARKERS_NODE=markers
MEDIA_NODE=media
MIME_TYPE_NODE=mimeType
MULTIPLE_INSTANCES_NODE=multipleInstances
NAME_ATTRIBUTE=name
NAME_NODE=name
......
AUDIO_MPEG=audio/mpeg
\ No newline at end of file
......@@ -20,8 +20,9 @@ package lu.list.itis.dkd.tui.event.interaction;
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.5.0
* @param <H>
*/
public interface Handler extends Comparable<Handler> {
public interface Handler<H> extends Comparable<H> {
/**
* @param action
*/
......
......@@ -16,13 +16,15 @@
*/
package lu.list.itis.dkd.tui.event.interaction;
import lu.list.itis.dkd.tui.event.interaction.builder.BaseInteractionBuilder;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.5.0
*/
public class Interaction {
public class Interaction implements Comparable<Interaction> {
private String signature;
......@@ -69,6 +71,16 @@ public class Interaction {
this.signature = signature;
}
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public Interaction(BaseInteractionBuilder<?> builder) {
this.signature = builder.action;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -82,4 +94,18 @@ public class Interaction {
public String getSignature() {
return this.signature;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public int compareTo(Interaction interaction) {
if (interaction == null)
throw new NullPointerException();
int comparison = signature.compareTo(interaction.signature);
return comparison;
}
}
package lu.list.itis.dkd.tui.event.interaction.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.Interaction;
import lu.list.itis.dkd.tui.event.interaction.Signature;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.BaseWidget;
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 BaseInteractionBuilder<B extends BaseInteractionBuilder<B>> {
/** The name that will be given to the delegate. */
public String action;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** Constructor initialising the fields. */
public BaseInteractionBuilder() {
action = Externalization.EMPTY_STRING;
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseInteractionBuilder(Element rootElement) throws BuildException {
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseInteractionBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
action = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.ACTION_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Signature.UNDEFINED);;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Method for building a {@link BaseWidget} with the values set by the builder.
*
* @return An instance of {@link BaseWidget} as by the values issued to the builder.
*/
// ---------------------------------------------------------------------------
public abstract Interaction build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * 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.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.Interaction;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class InteractionBuilder extends BaseInteractionBuilder<InteractionBuilder> {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public InteractionBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public InteractionBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public Interaction build() {
return new Interaction(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;
import lu.list.itis.dkd.tui.content.Playable;
import lu.list.itis.dkd.tui.event.interaction.Interaction;
import lu.list.itis.dkd.tui.event.interaction.delegate.builder.BaseMediaDelegateBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import javax.media.Controller;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.Time;
import javax.media.format.AudioFormat;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class AudioDelegate extends MediaDelegate implements Playable {
private Player player;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final String MP3_DECODER = "com.sun.media.codec.audio.mp3.JavaDecoder"; //$NON-NLS-1$
private static final Format PCM_FORMAT = new AudioFormat(AudioFormat.LINEAR);
private static final Format MPEG_FORMAT = new AudioFormat(AudioFormat.MPEG);
private static final Format MP3_FORMAT = new AudioFormat(AudioFormat.MPEGLAYER3);
private static Time BEGIN = new Time(0);
static {
PlugInManager.addPlugIn(MP3_DECODER, new Format[] {MPEG_FORMAT, MP3_FORMAT}, new Format[] {PCM_FORMAT}, PlugInManager.CODEC);
}
private static final Logger LOGGER = LoggerFactory.getLogger(AudioDelegate.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public AudioDelegate(BaseMediaDelegateBuilder<?> builder) {
super(builder);
this.setupFromProperties();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void setupFromProperties() {
File mediaFile = new File(this.baseUrl.toString(), this.media);
try {
MediaLocator locator = new MediaLocator(mediaFile.toURI().toURL());
this.player = Manager.createPlayer(locator);
this.player.realize();
} catch (NoPlayerException | IOException e) {
LOGGER.error("Failed to prepare media {} in {}!", this.media, this.baseUrl, e); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
@Override
public boolean handle(Interaction action) {
this.play();
return true;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void play() {
if ((this.player != null) && (player.getState() == Controller.Realized)) {
this.player.setMediaTime(BEGIN);
this.player.start();
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void pause() {
if ((this.player != null) && (player.getState() == Controller.Started)) {
this.player.stop();
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void stop() {
if ((this.player != null) && (player.getState() == Controller.Started)) {
this.player.stop();
this.player.setMediaTime(BEGIN);
}
}
}
\ No newline at end of file
/**
* 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.event.interaction.Handler;
import lu.list.itis.dkd.tui.event.interaction.delegate.builder.BaseDelegateBuilder;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class Delegate implements Handler<Delegate> {
protected String name;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public Delegate(BaseDelegateBuilder<?> builder) {
this.name = builder.name;
}
// ---------------------------------------------------------------------------
/**
* @param original
*/
// ---------------------------------------------------------------------------
public Delegate(Delegate original) {
this.name = original.name;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public int compareTo(Delegate delegate) {
if (delegate == null)
throw new NullPointerException();
String clazzName = this.getClass().getName();
int comparison = clazzName.compareTo(delegate.getClass().getName());
if (comparison == 0) {
comparison = this.name.compareTo(delegate.name);
}
return comparison;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * 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;
import lu.list.itis.dkd.tui.event.interaction.delegate.builder.BaseMediaDelegateBuilder;
import java.net.URL;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class MediaDelegate extends Delegate {
protected URL baseUrl;
protected String media;
protected String mimeTpye;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public MediaDelegate(BaseMediaDelegateBuilder<?> builder) {
super(builder);
this.baseUrl = builder.baseUrl;
this.media = builder.media;
this.mimeTpye = builder.mimeType;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
}
/**
* 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.AudioDelegate;
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 AudioDelegateBuilder extends BaseMediaDelegateBuilder<AudioDelegateBuilder> {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public AudioDelegateBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public AudioDelegateBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public AudioDelegate build() {
return new AudioDelegate(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
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.Delegate;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.BaseWidget;
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 BaseDelegateBuilder<B extends BaseDelegateBuilder<B>> {
/** The name that will be given to the delegate. */
public String name;
// ---------------------------------------------------------------------------