Commit 4d7ee192 authored by Nico Mack's avatar Nico Mack

Removed obsolete TangibleNumericalVariable

Added GenericVariable
parent ca380adf
......@@ -5,6 +5,7 @@ TEXT_VARIABLE_CLASS=text.variable.class
SPATIAL_VARIABLE_CLASS=spatial.variable.class
VECTOR_VARIABLE_CLASS=vector.variable.class
MAP_VARIABLE_CLASS=map.variable.class
GENERIC_VARIABLE_CLASS=generic.variable.class
EXECUTOR_NAMESPACE=lu.list.itis.dkd.tui.cps.system.executor
NAMESPACE_SEPARATOR=.
......
......@@ -190,6 +190,16 @@ public class EquationSystemBuilder {
String variableClass = "undefined"; //$NON-NLS-1$
try {
switch (type) {
case EquationSystemBundle.GENERIC_TYPE:
variableClass = properties.getProperty(EquationSystemBundle.GENERIC_VARIABLE_CLASS);
variable = (Variable<T>) Class.forName(variableClass)
.getConstructor(String.class)
.newInstance(name);
if (!Strings.isNullOrEmpty(value))
variable.setValue(variable.valueFromString(value));
break;
case EquationSystemBundle.LOGIC_TYPE:
default:
......@@ -439,9 +449,9 @@ public class EquationSystemBuilder {
// ---------------------------------------------------------------------------
/**
* Checks whether the specified equation creates a dependency cycle. Dependency cycles occur when
* two equations are mutually dependent, i.e. equation 1 has an input parameter being the result of
* equation 2 and vice versa.
* Checks whether the specified equation creates a dependency cycle. Dependency cycles occur
* when two equations are mutually dependent, i.e. equation 1 has an input parameter being the
* result of equation 2 and vice versa.
*
* @param equation
* specifies the XML node representing the equation
......@@ -474,8 +484,8 @@ public class EquationSystemBuilder {
// ---------------------------------------------------------------------------
/**
* Checks whether all defined output variables are connected to a corresponding equation to get the
* values from.
* Checks whether all defined output variables are connected to a corresponding equation to get
* the values from.
*
* @return <code>true</code> if all output variables are assigned to an equation.
*/
......@@ -861,8 +871,8 @@ public class EquationSystemBuilder {
* @param equationFile
* The file containing the XML representation of the equation system.
* @throws EquationSystemException
* Thrown when the file is <code>null</code>, does not exist, or if a required tag to parse
* the file correctly is missing.
* Thrown when the file is <code>null</code>, does not exist, or if a required tag to
* parse the file correctly is missing.
*/
// ---------------------------------------------------------------------------
......@@ -895,10 +905,11 @@ public class EquationSystemBuilder {
* Method used to build an equation system from a provided element.
*
* @param element
* The element holding, as child elements, the required data to build the equation system.
* The element holding, as child elements, the required data to build the equation
* system.
* @throws EquationSystemException
* Thrown when an error in the equation system specification prevented the equation system
* from being built.
* Thrown when an error in the equation system specification prevented the equation
* system from being built.
*/
// ---------------------------------------------------------------------------
......
......@@ -41,6 +41,7 @@ public class EquationSystemBundle extends NLS {
public static String SPATIAL_VARIABLE_CLASS;
public static String VECTOR_VARIABLE_CLASS;
public static String MAP_VARIABLE_CLASS;
public static String GENERIC_VARIABLE_CLASS;
public static String CONNECTORS_ELEMENT;
public static String CONNECTOR_ELEMENT;
......@@ -88,6 +89,7 @@ public class EquationSystemBundle extends NLS {
public static final String TEXT_TYPE = "text";
public static final String VECTOR_TYPE = "vector";
public static final String MAP_TYPE = "map";
public static final String GENERIC_TYPE = "generic";
public static final String ISOLATED_VALUE = "isolated";
......@@ -97,5 +99,6 @@ public class EquationSystemBundle extends NLS {
NLS.initializeMessages(BUNDLE_NAME, EquationSystemBundle.class);
}
private EquationSystemBundle() {}
private EquationSystemBundle() {
}
}
......@@ -18,28 +18,43 @@
* 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.cps.variable.tangible;
package lu.list.itis.dkd.tui.cps.variable;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.event.ContextEvent;
import lu.list.itis.dkd.tui.event.ContextEventListener;
import lu.list.itis.dkd.tui.exception.UnsupportedInformationException;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Vector;
/**
* Class extending the {@link NumericalVariable} by implementing an interface,
* {@link ContextEventListener} which enables the variable to directly listen to changes pushed by a
* tangible component.
* Class implementing a generic variables as handled by the {@link System}.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 1.3.0
* @author Nico Mack [nico.mack@list.lu]
* @since 1.7.0
* @version 1.0.0
*/
@NonNullByDefault
public class TangibleNumericalVariable extends NumericalVariable implements ContextEventListener, InformationProvider<Double> {
public class GenericVariable extends Variable<Object> {
private Object initialValue;
private static final Logger LOGGER = LoggerFactory.getLogger(GenericVariable.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public GenericVariable(String name) {
super(EquationSystemBundle.TEXT_TYPE, name);
this.value = EquationSystemBundle.EMPTY_STRING;
}
// ---------------------------------------------------------------------------
/**
* Constructor resorting to the super constructor to initialise the name and unit and locally
* initialising the numerical value.
......@@ -51,45 +66,89 @@ public class TangibleNumericalVariable extends NumericalVariable implements Cont
* @param value
* The value held by the variable.
*/
public TangibleNumericalVariable(String name, String unit, double value) {
super(name, unit, value);
// ---------------------------------------------------------------------------
public GenericVariable(String name, Object value) {
super(EquationSystemBundle.TEXT_TYPE, name, EquationSystemBundle.EMPTY_STRING);
initialValue = value;
this.clear();
}
/**
* Constructor resorting to the super constructor to initialise the name and unit and locally
* initialising the numerical value.
* {@inheritDoc}<br>
* <br>
*
* @param rootElement
* The root element of the variable containing, as text on child elements, all the
* necessary information to initialize the variable.
* The method constructs a string separating the value and the unit with a space.
*/
// public TangibleNumericalVariable(Element rootElement) {
// super(rootElement);
// }
/** {@inheritDoc} */
@Override
public void contextUpdated(ContextEvent event) throws UnsupportedInformationException {
if (event.getInformation() == null) {
throw new UnsupportedInformationException("Null information cannot be set!"); //$NON-NLS-1$
}
setValue(this.valueFromString(event.getInformation().toString()));
public String toString() {
return (this.value != null) ? this.value.toString() : "null";
}
/** This method is not supported and will always return the general, position-agnostic value. */
/**
* {@inheritDoc}<br>
* <br>
*
* The hash code is based on the <code>toString()</code> representation of this class.
*/
@Override
public Double getInformation(@Nullable Point position) {
return this.getInformation();
public int hashCode() {
return toString().hashCode();
}
/**
* {@inheritDoc}<br>
* <br>
*
* This method returns the value.
* The equality test is base on equality of name, unit, and value.
*/
@Override
public Double getInformation() {
return Double.valueOf(this.value);
public boolean equals(@Nullable Object object) {
if (object == null)
return false;
if (object == this)
return true;
if (object instanceof GenericVariable) {
GenericVariable variable = (GenericVariable) object;
if (name.equals(variable.getName()) && unit.equals(variable.getUnit()) && variable.getValue().equals(value)) {
return true;
}
}
return false;
}
/** {@inheritDoc} */
@Override
public void setValueFromObject(Object object) {
this.setValue(this.valueFromObject(object));
}
@Override
public void clear() {
this.setValue(this.initialValue);
}
/** {@inheritDoc} */
@Override
public GenericVariable clone() {
GenericVariable variable = new GenericVariable(name, value);
variable.listeners = new Vector<>(listeners);
return variable;
}
/** {@inheritDoc} */
@Override
public Object valueFromString(String stringValue) {
return stringValue;
}
@Override
public Object valueFromObject(Object objectValue) {
return objectValue;
}
}
\ No newline at end of file
......@@ -237,6 +237,11 @@ public class ColourScale<T extends Comparable<T>> {
return this.labelColour;
}
// ---------------------------------------------------------------------------
public Color getDefaultColour() {
return this.defaultColour;
}
// ---------------------------------------------------------------------------
......
......@@ -3,8 +3,8 @@ package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable;
import lu.list.itis.dkd.tui.feature.tether.Tetherable;
import lu.list.itis.dkd.tui.widget.builder.GaugeWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.Gauge;
......@@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
// ***************************************************************************
public class GaugeWidget extends TetherableWidget implements InputChangeListener, InformationReceiver<Double> {
private TangibleNumericalVariable variable;
private NumericalVariable variable;
// ***************************************************************************
// * Constants *
......
......@@ -417,6 +417,11 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
connected.addAll(display.connectWithSystemVariables(systemVariables));
}
List<VariableBased> handlers = this.getHandlers(VariableBased.class);
for (VariableBased handler : handlers) {
connected.addAll(handler.connectWithSystemVariables(systemVariables));
}
if ((systemVariables != null) && systemVariables.containsKey(this.variable.getName())) {
NumericalVariable numeric = Variable.castTo(systemVariables.get(this.variable.getName()), NumericalVariable.class);
if (numeric != null) {
......
......@@ -4,7 +4,7 @@ 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.VariableBootstrapper;
import lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.widget.GaugeWidget;
......@@ -24,7 +24,7 @@ import org.jdom2.Element;
// ***************************************************************************
public abstract class BaseGaugeWidgetBuilder<B extends BaseGaugeWidgetBuilder<B>> extends BaseTetherableBuilder<B> {
public TangibleNumericalVariable variable;
public NumericalVariable variable;
// ***************************************************************************
// * Constants *
......@@ -52,7 +52,7 @@ public abstract class BaseGaugeWidgetBuilder<B extends BaseGaugeWidgetBuilder<B>
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
variable = (TangibleNumericalVariable) VariableBootstrapper.buildVariableFromElement(rootElement.getChild(CpsNamespace.VARIABLE_NODE), context, callback);
variable = (NumericalVariable) VariableBootstrapper.buildVariableFromElement(rootElement.getChild(CpsNamespace.VARIABLE_NODE), context, callback);
}
// ---------------------------------------------------------------------------
......@@ -71,7 +71,7 @@ public abstract class BaseGaugeWidgetBuilder<B extends BaseGaugeWidgetBuilder<B>
* The instance to set.
* @return An instance of this builder for chain calling.
*/
public B withVariable(TangibleNumericalVariable variable) {
public B withVariable(NumericalVariable variable) {
this.variable = variable;
return (B) this;
}
......
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