Commit fc01bb9b authored by Nico Mack's avatar Nico Mack

Integrated conditions to widgets.

Added conditionSatisfied interaction.
parent 8b5aff2a
......@@ -28,6 +28,7 @@ COLOUR_NODE=colour
COLOUR_PALETTE_NODE=colourPalette
COLOURSC_NODE=colourscheme
CONDITION_NODE=condition
CONDITIONS_NODE=conditions
CONDITION_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.event.conditional.builder
CONNECTIONS_NODE=connections
CONTENT_NODE=content
......@@ -76,6 +77,7 @@ FILL_COLOUR_NUANCE_NODE=fillColourNuance
FLIP_TITLE_BY_QUADRANT_NODE=flipTitleByQuadrant
FONT_NODE=font
FONT_SIZE_NODE=fontSize
FOR_ATTRIBUTE=for
FULLSCREEN_NODE=fullScreen
GAP_NODE=gap
GLOBAL_STATE_LISTENER_NODE=globalStateListener
......
......@@ -14,3 +14,5 @@ ON_RELEASED=released
ON_TETHER_ESTABLISHED=tetherEstablished
ON_TETHER_TORN_DOWN=tetherTornDown
ON_CONDITION_SATISFIED=conditionSatisfied
\ No newline at end of file
......@@ -273,6 +273,10 @@ public abstract class TangibleApplication {
stageManager.repaint();
}
public void shutdown() {
this.disconnect();
}
/**
* Method for retrieving all active {@link TangibleObject} cursors from the {@link TuiAdapter}
......
......@@ -16,7 +16,12 @@
*/
package lu.list.itis.dkd.tui.event.conditional;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.event.conditional.builder.BaseConditionBuilder;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import com.google.common.collect.Multimap;
/**
* @author Nico Mack [nico.mack@list.lu]
......@@ -28,7 +33,9 @@ import lu.list.itis.dkd.tui.event.conditional.builder.BaseConditionBuilder;
// * Class Definition and Members *
// ***************************************************************************
public abstract class Condition<T> implements Conditional<T> {
public abstract class Condition<T> implements Conditional<T>, Comparable<Condition> {
private String name;
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -40,7 +47,9 @@ public abstract class Condition<T> implements Conditional<T> {
*/
// ---------------------------------------------------------------------------
public Condition() {}
public Condition() {
this.name = Externalization.EMPTY_STRING;
}
// ---------------------------------------------------------------------------
/**
......@@ -49,13 +58,23 @@ public abstract class Condition<T> implements Conditional<T> {
// ---------------------------------------------------------------------------
public Condition(BaseConditionBuilder<?> builder) {
// Nothing to do here.
this.name = builder.name;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public String getName() {
return this.name;
}
// ---------------------------------------------------------------------------
@Override
......@@ -70,4 +89,27 @@ public abstract class Condition<T> implements Conditional<T> {
return this;
}
// ---------------------------------------------------------------------------
/**
* Comparison as defined by the {@link Comparable} interface. This comparison is based on the
* integer comparison of the draw priorities, ordering lower priorities first. This will result in
* lower priority {@link Corona} instances being overlapped by prioritized ones.<br>
* <br>
*
* <b>Note</b>: As the {@link Multimap} used to store {@link Corona} instances uses the
* {@link Comparable} interface to test for equality, all instances must have different draw
* priorities or not be added to the map.<br>
* <br>
*
* {@inheritDoc}
*/
// ---------------------------------------------------------------------------
@Override
public int compareTo(@Nullable Condition condition) {
if (condition == null)
throw new NullPointerException();
return this.name.compareTo(condition.getName());
}
}
......@@ -16,10 +16,13 @@
*/
package lu.list.itis.dkd.tui.event.conditional.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.conditional.Condition;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
......@@ -31,10 +34,60 @@ import org.jdom2.Element;
*/
public abstract class BaseConditionBuilder<B extends BaseConditionBuilder<B>> {
public BaseConditionBuilder(Element rootElement) throws BuildException {};
/** Optional condition name */
public String name;
public BaseConditionBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {};
// ---------------------------------------------------------------------------
// ***************************************************************************
// *Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseConditionBuilder(Element rootElement) throws BuildException {
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseConditionBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.name = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.NAME_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
......
......@@ -27,4 +27,6 @@ public interface Handler<H> extends Comparable<H> {
* @param action
*/
boolean handle(Interaction action);
boolean handle(Interaction action, Object discriminator);
}
......@@ -27,6 +27,7 @@ import lu.list.itis.dkd.tui.event.interaction.builder.BaseInteractionBuilder;
public class Interaction implements Comparable<Interaction> {
private String signature;
private Object discriminator;
// ***************************************************************************
// * Constants *
......@@ -47,6 +48,8 @@ public class Interaction implements Comparable<Interaction> {
public static final Interaction ON_TETHER_ESTABLISHED = new Interaction(Signature.ON_TETHER_ESTABLISHED);
public static final Interaction ON_TETHER_TORN_DOWN = new Interaction(Signature.ON_TETHER_TORN_DOWN);
public static final Interaction ON_CONDITION_SATISFIED = new Interaction(Signature.ON_CONDITION_SATISFIED);
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -71,6 +74,28 @@ public class Interaction implements Comparable<Interaction> {
this.signature = signature;
}
// ---------------------------------------------------------------------------
/**
* @param signature
*/
// ---------------------------------------------------------------------------
public Interaction(String signature, Object discriminator) {
this.signature = signature;
this.discriminator = discriminator;
}
// ---------------------------------------------------------------------------
/**
* @param original
*/
// ---------------------------------------------------------------------------
public Interaction(Interaction original) {
this.signature = original.signature;
this.discriminator = original.discriminator;
}
// ---------------------------------------------------------------------------
/**
* @param builder
......@@ -95,6 +120,24 @@ public class Interaction implements Comparable<Interaction> {
return this.signature;
}
// ---------------------------------------------------------------------------
/**
* @param newDiscriminator
*/
// ---------------------------------------------------------------------------
public void setDiscriminator(Object newDiscriminator) {
this.discriminator = newDiscriminator;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
public Object getDiscriminator() {
return this.discriminator;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
......
......@@ -61,6 +61,26 @@ public class InteractionManager implements Interactive {
// ***************************************************************************
// ---------------------------------------------------------------------------
private boolean handle(Interaction action) {
boolean handled = false;
Collection<Handler> actionHandlers = handlers.get(action.getSignature());
for (Handler handler : actionHandlers) {
handled |= handler.handle(action);
}
return handled;
}
// ---------------------------------------------------------------------------
private boolean handle(Interaction action, Object discriminator) {
boolean handled = false;
Collection<Handler> actionHandlers = handlers.get(action.getSignature());
for (Handler handler : actionHandlers) {
handled |= handler.handle(action, discriminator);
}
return handled;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -119,10 +139,8 @@ public class InteractionManager implements Interactive {
public boolean respondTo(Interaction action) {
boolean handled = false;
if (handlers.containsKey(action.getSignature())) {
Collection<Handler> actionHandlers = handlers.get(action.getSignature());
for (Handler handler : actionHandlers) {
handled |= handler.handle(action);
}
Object discriminator = action.getDiscriminator();
handled = (discriminator == null) ? handle(action) : handle(action, discriminator);
}
return handled;
}
......
......@@ -50,6 +50,8 @@ public class Signature extends NLS {
public static String ON_TETHER_ESTABLISHED;
public static String ON_TETHER_TORN_DOWN;
public static String ON_CONDITION_SATISFIED;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Signature.class);
......
......@@ -75,6 +75,17 @@ public class AnimationDelegate extends Delegate {
this.doableMethods = Delegate.getDoableMethods(AnimationDelegate.class);
}
// ---------------------------------------------------------------------------
private void run() {
Runnable doIt = () -> {
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
Thread handlingThread = new Thread(doIt);
handlingThread.start();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -90,14 +101,33 @@ public class AnimationDelegate extends Delegate {
if (this.target != null) {
if (doableMethods.containsKey(this.doable)) {
this.run();
return true;
}
LOGGER.warn("Don't know how to do {}!", this.doable); //$NON-NLS-1$
}
return false;
}
Runnable doIt = () -> {
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
// ---------------------------------------------------------------------------
Thread handlingThread = new Thread(doIt);
handlingThread.start();
@Override
public boolean handle(Interaction action, Object discriminatorObject) {
Object discrimatorString = new String();
if (discriminatorObject != null) {
discrimatorString = discriminatorObject.toString();
}
if (target == null) {
this.target = TangibleObjectManager.getWidget(handle);
}
if (this.target != null) {
if ((doableMethods.containsKey(this.doable))
&& this.discriminator.equals(discrimatorString)) {
this.run();
return true;
}
LOGGER.warn("Don't know how to do {}!", this.doable); //$NON-NLS-1$
......
......@@ -115,6 +115,17 @@ public class AudioDelegate extends MediaDelegate implements Playable, Controller
}
}
// ---------------------------------------------------------------------------
private void run() {
Runnable doIt = () -> {
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
Thread handlingThread = new Thread(doIt);
handlingThread.start();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -125,17 +136,32 @@ public class AudioDelegate extends MediaDelegate implements Playable, Controller
public boolean handle(Interaction action) {
if (doableMethods.containsKey(this.doable)) {
this.run();
return true;
}
LOGGER.warn("Don't know how to do {}!", this.doable); //$NON-NLS-1$
Runnable doIt = () -> {
Delegate.invokeDoableMethod(doableMethods.get(this.doable), this, null);
};
return false;
}
Thread handlingThread = new Thread(doIt);
handlingThread.start();
// ---------------------------------------------------------------------------
@Override
public boolean handle(Interaction action, Object discriminatorObject) {
Object discrimatorString = new String();
if (discriminatorObject != null) {
discrimatorString = discriminatorObject.toString();
}
if (doableMethods.containsKey(this.doable)) {
if (this.discriminator.equals(discrimatorString)) {
this.run();
return true;
}
} else {
LOGGER.warn("Don't know how to do {}!", this.doable); //$NON-NLS-1$
}
return false;
}
......
......@@ -40,6 +40,7 @@ public abstract class Delegate implements Handler<Delegate> {
protected String name;
protected String doable;
protected String discriminator;
// ***************************************************************************
// * Constants *
......@@ -60,6 +61,7 @@ public abstract class Delegate implements Handler<Delegate> {
public Delegate(BaseDelegateBuilder<?> builder) {
this.name = builder.name;
this.doable = builder.doable;
this.discriminator = builder.discriminator;
}
// ---------------------------------------------------------------------------
......@@ -71,6 +73,7 @@ public abstract class Delegate implements Handler<Delegate> {
public Delegate(Delegate original) {
this.name = original.name;
this.doable = original.doable;
this.discriminator = original.discriminator;
}
// ---------------------------------------------------------------------------
......@@ -124,6 +127,9 @@ public abstract class Delegate implements Handler<Delegate> {
if (comparison == 0) {
comparison = this.doable.compareTo(delegate.doable);
}
if (comparison == 0) {
comparison = this.discriminator.compareTo(delegate.discriminator);
}
if (comparison == 0) {
comparison = this.name.compareTo(delegate.name);
}
......
......@@ -27,6 +27,7 @@ public abstract class BaseDelegateBuilder<B extends BaseDelegateBuilder<B>> {
/** The name that will be given to the delegate. */
public String name;
public String doable;
public String discriminator;
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -38,6 +39,7 @@ public abstract class BaseDelegateBuilder<B extends BaseDelegateBuilder<B>> {
public BaseDelegateBuilder() {
name = Externalization.EMPTY_STRING;
doable = Externalization.EMPTY_STRING;
discriminator = Externalization.EMPTY_STRING;
}
// ---------------------------------------------------------------------------
......@@ -72,6 +74,7 @@ public abstract class BaseDelegateBuilder<B extends BaseDelegateBuilder<B>> {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
doable = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.DO_ATTRIBUTE, BootstrappingUtils.MANDATORY, null);
discriminator = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.FOR_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
name = BootstrappingUtils.getContentAsString(rootElement, Externalization.NAME_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
}
......
......@@ -63,6 +63,7 @@ public class Externalization extends NLS {
public static String COLOUR_PALETTE_NODE;
public static String COLOURSC_NODE;
public static String CONDITION_NODE;
public static String CONDITIONS_NODE;
public static String CONDITION_BUILDER_NAMESPACE;
public static String CONNECTIONS_NODE;
public static String CONTENT_NODE;
......@@ -111,6 +112,7 @@ public class Externalization extends NLS {
public static String FLIP_TITLE_BY_QUADRANT_NODE;
public static String FONT_NODE;
public static String FONT_SIZE_NODE;
public static String FOR_ATTRIBUTE;
public static String FULLSCREEN_NODE;
public static String GAP_NODE;
public static String GLOBAL_STATE_LISTENER_NODE;
......
......@@ -23,6 +23,7 @@ package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.event.conditional.Condition;
import lu.list.itis.dkd.tui.event.interaction.Handler;
import lu.list.itis.dkd.tui.event.interaction.Interaction;
import lu.list.itis.dkd.tui.event.interaction.InteractionManager;
......@@ -76,6 +77,8 @@ public class BaseWidget implements Positionable, Touchable, Interactive {
private Multimap<Integer, Corona> coronas;
/** The positions where the widget's handles are at. */
private HashMap<Integer, Point> positions;
/** The conditions assigned to this widget. */
protected List<Condition<Object>> conditions;
/** The name given to this widget. */
protected String name;
/** Specifies whether this widget is controlled by a tangible object or not. */
......@@ -124,6 +127,7 @@ public class BaseWidget implements Positionable, Touchable, Interactive {
coronas = builder.coronas;
positions = builder.positions;
conditions = builder.conditions;
this.setupInteractions(builder.interactions);
......
......@@ -25,10 +25,12 @@ 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.bootstrapping.ConditionBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.CoronaBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.InteractionBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.NetworkAdapterBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.ShapeBootstrapper;
import lu.list.itis.dkd.tui.event.conditional.Condition;
import lu.list.itis.dkd.tui.event.interaction.Interaction;
import lu.list.itis.dkd.tui.event.interaction.delegate.Delegate;
import lu.list.itis.dkd.tui.exception.BuildException;
......@@ -45,7 +47,9 @@ import com.google.common.collect.TreeMultimap;
import org.jdom2.Element;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Abstract builder class serving as the top level hierarchical construct for all widget builders.
......@@ -63,6 +67,8 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
public Multimap<Integer, Corona> coronas;
/** The base where the widget is at. */
public HashMap<Integer, Point> positions;
/** The conditions assigned to this widget. */
public List<Condition<Object>> conditions;
/** The name that will be given to the widget. */
public String name;
/** The (optional) Id of the stage to present the widget. */
......@@ -154,6 +160,15 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
coronas = CoronaBootstrapper.getCoronas(rootElement.getChild(Externalization.CORONAS_NODE), context, callback);
conditions = new ArrayList<>();
Element conditionsNode = rootElement.getChild(Externalization.CONDITIONS_NODE);
if (conditionsNode != null) {
for (Element conditionNode : conditionsNode.getChildren(Externalization.CONDITION_NODE)) {
conditions.add((Condition<Object>) ConditionBootstrapper.buildConditionFromTemplate(conditionNode, context, callback));
}
}
Element interactionsNode = rootElement.getChild(Externalization.INTERACTIONS_NODE);
if (interactionsNode != null) {
interactions = InteractionBootstrapper.buildInteractionFromTemplate(interactionsNode, context, callback);
......
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