Commit 896664ba authored by Eric Tobias's avatar Eric Tobias

Added a boolean to the Textbox to trigger whether the textbox will react to...

Added a boolean to the Textbox to trigger whether the textbox will react to inputs from the implemented interfaces. Reflected change in the builder as well.
parent 173a3e68
......@@ -51,6 +51,8 @@ public class TextBox extends Corona implements ContextEventListener, Information
private Color colour = Color.BLACK;
private boolean centred = false;
private int lineWidth = 20;
/** Whether the text is assignable, that is, reacting to context or information updates. */
public boolean assignable = true;
/**
* Constructor initialising all fields by the supplied builder.
......@@ -66,6 +68,7 @@ public class TextBox extends Corona implements ContextEventListener, Information
colour = builder.colour;
centred = builder.centred;
lineWidth = builder.lineWidth;
assignable = builder.assignable;
}
/**
......@@ -112,12 +115,18 @@ public class TextBox extends Corona implements ContextEventListener, Information
*/
@Override
public void setInformation(String information) {
text = information;
if (assignable) {
text = information;
}
}
/** {@inheritDoc} */
@Override
public void contextUpdated(ContextEvent event) throws UnsupportedInformationException {
if (!assignable) {
return;
}
if (event.getInformation() instanceof String || event.getInformation() instanceof Number) {
text = event.getInformation().toString();
} else {
......
......@@ -58,6 +58,8 @@ public abstract class BaseTextBoxBuilder<B extends BaseTextBoxBuilder<B>> extend
public boolean centred = false;
/** The maximum width of any written line. */
public int lineWidth = 20;
/** Whether the text is assignable, that is, reacting to context or information updates. */
public boolean assignable = true;
/**
* Constructor setting the centre of the corona.
......@@ -127,6 +129,11 @@ public abstract class BaseTextBoxBuilder<B extends BaseTextBoxBuilder<B>> extend
throw new BuildException("The provided line width must be an integer value!", nfe); //$NON-NLS-1$
}
Element assignabledNode = rootElement.getChild("assignable");
if (null != assignabledNode) {
assignable = Boolean.parseBoolean(assignabledNode.getText());
}
text = Strings.nullToEmpty(rootElement.getChildText(Externalization.TEXT_NODE));
}
......@@ -226,4 +233,10 @@ public abstract class BaseTextBoxBuilder<B extends BaseTextBoxBuilder<B>> extend
this.lineWidth = width;
return (B) this;
}
@SuppressWarnings("unchecked")
public B isAssignable(boolean isAssignable) {
this.assignable = isAssignable;
return (B) this;
}
}
\ No newline at end of file
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