Commit 43e06060 authored by Eric Tobias's avatar Eric Tobias

Bug fixes and refactoring

parent 83bf257b
......@@ -17,6 +17,7 @@
<definingShape>Circle</definingShape>
<networkAdapter></networkAdapter>
</object>
</objects>
<cursors>
<cursor>
......
ALPHA=alpha
BACKGROUND_COLOUR=backgroundColour
BORDER_THICKNESS=borderThickness
BORDER_WIDTH=borderWidth
ALPHA_NODE=alpha
BACKGROUND_COLOUR_NODE=backgroundColour
BLOBS_NODE=blobs
BORDER_THICKNESS_NODE=borderThickness
BORDER_WIDTH_NODE=borderWidth
BUILDER_CLASS_POSTFIX=Builder
CENTRE_NODE=centre
CENTRED=centred
COLOUR=colour
CENTRED_NODE=centred
COLOUR_NODE=colour
CORONA_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.corona.builder
CORONA_NODE=corona
CORONAS_NODE=coronas
CURSORS_NODE=cursors
DEFINING_SHAPE_NODE=definingShape
DRAW_BORDER=drawBorder
DRAW_BORDER_NODE=drawBorder
DRAW_PRIORITY_NODE=drawPriority
EDGE_COLOUR=edgeColour
FILL_COLOUR=fillColour
FONT=font
FONT_SIZE=fontSize
EDGE_COLOUR_NODE=edgeColour
EMPTY_STRING=
FILL_COLOUR_NODE=fillColour
FONT_NODE=font
FONT_SIZE_NODE=fontSize
GLOBAL_STATE_LISTENER_NODE=globalStateListener
HANDLE_NODE=handle
HANDLES_NODE=handles
IMAGE=image
IMAGE_NODE=image
INFORMATION=information
INITIAL_ROTATION_NODE=initialRotation
INITIAL_TRANSLATION_NODE=initialTranslation
JAVA_AWT_COLOR_NAMESPACE=java.awt.Color
LENGTH=length
LINE=line
LINE_HEIGHT_RATIO=lineHeightRatio
LINE_WIDTH=lineWidth
LENGTH_NODE=length
LINE_NODE=line
LINE_HEIGHT_RATIO_NODE=lineHeightRatio
LINE_WIDTH_NODE=lineWidth
NAME_NODE=name
NAMESPACE_NODE=namespace
NAMESPACE_SEPARATOR=.
NETWORK_ADAPTER_NODE=networkAdapter
RADIUS=radius
OBJECT_NODE=object
OBJECTS_NODE=objects
RADIUS_NODE=radius
ROTATE_WITH_HANDLE_NODE=rotateWithHandle
SHAPE_NODE=shape
SPIN_ON_CORONA_CENTRE_NODE=spinOnCoronaCentre
START=start
TEXT=text
START_NODE=start
TEXT_NODE=text
TYPE_NODE=type
WIDGET_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.builder
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. 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.bootstrapping;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.event.ContextEventListener;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
import java.util.List;
import java.util.Vector;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.2
* @version 2.2.0
*/
@NonNullByDefault
public class ContextEventListenerBootstrapper {
/**
* @param rootElements
* @return
* @throws BuildException
*/
public static List<ContextEventListener> getContextEventListeners(List<Element> rootElements) throws BuildException {
List<ContextEventListener> listeners = new Vector<>();
for (Element listenerNode : rootElements) {
listeners.add(resolveListener(listenerNode));
}
return listeners;
}
/**
* Method used to instantiate a {@link ContextEventListener} from a provided {@link Element}.
*
* @param listenerNode
* The node containing, as child nodes, all the relevant information to instantiate a
* concrete {@link ContextEventListener}.
* @return The concrete {@link ContextEventListener} instance.
* @throws BuildException
* Thrown when one or more of the required bits of information were missing or if an
* error occurred during any of the reflective calls used to resolve the concrete
* instance in question.
*/
@SuppressWarnings("unchecked")
private static ContextEventListener resolveListener(Element listenerNode) throws BuildException {
String namespace = listenerNode.getChildText("namespace");
String _class = listenerNode.getChildText("type");
Class<? extends ContextEventListener> listenerClass;
try {
listenerClass = (Class<? extends ContextEventListener>) Class.forName(namespace + _class);
} catch (ReflectiveOperationException roe) {
throw new BuildException("An error occurred while trying to access the concrete context event listener class!", roe); //$NON-NLS-1$
} catch (ClassCastException cce) {
throw new BuildException("The given class was not a sub-class of ContextEventListener!", cce); //$NON-NLS-1$
}
List<Element> indexedArgumentNodes = listenerNode.getChildren("indexedArguments");
Object[] arguments = resolveArguments(indexedArgumentNodes);
return null;
}
/**
* @param indexedArgumentNodes
* @return
* @throws BuildException
*/
private static Object[] resolveArguments(List<Element> indexedArgumentNodes) throws BuildException {
Object[] arguments = new Object[indexedArgumentNodes.size()];
// TODO continue here.
return arguments;
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import lu.list.itis.dkd.tui.widget.corona.builder.CoronaBuilder;
......@@ -35,8 +36,6 @@ import java.lang.reflect.InvocationTargetException;
*/
public class CoronaBootstrapper {
private static final String CORONA_BUILDER_NAMESPACE = "lu.list.itis.dkd.tui.widget.corona.builder."; //$NON-NLS-1$
/**
* Method used to determine the appropriate builder for a given corona and then issue a build
* call.
......@@ -63,9 +62,8 @@ public class CoronaBootstrapper {
* class.
*/
private static Corona getCorona(Element coronaNode) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
Element type = coronaNode.getChild("type"); //$NON-NLS-1$
Class<?> builder = Class.forName(CORONA_BUILDER_NAMESPACE + type.getValue() + "Builder"); //$NON-NLS-1$
Element type = coronaNode.getChild(Externalization.TYPE_NODE);
Class<?> builder = Class.forName(Externalization.CORONA_BUILDER_NAMESPACE + Externalization.NAMESPACE_SEPARATOR + type.getValue() + Externalization.BUILDER_CLASS_POSTFIX);
@SuppressWarnings("unchecked")
Constructor<CoronaBuilder<?>> constructor = (Constructor<CoronaBuilder<?>>) builder.getConstructor(new Class[] {Element.class});
return constructor.newInstance(new Object[] {coronaNode}).build();
......@@ -85,9 +83,9 @@ public class CoronaBootstrapper {
public static Multimap<Integer, Corona> getCoronas(Element coronaRootNode) throws BuildException {
Multimap<Integer, Corona> coronas = TreeMultimap.create();
for (Element coronaNode : coronaRootNode.getChildren("corona")) { //$NON-NLS-1$
for (Element coronaNode : coronaRootNode.getChildren(Externalization.CORONA_NODE)) {
try {
int handleId = Integer.parseInt(coronaNode.getChildText("handle")); //$NON-NLS-1$
int handleId = Integer.parseInt(coronaNode.getChildText(Externalization.HANDLE_NODE));
coronas.put(handleId, getCorona(coronaNode));
} catch (NumberFormatException nfe) {
throw new BuildException("The corona was not associated with any handle. The handle ID may not be null!", nfe); //$NON-NLS-1$
......
......@@ -18,6 +18,7 @@ package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
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 lu.list.itis.dkd.tui.widget.builder.BaseBuilder;
......@@ -34,6 +35,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -44,8 +46,6 @@ import java.util.logging.Logger;
*/
@NonNullByDefault
public class TangibleObjectBootstrapper {
private static final String WIDGET_BUILDER_NAMESPACE = "lu.list.itis.dkd.tui.widget.builder."; //$NON-NLS-1$
private static final Logger logger = Logger.getLogger(TangibleObjectBootstrapper.class.getSimpleName());
private Document document;
......@@ -99,7 +99,7 @@ public class TangibleObjectBootstrapper {
*/
public void bootstrap() throws BuildException {
Element rootNode = document.getRootElement();
List<Element> objectRootNodes = rootNode.getChildren("objects"); //$NON-NLS-1$
List<Element> objectRootNodes = rootNode.getChildren(Externalization.OBJECTS_NODE); // $NON-NLS-1$
for (Element objectNode : objectRootNodes) {
switch (objectNode.getName()) {
......@@ -128,7 +128,7 @@ public class TangibleObjectBootstrapper {
* TODO
*/
private void loadObjects(Element objectRootNode) throws BuildException {
List<Element> objectNodes = objectRootNode.getChildren("object"); //$NON-NLS-1$
List<Element> objectNodes = objectRootNode.getChildren(Externalization.OBJECT_NODE);
try {
for (Element objectNode : objectNodes) {
......@@ -170,8 +170,8 @@ public class TangibleObjectBootstrapper {
*/
private BaseWidget buildObjectFromElement(Element objectNode) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
Element type = objectNode.getChild("type"); //$NON-NLS-1$
Class<?> builder = Class.forName(WIDGET_BUILDER_NAMESPACE + type.getValue() + "Builder"); //$NON-NLS-1$
Element type = objectNode.getChild(Externalization.TYPE_NODE);
Class<?> builder = Class.forName(Externalization.WIDGET_BUILDER_NAMESPACE + Externalization.NAMESPACE_SEPARATOR + type.getValue() + Externalization.BUILDER_CLASS_POSTFIX);
@SuppressWarnings("unchecked")
Constructor<BaseBuilder<?>> constructor = (Constructor<BaseBuilder<?>>) builder.getConstructor(new Class[] {Element.class});
......@@ -185,4 +185,21 @@ public class TangibleObjectBootstrapper {
private void loadBlobs() {
Element rootNode = document.getRootElement();
}
/**
* Simple getter method for objects.
*
* @return The value of objects.
*/
public ArrayList<BaseWidget> getObjects() {
return objects;
}
public ConcurrentHashMap<Integer, BaseWidget> getObjectMap() {
ConcurrentHashMap<Integer, BaseWidget> objectMap = new ConcurrentHashMap<>();
objects.forEach(widget -> widget.getPositions().keySet().forEach(handleId -> objectMap.put(handleId, widget)));
return objectMap;
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@
* 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.bootstrapping;
package lu.list.itis.dkd.tui.utility;
import org.eclipse.osgi.util.NLS;
......@@ -26,47 +26,60 @@ import org.eclipse.osgi.util.NLS;
* @version 2.2.0
*/
@SuppressWarnings("javadoc")
public class Messages extends NLS {
private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$
public static String ALPHA;
public static String BACKGROUND_COLOUR;
public static String BORDER_THICKNESS;
public static String BORDER_WIDTH;
public class Externalization extends NLS {
private static final String BUNDLE_NAME = "externalization"; //$NON-NLS-1$
public static String ALPHA_NODE;
public static String BACKGROUND_COLOUR_NODE;
public static String BLOBS_NODE;
public static String BORDER_THICKNESS_NODE;
public static String BORDER_WIDTH_NODE;
public static String BUILDER_CLASS_POSTFIX;
public static String CENTRE_NODE;
public static String CENTRED;
public static String COLOUR;
public static String CENTRED_NODE;
public static String COLOUR_NODE;
public static String CORONA_BUILDER_NAMESPACE;
public static String CORONA_NODE;
public static String CORONAS_NODE;
public static String CURSORS_NODE;
public static String DEFINING_SHAPE_NODE;
public static String DRAW_BORDER;
public static String DRAW_BORDER_NODE;
public static String DRAW_PRIORITY_NODE;
public static String EDGE_COLOUR;
public static String FILL_COLOUR;
public static String FONT;
public static String FONT_SIZE;
public static String EDGE_COLOUR_NODE;
public static String EMPTY_STRING;
public static String FILL_COLOUR_NODE;
public static String FONT_NODE;
public static String FONT_SIZE_NODE;
public static String GLOBAL_STATE_LISTENER_NODE;
public static String HANDLE_NODE;
public static String HANDLES_NODE;
public static String IMAGE;
public static String IMAGE_NODE;
public static String INFORMATION;
public static String INITIAL_ROTATION_NODE;
public static String INITIAL_TRANSLATION_NODE;
public static String JAVA_AWT_COLOR_NAMESPACE;
public static String LENGTH;
public static String LINE;
public static String LINE_HEIGHT_RATIO;
public static String LINE_WIDTH;
public static String LENGTH_NODE;
public static String LINE_NODE;
public static String LINE_HEIGHT_RATIO_NODE;
public static String LINE_WIDTH_NODE;
public static String NAME_NODE;
public static String NAMESPACE_NODE;
public static String NAMESPACE_SEPARATOR;
public static String NETWORK_ADAPTER_NODE;
public static String RADIUS;
public static String OBJECT_NODE;
public static String OBJECTS_NODE;
public static String RADIUS_NODE;
public static String ROTATE_WITH_HANDLE_NODE;
public static String SHAPE_NODE;
public static String SPIN_ON_CORONA_CENTRE_NODE;
public static String START;
public static String TEXT;
public static String START_NODE;
public static String TEXT_NODE;
public static String TYPE_NODE;
public static String WIDGET_BUILDER_NAMESPACE;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
NLS.initializeMessages(BUNDLE_NAME, Externalization.class);
}
private Messages() {}
private Externalization() {}
}
\ No newline at end of file
......@@ -170,7 +170,7 @@ public class Point extends Float {
if (rootNode.getChild("state") != null) { //$NON-NLS-1$
try {
Class<?> stateClass = Class.forName(Point.class.getPackage() + "." + rootNode.getChildText("state")); //$NON-NLS-1$ //$NON-NLS-2$
Class<?> stateClass = Class.forName(Point.class.getPackage().getName() + "." + rootNode.getChildText("state")); //$NON-NLS-1$ //$NON-NLS-2$
Constructor<?> stateConstructor = stateClass.getConstructor(new Class[] {Point.class, java.lang.Float.TYPE, java.lang.Float.TYPE});
this.state = (CoordinateState) stateConstructor.newInstance(new Object[] {this, x, y});
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
......
......@@ -18,12 +18,12 @@ package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.Messages;
import lu.list.itis.dkd.tui.bootstrapping.CoronaBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.NetworkAdapterBootstrapper;
import lu.list.itis.dkd.tui.bootstrapping.ShapeBootstrapper;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.network.adapter.NetworkAdapter;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import lu.list.itis.dkd.tui.widget.corona.Corona;
......@@ -68,7 +68,7 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
public BaseBuilder() {
coronas = TreeMultimap.create();
positions = new HashMap<>();
name = ""; //$NON-NLS-1$
name = Externalization.EMPTY_STRING;
}
/**
......@@ -87,7 +87,7 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
coronas = TreeMultimap.create();
positions = new HashMap<>();
for (Element handleNode : rootElement.getChild(Messages.HANDLES_NODE).getChildren(Messages.HANDLE_NODE)) {
for (Element handleNode : rootElement.getChild(Externalization.HANDLES_NODE).getChildren(Externalization.HANDLE_NODE)) {
try {
int id = Integer.parseInt(handleNode.getText());
positions.put(id, null);
......@@ -96,11 +96,11 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
}
}
name = Strings.nullToEmpty(rootElement.getChildText(Messages.NAME_NODE));
definingShape = ShapeBootstrapper.getShape(rootElement.getChildText(Messages.DEFINING_SHAPE_NODE));
networkAdapter = NetworkAdapterBootstrapper.getNetworkAdapter(rootElement.getChild(Messages.NETWORK_ADAPTER_NODE));
name = Strings.nullToEmpty(rootElement.getChildText(Externalization.NAME_NODE));
definingShape = ShapeBootstrapper.getShape(rootElement.getChildText(Externalization.DEFINING_SHAPE_NODE));
networkAdapter = NetworkAdapterBootstrapper.getNetworkAdapter(rootElement.getChild(Externalization.NETWORK_ADAPTER_NODE));
coronas = CoronaBootstrapper.getCoronas(rootElement.getChild(Messages.CORONAS_NODE));
coronas = CoronaBootstrapper.getCoronas(rootElement.getChild(Externalization.CORONAS_NODE));
}
/**
......
......@@ -17,12 +17,17 @@
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.bootstrapping.ContextEventListenerBootstrapper;
import lu.list.itis.dkd.tui.event.ContextEventListener;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.ContextAwareWidget;
import lu.list.itis.dkd.tui.widget.corona.ContextAwareCorona;
import com.google.common.collect.HashMultimap;
import org.jdom2.Element;
import java.util.Vector;
/**
......@@ -44,6 +49,33 @@ public abstract class BaseContextAwareBuilder<B extends BaseContextAwareBuilder<
/** Field holding all listeners to be notified on events changing the global state. */
public volatile Vector<ContextEventListener> globalStateListeners = new Vector<>();
/** Constructor initialising the fields. */
protected BaseContextAwareBuilder() {
super();
}
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
protected BaseContextAwareBuilder(Element rootElement) throws BuildException {
super(rootElement);
globalStateListeners.addAll(ContextEventListenerBootstrapper.getContextEventListeners(
rootElement.getChildren(Externalization.GLOBAL_STATE_LISTENER_NODE)));
// TODO add specific corona listener.
}
/**
* Method used to add a listener for a specific corona.
*
......
......@@ -17,25 +17,69 @@
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.FunctionWidget;
import org.jdom2.Element;
/**
* Builder serving as abstract super class for all content builders.
*
* @author Eric TOBIAS [eric.tobias@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.1.4
* @version 2.2.0
* @param <B>
* The concrete builder.
*/
@NonNullByDefault
public abstract class BaseFunctionWidgetBuilder<B extends BaseFunctionWidgetBuilder<B>> extends BaseBuilder<B> {
/** The runnable to be run by the function widget once built. */
public Runnable runnable;
/** Constructor initialising the fields. */
protected BaseFunctionWidgetBuilder() {
super();
}
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
protected BaseFunctionWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
try {
String namespace = rootElement.getChildText(Externalization.NAMESPACE_NODE);
String _class = rootElement.getChildText(Externalization.TYPE_NODE);
@SuppressWarnings("unchecked")
Class<Runnable> _runnable = (Class<Runnable>) Class.forName(namespace + _class);
runnable = _runnable.newInstance();
} catch (ReflectiveOperationException roe) {
throw new BuildException("An error occurred while trying to access the concrete non-arg Runnable class instance!", roe); //$NON-NLS-1$
} catch (ClassCastException cce) {
throw new BuildException("The given class was not a sub-class of Runnable!", cce); //$NON-NLS-1$
}
}
/**
* Method for adding a {@link Runnable} to be run by the function widget.
*
* @param runnable
* The {@link Runnable} to run.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withRunnable(Runnable runnable) {
public B withRunnable(@SuppressWarnings("hiding") Runnable runnable) {
this.runnable = runnable;
return (B) this;
}
......
......@@ -17,19 +17,21 @@
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.StatefulWidget;
import lu.list.itis.dkd.tui.widget.state.NuiState;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import org.jdom2.Element;
import java.util.concurrent.ConcurrentHashMap;
/**
* Abstract builder serving as the super class for all stateful builders of stateful widgets.
*
* @author Eric TOBIAS [eric.tobias@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.2
* @version 2.2.0
* @param <B>
* The concrete builder.
*/
......@@ -39,23 +41,28 @@ public abstract class BaseStatefulBuilder<B extends BaseStatefulBuilder<B>> exte
public ConcurrentHashMap<Integer, StateManager> states;
/** Constructor initialising the fields. */
public BaseStatefulBuilder() {
protected BaseStatefulBuilder() {
super();
states = new ConcurrentHashMap<>();
}
/**
* Method for setting the {@link NuiState} the widget is to have upon construction.
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param handleID
* The identifier of the handle to add a state for.
* @param stateManager
* The state to set the handle to.
* @return An instance of the builder for chain calling.
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
@SuppressWarnings("unchecked")
public B withHandleState(int handleID, StateManager stateManager) {
states.putIfAbsent(handleID, stateManager);
return (B) this;
protected BaseStatefulBuilder(Element rootElement) throws BuildException {
super(rootElement);
states = new ConcurrentHashMap<>();
positions.keySet().forEach(handleId -> states.putIfAbsent(handleId, new StateManager()));
}
/**
......@@ -68,7 +75,6 @@ public abstract class BaseStatefulBuilder<B extends BaseStatefulBuilder<B>> exte
super.withHandle(handleID, position);
states.put(handleID, new StateManager());
return (B) this;
}
/**
......
......@@ -16,15 +16,38 @@
*/
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.FunctionWidget;
import org.jdom2.Element;