Commit ea2e45ce authored by Eric Tobias's avatar Eric Tobias

Added a few more bootstrapping facilities.

parent d929cb22
2.2.0
2.2
Implementation of XML based bootstrapping for widgets and coronas.
......@@ -11,6 +11,8 @@ Implementation of XML based bootstrapping for widgets and coronas.
+ Removed field and methods for corona persistence from Corona and the CoronaBuilder. No scenario exists that accounts for persistence and the related methods when drawing were not supported either.
+ Removed the field "background" and all related methods from Corona. Adjusted Image accordingly. The field was not used. Conceptually, coronas should never be part of the background.
+ Added ValueProvider interface.
2.1.4
......
This diff is collapsed.
ALPHA_NODE=alpha
BACKGROUND_COLOUR_NODE=backgroundColour
BASE_VALUE_NODE=baseValue
BLOBS_NODE=blobs
BORDER_THICKNESS_NODE=borderThickness
BORDER_WIDTH_NODE=borderWidth
......@@ -31,6 +32,11 @@ LENGTH_NODE=length
LINE_NODE=line
LINE_HEIGHT_RATIO_NODE=lineHeightRatio
LINE_WIDTH_NODE=lineWidth
LOWER_BOUND_NODE=lowerBound
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
NAME_NODE=name
NAMESPACE_NODE=namespace
NAMESPACE_SEPARATOR=.
......@@ -42,6 +48,10 @@ ROTATE_WITH_HANDLE_NODE=rotateWithHandle
SHAPE_NODE=shape
SPIN_ON_CORONA_CENTRE_NODE=spinOnCoronaCentre
START_NODE=start
STEP_SIZE_NODE=stepSize
TEXT_NODE=text
TYPE_NODE=type
UPPER_BOUND_NODE=upperBound
UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
WIDGET_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.builder
......@@ -24,4 +24,7 @@ cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
\ No newline at end of file
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = config/bootstrapping.xml
\ No newline at end of file
......@@ -6,8 +6,8 @@
<name>TULIP</name>
<description>A framework for tabletop tangible user interface applications.</description>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1280
windowHeight = 800
fullScreen = false
font = Arial
fontSize = 13
colour = BLACK
centred = false
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
\ No newline at end of file
......@@ -83,12 +83,12 @@ public abstract class TangibleApplication {
/**
* Constructor initialising several basic properties.
*
* @param newPropertiesFileURI
* @param newPropertiesFileUri
* The URI of the properties file to load.
*/
protected TangibleApplication(@Nullable String newPropertiesFileURI) {
if (newPropertiesFileURI != null && !newPropertiesFileURI.isEmpty()) {
properties = PropertiesFetcher.fetchProperties(newPropertiesFileURI);
protected TangibleApplication(@Nullable String newPropertiesFileUri) {
if (newPropertiesFileUri != null && !newPropertiesFileUri.isEmpty()) {
properties = PropertiesFetcher.fetchProperties(newPropertiesFileUri);
}
properties = PropertiesFetcher.fetchProperties();
......
/**
* 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.Nullable;
import lu.list.itis.dkd.tui.TangibleApplication;
import lu.list.itis.dkd.tui.exception.BuildException;
/**
* Class implementing a concrete tangible application that will leverage the instantiation of its
* parent to populate most fields before making use of a tangible object manager bootstrapper to
* load all tangibles.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.2
* @version 2.2.2
*/
public class TangibleApplicationBootstrapper extends TangibleApplication {
/**
* @param newPropertiesFileUri
* @throws BuildException
*
*/
public TangibleApplicationBootstrapper(@Nullable String newPropertiesFileUri) throws BuildException {
super(newPropertiesFileUri);
objectManager = new TangibleObjectBootstrapper(this, logger, properties, properties.getProperty("bootstrapping.root", "config/bootstrapping.xml")); //$NON-NLS-1$ //$NON-NLS-2$
adapter.setObjectManager(objectManager);
// TODO Initialize Content Manager (or leave it null)
}
}
\ No newline at end of file
......@@ -17,6 +17,8 @@
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleApplication;
import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.BaseWidget;
......@@ -33,9 +35,8 @@ import java.io.File;
import java.io.IOException;
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.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -45,42 +46,52 @@ import java.util.logging.Logger;
* @version 2.2.0
*/
@NonNullByDefault
public class TangibleObjectBootstrapper {
private static final Logger logger = Logger.getLogger(TangibleObjectBootstrapper.class.getSimpleName());
public class TangibleObjectBootstrapper extends TangibleObjectManager {
private Document document;
private ArrayList<BaseWidget> objects = new ArrayList<>();
private ArrayList<BaseWidget> cursors = new ArrayList<>();
private ArrayList<BaseWidget> blobs = new ArrayList<>();
/**
* Constructor initializing all fields.
*
* @param document
* The document containing the XML definition of all objects to initialize.
* @param applicationContext
* The {@link TangibleApplication} hosting this manager.
* @param applicationLogger
* The {@link Logger} to use for all logging purposes.
* @param properties
* The properties instance from which to load the default values from.
*/
public TangibleObjectBootstrapper(Document document) {
public TangibleObjectBootstrapper(TangibleApplication applicationContext,
Logger applicationLogger, Properties properties, Document document) {
super(applicationContext, applicationLogger, properties);
this.document = document;
}
/**
* Constructor initializing all fields.
*
* @param fileURI
* @param fileUri
* The URI of the document containing the XML definition of all objects to initialize.
* @param applicationContext
* The {@link TangibleApplication} hosting this manager.
* @param applicationLogger
* The {@link Logger} to use for all logging purposes.
* @param properties
* The properties instance from which to load the default values from.
* @throws BuildException
* Thrown when the provided file URI it not valid or empty.
*/
public TangibleObjectBootstrapper(String fileURI) throws BuildException {
public TangibleObjectBootstrapper(TangibleApplication applicationContext,
Logger applicationLogger, Properties properties, String fileUri) throws BuildException {
super(applicationContext, applicationLogger, properties);
if (Strings.isNullOrEmpty(fileURI)) {
if (Strings.isNullOrEmpty(fileUri)) {
throw new BuildException("The provided file URI may not be null or empty!"); //$NON-NLS-1$
}
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File(fileURI);
File xmlFile = new File(fileUri);
try {
this.document = builder.build(xmlFile);
......@@ -97,7 +108,8 @@ public class TangibleObjectBootstrapper {
* @throws BuildException
* Thrown when one or more of the tangibles failed to build.
*/
public void bootstrap() throws BuildException {
@Override
public void defineWidgets() throws BuildException {
Element rootNode = document.getRootElement();
List<Element> objectRootNodes = rootNode.getChildren(Externalization.OBJECTS_NODE); // $NON-NLS-1$
......@@ -132,12 +144,13 @@ public class TangibleObjectBootstrapper {
try {
for (Element objectNode : objectNodes) {
objects.add(buildObjectFromElement(objectNode));
BaseWidget widget = buildObjectFromElement(objectNode);
widget.getPositions().keySet().forEach(handleId -> objectMap.put(handleId, widget));
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
// TODO add logging and collect all other exceptions.
objects.clear();
objectMap.clear();
throw new BuildException("One of the desired tangibles could not be build! " + e.getMessage(), e); //$NON-NLS-1$
}
}
......@@ -185,21 +198,4 @@ 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
......@@ -30,6 +30,7 @@ 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 BASE_VALUE_NODE;
public static String BLOBS_NODE;
public static String BORDER_THICKNESS_NODE;
public static String BORDER_WIDTH_NODE;
......@@ -61,6 +62,11 @@ public class Externalization extends NLS {
public static String LINE_NODE;
public static String LINE_HEIGHT_RATIO_NODE;
public static String LINE_WIDTH_NODE;
public static String LOWER_BOUND_NODE;
public static String LOWER_STOP_ANGLE_NODE;
public static String MAXIMUM_VALUE_NODE;
public static String MINIMUM_VALUE_NODE;
public static String MODIFY_VALUE_ON_ROTATION_NODE;
public static String NAME_NODE;
public static String NAMESPACE_NODE;
public static String NAMESPACE_SEPARATOR;
......@@ -72,8 +78,12 @@ public class Externalization extends NLS {
public static String SHAPE_NODE;
public static String SPIN_ON_CORONA_CENTRE_NODE;
public static String START_NODE;
public static String STEP_SIZE_NODE;
public static String TEXT_NODE;
public static String TYPE_NODE;
public static String UPPER_BOUND_NODE;
public static String UPPER_STOP_ANGLE_NODE;
public static String VARIABLE_NODE;
public static String WIDGET_BUILDER_NAMESPACE;
static {
......
......@@ -25,10 +25,10 @@ import java.util.logging.Logger;
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.1.0
* @version 2.2.2
*/
public final class PropertiesFetcher {
private static final String TANGIBLE_GIS_PROPERTIES = "properties.properties"; //$NON-NLS-1$
private static final String TANGIBLE_PROPERTIES = "properties.properties"; //$NON-NLS-1$
private static Properties properties;
private static Logger logger = Logger.getLogger(PropertiesFetcher.class.getSimpleName());
......@@ -53,7 +53,7 @@ public final class PropertiesFetcher {
} catch (final IOException e) {
logger.log(Level.INFO, "Proeprties file could not be loaded from external location!"); //$NON-NLS-1$
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PropertiesFetcher.TANGIBLE_GIS_PROPERTIES));
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PropertiesFetcher.TANGIBLE_PROPERTIES));
} catch (final IOException ioe) {
logger.log(Level.SEVERE, "The porperties file could not be loaded!", ioe); //$NON-NLS-1$
}
......@@ -70,7 +70,7 @@ public final class PropertiesFetcher {
* Thrown when the file could not be located or loaded.
*/
private static void loadFromExternalFile() throws IOException {
try (FileInputStream inputStream = new FileInputStream(new File(TANGIBLE_GIS_PROPERTIES))) {
try (FileInputStream inputStream = new FileInputStream(new File(TANGIBLE_PROPERTIES))) {
properties.load(inputStream);
}
}
......
......@@ -16,12 +16,12 @@
*/
package lu.list.itis.dkd.tui.bootstrapping;
import static org.junit.Assert.fail;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
......@@ -34,21 +34,9 @@ import java.io.IOException;
*/
public class TangibleObjectBootstrapperTest {
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* Test method for
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#TangibleObjectBootstrapper(org.jdom2.Document)}
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#TangibleObjectBootstrapper(lu.list.itis.dkd.tui.TangibleApplication, java.util.logging.Logger, java.util.Properties, org.jdom2.Document)}
* .
*
* @throws BuildException
......@@ -60,34 +48,34 @@ public class TangibleObjectBootstrapperTest {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("test/bootstrapping.xml"); //$NON-NLS-1$
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper(builder.build(xmlFile));
bootstrapper.bootstrap();
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper(null, null, null, builder.build(xmlFile));
bootstrapper.defineWidgets();
}
/**
* Test method for
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#TangibleObjectBootstrapper(java.lang.String)}
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#TangibleObjectBootstrapper(lu.list.itis.dkd.tui.TangibleApplication, java.util.logging.Logger, java.util.Properties, String)}
* .
*
* @throws BuildException
*/
@Test
public void testTangibleObjectBootstrapperString() throws BuildException {
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper("test/bootstrapping.xml"); //$NON-NLS-1$
bootstrapper.bootstrap();
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper(null, null, null, "test/bootstrapping.xml"); //$NON-NLS-1$
bootstrapper.defineWidgets();
}
/**
* Test method for
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#bootstrap()}.
* {@link lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper#defineWidgets()}.
*
* @throws BuildException
*/
@Test
public void testBootstrap() throws BuildException {
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper("test/bootstrapping.xml"); //$NON-NLS-1$
bootstrapper.bootstrap();
TangibleObjectBootstrapper bootstrapper = new TangibleObjectBootstrapper(null, null, null, "test/bootstrapping.xml"); //$NON-NLS-1$
bootstrapper.defineWidgets();
// bootstrapper.
fail();
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ package lu.list.itis.dkd.tui.widget.builder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper;
import lu.list.itis.dkd.tui.network.adapter.TcpServer;
import lu.list.itis.dkd.tui.widget.BaseWidget;
......@@ -47,8 +48,8 @@ public class BaseBuilderBootstrappingTest {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("test/baseBuilderBootstrapping.xml"); //$NON-NLS-1$
bootstrapper = new TangibleObjectBootstrapper(builder.build(xmlFile));
bootstrapper.bootstrap();
bootstrapper = new TangibleObjectBootstrapper(null, null, null, builder.build(xmlFile));
bootstrapper.defineWidgets();
}
/**
......@@ -57,9 +58,9 @@ public class BaseBuilderBootstrappingTest {
*/
@Test
public final void testBaseBuilderElement() {
assertEquals(1, bootstrapper.getObjects().size());
assertEquals(4, TangibleObjectManager.getWidgets().size());
BaseWidget widget = bootstrapper.getObjects().get(0);
BaseWidget widget = (BaseWidget) TangibleObjectManager.getWidgets().toArray()[0];
assertEquals(4, widget.getPositions().size());
assertEquals(2, widget.getCoronas().size());
......
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