Commit 173a3e68 authored by Eric Tobias's avatar Eric Tobias

Changed how the Point is initialized form XML to allow for empty coordinates...

Changed how the Point is initialized form XML to allow for empty coordinates to initialize a default point.
parent e4e954a1
......@@ -47,6 +47,7 @@ OBJECT_NODE=object
OBJECTS_NODE=objects
RADIUS_NODE=radius
ROTATE_WITH_HANDLE_NODE=rotateWithHandle
ROTATION_DIRECTION_NODE=rotationDirection
SCALE_NODE=scale
SECTION_NODE=section
SECTIONS_NODE=sections
......@@ -54,6 +55,7 @@ SHAPE_NODE=shape
SPACE=\
SPIN_ON_CORONA_CENTRE_NODE=spinOnCoronaCentre
START_NODE=start
STATE_NODE=state
STEP_SIZE_NODE=stepSize
STOP_NODE=stop
TEXT_NODE=text
......@@ -66,3 +68,6 @@ UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
WIDGET_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.builder
WIDTH_NODE=width
X_NODE=x
Y_NODE=y
Z_NODE=z
......@@ -61,10 +61,10 @@ public class CameraCoordinates extends CoordinateState {
* {@inheritDoc}
*/
@Override
public void toCamera(@NonNull Point context) {/**
* The conversion is naught as the point's
* coordinates are already given in this reference
* scheme!
*/
public void toCamera(@NonNull Point context) {
/**
* The conversion is naught as the point's coordinates are already given in this reference
* scheme!
*/
}
}
\ No newline at end of file
......@@ -62,8 +62,9 @@ public abstract class CoordinateState {
*/
@Override
public boolean equals(Object state) {
if (this == state)
if (this == state) {
return true;
}
if (state instanceof CoordinateState) {
return getClass().getName().equals(((CoordinateState) state).getClass().getName());
......
......@@ -77,6 +77,7 @@ public class Externalization extends NLS {
public static String OBJECTS_NODE;
public static String RADIUS_NODE;
public static String ROTATE_WITH_HANDLE_NODE;
public static String ROTATION_DIRECTION_NODE;
public static String SCALE_NODE;
public static String SECTION_NODE;
public static String SECTIONS_NODE;
......@@ -84,6 +85,7 @@ public class Externalization extends NLS {
public static String SPACE;
public static String SPIN_ON_CORONA_CENTRE_NODE;
public static String START_NODE;
public static String STATE_NODE;
public static String STEP_SIZE_NODE;
public static String STOP_NODE;
public static String TEXT_NODE;
......@@ -96,6 +98,9 @@ public class Externalization extends NLS {
public static String VARIABLE_NODE;
public static String WIDGET_BUILDER_NAMESPACE;
public static String WIDTH_NODE;
public static String X_NODE;
public static String Y_NODE;
public static String Z_NODE;
static {
// initialize resource bundle
......
......@@ -21,6 +21,7 @@ import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.exception.BuildException;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.jdom2.Element;
......@@ -159,29 +160,36 @@ public class Point extends Float {
*
* @param rootNode
* The node that contains, as child nodes, all relevant nodes to initialize the
* corresponding fields.
* corresponding fields. If the node is <code>null</code> then a call to
* {@link Point#Point()} will be issued and the result returned.
* @throws BuildException
* Thrown when one or more of the required parameters for the Point could not be set.
*/
public Point(Element rootNode) throws BuildException {
public Point(@Nullable Element rootNode) throws BuildException {
super();
super(java.lang.Float.parseFloat(rootNode.getChildText("x")), java.lang.Float.parseFloat(rootNode.getChildText("y"))); //$NON-NLS-1$ //$NON-NLS-2$
this.angle = java.lang.Float.parseFloat(rootNode.getChildText("z")); //$NON-NLS-1$
String xCoordinate = Strings.nullToEmpty(rootNode.getChildText(Externalization.X_NODE));
String yCoordinate = Strings.nullToEmpty(rootNode.getChildText(Externalization.Y_NODE));
String angleValue = Strings.nullToEmpty(rootNode.getChildText(Externalization.Z_NODE));
if (rootNode.getChild("state") != null) { //$NON-NLS-1$
this.x = xCoordinate.isEmpty() ? 0f : java.lang.Float.parseFloat(xCoordinate);
this.y = yCoordinate.isEmpty() ? 0f : java.lang.Float.parseFloat(yCoordinate);
this.angle = angleValue.isEmpty() ? 0f : java.lang.Float.parseFloat(angleValue);
if (rootNode.getChild(Externalization.STATE_NODE) != null) {
try {
Class<?> stateClass = Class.forName(Point.class.getPackage().getName() + "." + rootNode.getChildText("state")); //$NON-NLS-1$ //$NON-NLS-2$
Class<?> stateClass = Class.forName(Point.class.getPackage().getName() + "." + rootNode.getChildText(Externalization.STATE_NODE)); //$NON-NLS-1$
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) {
throw new BuildException("The state of the point cannot be resolved for " + rootNode.getChildText("state"), e); //$NON-NLS-1$ //$NON-NLS-2$
throw new BuildException("The state of the point cannot be resolved for " + rootNode.getChildText(Externalization.STATE_NODE), e); //$NON-NLS-1$
}
} else {
state = new CameraCoordinates(this, x, y);
}
if (rootNode.getChild("rotationDirection") != null) { //$NON-NLS-1$
rotationDirection = java.lang.Float.parseFloat(rootNode.getChildText("rotationDirection")); //$NON-NLS-1$
if (rootNode.getChild(Externalization.ROTATION_DIRECTION_NODE) != null) {
rotationDirection = java.lang.Float.parseFloat(rootNode.getChildText(Externalization.ROTATION_DIRECTION_NODE));
}
}
......@@ -238,7 +246,12 @@ public class Point extends Float {
public static boolean areEqual(Point a, Point b) {
if (a.getState().getClass().equals(b.getState().getClass())) {
/**
* A B A AND B 1 0 0 1 1 1 0 0 0 0 1 0
* @formatter:off
* A B A AND B
* 1 0 0 1
* 1 1 0 0
* 0 0 1 0
* @formatter:on
*/
return java.lang.Float.compare(a.x, b.x) == 0 && java.lang.Float.compare(a.y, b.y) == 0;
}
......@@ -365,14 +378,16 @@ public class Point extends Float {
* @pre point.state equal to state iff point != null
*/
public Point subtract(@Nullable Point point, boolean subtractAngle) {
if (point == null)
if (point == null) {
return this;
}
Preconditions.checkArgument(point.getState().getClass().getName().equals(state.getClass().getName()));
Point clone = clone();
clone.setLocation(clone.x - point.x, clone.y - point.y);
if (subtractAngle)
if (subtractAngle) {
clone.angle -= point.angle;
}
return clone;
}
......@@ -390,18 +405,20 @@ public class Point extends Float {
* @see #clone()
*/
public Point delta(@Nullable Point point) {
if (point == null)
if (point == null) {
return clone();
}
if (rotationDirection > 0) {
// TODO Do something meaningful with the rotation direction.
}
double lastRotation = angle - point.getAngle();
if (lastRotation > 1.5 * Math.PI)
if (lastRotation > 1.5 * Math.PI) {
lastRotation -= 2 * Math.PI;
else if (lastRotation < -1.5 * Math.PI)
} else if (lastRotation < -1.5 * Math.PI) {
lastRotation += 2 * Math.PI;
}
return new Point((float) (getX() - point.getX()), (float) (getY() - point.getY()), (float) lastRotation, rotationDirection);
}
......
......@@ -53,11 +53,11 @@ public class ScreenCoordinates extends CoordinateState {
* {@inheritDoc}
*/
@Override
public void toScreen(@NonNull Point context) {/**
* The conversion is naught as the point's
* coordinates are already given in this reference
* scheme!
*/
public void toScreen(@NonNull Point context) {
/**
* The conversion is naught as the point's coordinates are already given in this reference
* scheme!
*/
}
/**
......
......@@ -45,11 +45,11 @@ public class TableCoordinates extends CoordinateState {
* {@inheritDoc}
*/
@Override
public void toTable(@NonNull Point context) {/**
* The conversion is naught as the point's
* coordinates are already given in this reference
* scheme!
*/
public void toTable(@NonNull Point context) {
/**
* The conversion is naught as the point's coordinates are already given in this reference
* scheme!
*/
}
/**
......
......@@ -51,13 +51,13 @@ public class Gauge extends Corona implements InformationReceiver<Double> {
width = (int) builder.width;
height = (int) builder.height;
sections = builder.sections;
scale = builder.scale;
rendered = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
gauge = new Radial();
gauge.setMinValue(builder.lowerBound);
gauge.setMaxValue(builder.upperBound);
gauge.setFrameType(FrameType.ROUND);
gauge.setVisible(true);
gauge.setSize(width, height);
gauge.setTitle(builder.title);
gauge.setUnitString(builder.unit);
gauge.setLedVisible(false);
......@@ -66,18 +66,10 @@ public class Gauge extends Corona implements InformationReceiver<Double> {
if (sections != null) {
gauge.setSectionsVisible(true);
Section[] sectionArray = new Section[sections.size()];
int index = 0;
for (Section section : sections) {
sectionArray[index++] = section;
}
gauge.setSections(sectionArray);
gauge.setSections(sections.toArray(new Section[sections.size()]));
}
this.scale = builder.scale;
rendered = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
gauge.setSize(width, height);
gauge.setVisible(true);
}
......
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