Commit a6862732 authored by Eric Tobias's avatar Eric Tobias

Added boolean variable and changed the returns of other variables to be able...

Added boolean variable and changed the returns of other variables to be able to more consistently give information not only on the value but also units
parent e896f500
/**
* Copyright Luxembourg Institute of Science and Technology, 2016. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.cps.variable;
import lu.list.itis.dkd.cps.InputChangeListener;
import lu.list.itis.dkd.cps.InputEvent;
import java.util.Vector;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class BooleanVariable extends Variable {
protected boolean value;
/**
* @param name
* @param unit
* @param value
*/
public BooleanVariable(String name, String unit, boolean value) {
super(name, unit);
this.value = value;
}
/** {@inheritDoc} */
@Override
public Boolean getValue() {
return value;
}
/** {@inheritDoc} */
@Override
public void setValue(Object value) {
if (value instanceof Boolean) {
this.value = (Boolean) value;
} else {
this.value = Boolean.parseBoolean(value.toString());
}
for (InputChangeListener listener : listeners) {
listener.inputChanged(new InputEvent(this));
}
}
/** {@inheritDoc} */
@Override
public Variable clone() {
BooleanVariable variable = new BooleanVariable(name, unit, value);
variable.listeners = new Vector<>(listeners);
return variable;
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import lu.list.itis.dkd.dbc.annotation.Nullable;
import org.jdom2.Element;
import java.text.DecimalFormat;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -140,7 +141,7 @@ public class NumericalVariable extends Variable {
public NumericalVariable clone() {
NumericalVariable variable = new NumericalVariable(name, unit, value);
variable.format = format;
variable.listeners = listeners;
variable.listeners = new Vector<>(listeners);
return variable;
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ import org.jdom2.Element;
* @version 1.1.0
*/
@NonNullByDefault
public class TangibleNumericalVariable extends NumericalVariable implements ContextEventListener, InformationProvider<Double> {
public class TangibleNumericalVariable extends NumericalVariable implements ContextEventListener, InformationProvider<String> {
/**
* Constructor resorting to the super constructor to initialise the name and unit and locally
* initialising the numerical value.
......@@ -64,7 +64,7 @@ public class TangibleNumericalVariable extends NumericalVariable implements Cont
/** This method is not supported and will always return the general, position-agnostic value. */
@Override
public Double getInformation(@Nullable Point position) {
public String getInformation(@Nullable Point position) {
return this.getInformation();
}
......@@ -75,7 +75,7 @@ public class TangibleNumericalVariable extends NumericalVariable implements Cont
* This method returns the value.
*/
@Override
public Double getInformation() {
return Double.valueOf(this.value);
public String getInformation() {
return toString();
}
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ import java.awt.Graphics2D;
* @version 2.2.3
*/
@NonNullByDefault
public final class ValueWidget extends BaseWidget implements InformationProvider<Double> {
public final class ValueWidget extends BaseWidget implements InformationProvider<String> {
/** The minimum value to be stored by the widget. */
private double lowerBound;
......@@ -125,14 +125,14 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
/** {@inheritDoc} */
@Override
public @Nullable Double getInformation(Point position) {
public @Nullable String getInformation(Point position) {
return variable.getInformation(position);
}
/** {@inheritDoc} */
@Override
public Double getInformation() {
return variable.getInformation();
public String getInformation() {
return variable.toString();
}
/**
......
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