use of org.terasology.rendering.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.
the class NUIEditorNodeUtils method createNewScreen.
/**
* @return The {@link JsonTree} to be used as an initial screen template within {@link NUIEditorScreen}.
*/
public static JsonTree createNewScreen() {
JsonTree tree = new JsonTree(new JsonTreeValue(null, null, JsonTreeValue.Type.OBJECT));
tree.addChild(new JsonTreeValue("type", "PlaceholderScreen", JsonTreeValue.Type.KEY_VALUE_PAIR));
tree.addChild(new JsonTreeValue("skin", "engine:default", JsonTreeValue.Type.KEY_VALUE_PAIR));
JsonTree layout = new JsonTree(new JsonTreeValue("contents", null, JsonTreeValue.Type.OBJECT));
layout.addChild(new JsonTreeValue("type", "RelativeLayout", JsonTreeValue.Type.KEY_VALUE_PAIR));
JsonTree contents = new JsonTree(new JsonTreeValue("contents", null, JsonTreeValue.Type.ARRAY));
JsonTree label = createNewWidget("UILabel", "sampleLabel", true);
label.addChild(new JsonTreeValue("text", SAMPLE_LABEL_TEXT, JsonTreeValue.Type.KEY_VALUE_PAIR));
contents.addChild(label);
layout.addChild(contents);
tree.addChild(layout);
return tree;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.
the class NUIEditorTextEntryBuilder method createValueEditor.
/**
* @return A {@link UITextEntry} to be used to edit a JSON value node.
*/
public static UITextEntry<JsonTree> createValueEditor() {
UITextEntry.Formatter<JsonTree> formatter = value -> value.getValue().toString();
UITextEntry.Parser<JsonTree> parser = value -> {
try {
Double valueDouble = Double.parseDouble(value);
return new JsonTree(new JsonTreeValue(null, valueDouble, JsonTreeValue.Type.VALUE));
} catch (NumberFormatException e) {
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
return new JsonTree(new JsonTreeValue(null, Boolean.parseBoolean(value), JsonTreeValue.Type.VALUE));
} else {
return new JsonTree(new JsonTreeValue(null, value, JsonTreeValue.Type.VALUE));
}
}
};
return createEditorEntry(formatter, parser);
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.
the class NUIEditorTextEntryBuilder method createArrayEditor.
/**
* @return A {@link UITextEntry} to be used to edit a JSON array node.
*/
public static UITextEntry<JsonTree> createArrayEditor() {
UITextEntry.Formatter<JsonTree> formatter = value -> value.getValue().getKey();
UITextEntry.Parser<JsonTree> parser = value -> new JsonTree(new JsonTreeValue(value, null, JsonTreeValue.Type.ARRAY));
return createEditorEntry(formatter, parser);
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.
the class JsonEditorTreeView method undo.
/**
* Sets the widget's state to the previous item in the history.
*
* @return true if the widget's state was changed, false otherwise.
*/
public boolean undo() {
if (historyPosition > 0) {
historyPosition--;
JsonTree node = (JsonTree) history.get(historyPosition).copy();
setTreeViewModel(node, false);
return true;
}
return false;
}
use of org.terasology.rendering.nui.widgets.treeView.JsonTree in project Terasology by MovingBlocks.
the class JsonEditorTreeView method redo.
/**
* Sets the widget's state to the next item in the history.
*
* @return true if the widget's state was changed, false otherwise.
*/
public boolean redo() {
if (historyPosition < history.size() - 1) {
historyPosition++;
JsonTree node = (JsonTree) history.get(historyPosition).copy();
setTreeViewModel(node, false);
return true;
}
return false;
}
Aggregations