@Override public void addActor(ActorAddEvent event) { Actor actor = event.actor; StringBuilder item_name = new StringBuilder(); item_name.append(actor.getName()==null?"":actor.getName()); item_name.append("["); item_name.append(EditorManager.getInstance() .getActorType(actor).getSimpleName()); item_name.append("]"); Tree.Node item = createNodeItem(actor,item_name.toString()); item.setIcon(new TextureRegionDrawable(new TextureRegion(new Texture( Gdx.files.internal("icon/Label_16.png"))))); item.getActor().setTouchable(Touchable.disabled); if (actor.getParent() instanceof MainWindow){ stageNode.add(item); }else { Tree.Node parentNode = stageNode.findNode(actor.getParent()); if (parentNode!=null) parentNode.add(item); } tree.getSelection().choose(item); }
@Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (tree.getStage().hit(x, y, true) == tree && tree.getNodeAt(y) != null){ tree.getClickListener().clicked(event,x,y); tree.getClickListener().cancel(); Array<Actor> actors = new Array<>(); for (Tree.Node node:tree.getSelection().items() ) { actors.add((Actor) node.getObject()); } if (actors.size>0){ EditorManager.getInstance().getEventBus().post(new TreeSelectedActroEvent(actors)); }else { EditorManager.getInstance().getEventBus().post(new TreeCancelEvent()); } } return false; }
private void fillNode(Tree.Node node, String samplerId) { AbstractSampler sampler = loader.getSampler(samplerId); SamplerNode subNode = createNode(samplerId); if (subNode != null) { node.add(subNode); if (expansionMemory.containsKey(subNode.nodeId)) { subNode.setExpanded(expansionMemory.get(subNode.nodeId)); } if (sampler.getConfig() instanceof AbstractSamplerContainerConfig) { AbstractSamplerContainerConfig c = (AbstractSamplerContainerConfig) sampler.getConfig(); for (ChildSamplerConfig child : c.getChildSamplerConfigs()) { fillNode(subNode, child.samplerReferenceId); } } } }
/** @param child will be added to the actor casted to a Group or a Table. */ protected void addChild(final Actor child) { final Actor actor = getActor(); if (actor instanceof Tree) { final Tree.Node node = LmlUtilities.getTreeNode(child); if (node != null) { ((Tree) actor).add(node); } else { ((Tree) actor).add(new Tree.Node(child)); } } else if (actor instanceof Table) { LmlUtilities.getCell(child, (Table) actor); } else { ((Group) actor).addActor(child); } }
@Override public final void handleDataBetweenTags(final CharSequence rawData) { if (Strings.isWhitespace(rawData)) { return; } final String[] lines = Strings.split(rawData, '\n'); final Tree.Node node = LmlUtilities.getTreeNode(actor); if (node != null) { appendTreeNodes(lines, node); return; } for (String line : lines) { if (Strings.isNotWhitespace(line)) { line = line.trim(); handlePlainTextLine(line); } } }
@Override public void handleChild(final LmlTag childTag) { if (childTag.isAttachable()) { // Child tag is an attachable object that can be appended to any widget, even if it is not prepared to // handle children. For example, tooltip tag can be nested inside a label and will be properly attached, // even though label wouldn't know how to handle a normal child, like a button or another label. if (actor != null) { childTag.attachTo(this); } } else if (childTag.getActor() != null) { final Tree.Node node = LmlUtilities.getTreeNode(actor); if (node != null) { // This actor is a tree node. Adding its child as a leaf. Tree.Node childNode = LmlUtilities.getTreeNode(childTag.getActor()); if (childNode == null) { childNode = new Tree.Node(childTag.getActor()); } node.add(childNode); } else { handleValidChild(childTag); } } }
public static void setup(){ registerSerializer(Actor.class, new ActorSerializer()); registerSerializer(Scene.class, new SceneSerializer()); registerSerializer(ImageJson.class, new ImageJson()); registerSerializer(Label.class, new LabelSerializer()); registerSerializer(Button.class, new ButtonSerializer()); registerSerializer(TextButton.class, new TextButtonSerializer()); registerSerializer(Table.class, new TableSerializer()); registerSerializer(CheckBox.class, new CheckBoxSerializer()); registerSerializer(SelectBox.class, new SelectBoxSerializer()); registerSerializer(List.class, new ListSerializer()); registerSerializer(Slider.class, new SliderSerializer()); registerSerializer(TextField.class, new TextFieldSerializer()); registerSerializer(Touchpad.class, new TouchpadSerializer()); registerSerializer(Sprite.class, new SpriteSerializer()); registerSerializer(Dialog.class, new DialogSerializer()); registerSerializer(SplitPane.class, new SplitPaneSerializer()); registerSerializer(ScrollPane.class, new ScrollPaneSerializer()); registerSerializer(Stack.class, new StackSerializer()); registerSerializer(Tree.class, new TreeSerializer()); registerSerializer(Table.class, new TableSerializer()); registerSerializer(ButtonGroup.class, new ButtonGroupSerializer()); registerSerializer(HorizontalGroup.class, new HorizontalGroupSerializer()); registerSerializer(VerticalGroup.class, new VerticalGroupSerializer()); }
private Tree.Node createNodeItem(Object object, String title){ VisLabel label = new VisLabel(title); Tree.Node node = new Tree.Node(label); node.setObject(object); return node; }
@Override public void sureActor(SureActorEvent sureActorEvent) { Tree.Node selectedNode = tree.findNode(sureActorEvent.actor); if (selectedNode !=null && !tree.getSelection().contains(selectedNode)){ tree.getSelection().choose(selectedNode); } }
@Override public void setActorName(ActorNameEvent event) { Tree.Node item = tree.getSelection().getLastSelected(); if (item!=null){ Actor actor = (Actor) item.getObject(); StringBuilder item_name = new StringBuilder(); item_name.append(event.name); item_name.append("["); item_name.append(EditorManager.getInstance() .getActorType(actor).getSimpleName()); item_name.append("]"); ((Label)item.getActor()).setText(item_name.toString()); } }
@Override public void keyDel(KeyDelEvent event) { if (tree.getSelection().size()>0){ for (Tree.Node node : tree.getSelection().items()){ if (node.getObject() instanceof Actor){ ((Actor) node.getObject()).remove(); } tree.remove(node); } tree.getSelection().clear(); } }
@Override protected AbstractPanel ui() { configTree = new Tree(skin); configScroller = new ScrollPane(configTree, skin); addActor(configScroller); return this; }
@Override protected AbstractPanel ui() { if(gameWorld.hasLandscape()) { this.terrain = gameWorld.terrain; configTree = new Tree(skin); configScroller = new ScrollPane(configTree); addActor(configScroller); return this; } this.terrain = null; addActor(addLandscapeBtn = new TextButton("Add landscape", skin)); return this; }
@Override public void visitData(Visitable<GDXComponentBuilder.AttributeWrapper> visitable, GDXComponentBuilder.AttributeWrapper data) { if(true) return; if(data.attr != null) { Object compObj = GDXComponentBuilder.instance().buildComponent(data.attr); if(compObj instanceof Actor) { Tree.Node node = new Tree.Node((Actor)compObj); this.node.add(node); float compWidth = tree.getWidth() - 192; ((Actor) compObj).setWidth(compWidth-30); } } cat = data.name+": "+data.path; }
public void memory(Tree.Node node) { if (node instanceof SamplerNode) { SamplerNode sn = (SamplerNode) node; if (expansionMemory.containsKey(sn.nodeId)) { expansionMemory.remove(sn.nodeId); } expansionMemory.put(sn.nodeId, sn.isExpanded()); } for (Tree.Node n : node.getChildren()) { memory(n); } }
private void loadTree(Opus opus, Samplers loader) { if (tree.getNodes() != null) { for (Tree.Node n : tree.getNodes()) { memory(n); } } tree.clearChildren(); for (Layer l : opus.getLayers()) { addLayer(l); } tree.pack(); expansionMemory.clear(); pack(); Editor.post(new CommandLimitWindowSizes()); }
private void addChild(final Actor child) { final Tree.Node node = LmlUtilities.getTreeNode(child); if (node != null) { getTree().add(node); } else { getTree().add(new Tree.Node(child)); } }
private void appendTreeNodes(final String[] lines, final Tree.Node node) { for (String line : lines) { if (Strings.isNotWhitespace(line)) { line = line.trim(); node.add(new Tree.Node(toLabel(line))); } } }
/** @param actor is supposed to become a tree node. * @param parent optional actor's parent, used to validate if the actor can be a tree node (it has to have a tree * parent in the structure). * @param parser used to parse the actor. */ public void prepareTreeNode(final Actor actor, final LmlTag parent, final LmlParser parser) { if (parent == null) { parser.throwErrorIfStrict("Actor cannot be tree node if it has no parent."); return; } else if (!hasTreeParent(parent)) { parser.throwErrorIfStrict("Actor cannot be a tree node if it has no tree parent in the structure."); return; } node = new Tree.Node(actor); }
private static boolean hasTreeParent(LmlTag parent) { while (parent != null) { if (parent.getActor() instanceof Tree) { return true; } parent = parent.getParent(); } return false; }
/** @param actor might be a tree node. * @return tree node containing the actor if it is a tree node or null. */ public static Tree.Node getTreeNode(final Actor actor) { final LmlUserObject userObject = getOptionalLmlUserObject(actor); if (userObject != null) { return userObject.getNode(); } return null; }
public void create () { stage = new Stage(); Gdx.input.setInputProcessor(stage); Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); Table table = new Table(); table.setFillParent(true); stage.addActor(table); final Tree tree = new Tree(skin); final Node moo1 = new Node(new TextButton("moo1", skin)); final Node moo2 = new Node(new TextButton("moo2", skin)); final Node moo3 = new Node(new TextButton("moo3", skin)); final Node moo4 = new Node(new TextButton("moo4", skin)); final Node moo5 = new Node(new TextButton("moo5", skin)); tree.add(moo1); tree.add(moo2); moo2.add(moo3); moo3.add(moo4); tree.add(moo5); moo5.getActor().addListener(new ClickListener() { public void clicked (InputEvent event, float x, float y) { tree.remove(moo4); } }); table.add(tree).fill().expand(); }
private void addNormalWidgets () { Skin skin = VisUI.getSkin(); Tree tree = new Tree(skin); Node item1 = new Node(new Label("item 1", skin)); Node item2 = new Node(new Label("item 2", skin)); Node item3 = new Node(new Label("item 3", skin)); item1.add(new Node(new Label("item 1.1", skin))); item1.add(new Node(new Label("item 1.2", skin))); item1.add(new Node(new Label("item 1.3", skin))); item2.add(new Node(new Label("item 2.1", skin))); item2.add(new Node(new Label("item 2.2", skin))); item2.add(new Node(new Label("item 2.3", skin))); item3.add(new Node(new Label("item 3.1", skin))); item3.add(new Node(new Label("item 3.2", skin))); item3.add(new Node(new Label("item 3.3", skin))); item1.setExpanded(true); tree.add(item1); tree.add(item2); tree.add(item3); add(tree).expand().fill(); }
private int addToTree (Tree displayTree, TaskNode parentNode, Task<E> task, IntArray taskSteps, int taskStepIndex) { TaskNode node = new TaskNode(task, this, taskSteps == null ? step - 1 : taskSteps.get(taskStepIndex), getSkin()); taskNodes.put(task, node); if (parentNode == null) { displayTree.add(node); } else { parentNode.add(node); } taskStepIndex++; for (int i = 0; i < task.getChildCount(); i++) { Task<E> child = task.getChild(i); taskStepIndex = addToTree(displayTree, node, child, taskSteps, taskStepIndex); } return taskStepIndex; }
public void resetProperties() { properties.clear(); if (clazz.equals(Button.class)) { newStyleProperties(ButtonStyle.class); } else if (clazz.equals(CheckBox.class)) { newStyleProperties(CheckBoxStyle.class); properties.get("checkboxOn").optional = false; properties.get("checkboxOff").optional = false; properties.get("font").optional = false; } else if (clazz.equals(ImageButton.class)) { newStyleProperties(ImageButtonStyle.class); } else if (clazz.equals(ImageTextButton.class)) { newStyleProperties(ImageTextButtonStyle.class); properties.get("font").optional = false; } else if (clazz.equals(Label.class)) { newStyleProperties(LabelStyle.class); properties.get("font").optional = false; } else if (clazz.equals(List.class)) { newStyleProperties(ListStyle.class); properties.get("font").optional = false; properties.get("fontColorSelected").optional = false; properties.get("fontColorUnselected").optional = false; properties.get("selection").optional = false; } else if (clazz.equals(ProgressBar.class)) { newStyleProperties(ProgressBarStyle.class); //Though specified as optional in the doc, there are bugs without "background" being mandatory properties.get("background").optional = false; } else if (clazz.equals(ScrollPane.class)) { newStyleProperties(ScrollPaneStyle.class); } else if (clazz.equals(SelectBox.class)) { newStyleProperties(SelectBoxStyle.class); properties.get("font").optional = false; properties.get("fontColor").optional = false; properties.get("scrollStyle").optional = false; properties.get("scrollStyle").value = "default"; properties.get("listStyle").optional = false; properties.get("listStyle").value = "default"; } else if (clazz.equals(Slider.class)) { newStyleProperties(SliderStyle.class); //Though specified as optional in the doc, there are bugs without "background" being mandatory properties.get("background").optional = false; } else if (clazz.equals(SplitPane.class)) { newStyleProperties(SplitPaneStyle.class); properties.get("handle").optional = false; } else if (clazz.equals(TextButton.class)) { newStyleProperties(TextButtonStyle.class); properties.get("font").optional = false; } else if (clazz.equals(TextField.class)) { newStyleProperties(TextFieldStyle.class); properties.get("font").optional = false; properties.get("fontColor").optional = false; } else if (clazz.equals(TextTooltip.class)) { newStyleProperties(TextTooltipStyle.class); properties.get("label").optional = false; properties.get("label").value = "default"; } else if (clazz.equals(Touchpad.class)) { newStyleProperties(TouchpadStyle.class); } else if (clazz.equals(Tree.class)) { newStyleProperties(TreeStyle.class); properties.get("plus").optional = false; properties.get("minus").optional = false; } else if (clazz.equals(Window.class)) { newStyleProperties(WindowStyle.class); properties.get("titleFont").optional = false; } }
public GDXSetBuilderVisitor(Tree tree, Tree.Node node, Skin skin) { this(tree, node, skin, "root"); }
public GDXSetBuilderVisitor(Tree tree, Tree.Node node, Skin skin, String cat) { this.tree = tree; this.node = node; this.skin = skin; this.cat = cat; }
@Override public Class<Tree> getHandledType() { return Tree.class; }
@Override public void process(final LmlParser parser, final LmlTag tag, final Tree actor, final String rawAttributeData) { actor.setPadding(parser.parseFloat(rawAttributeData, actor)); }
@Override public void process(final LmlParser parser, final LmlTag tag, final Tree actor, final String rawAttributeData) { actor.setYSpacing(parser.parseFloat(rawAttributeData, actor)); }
@Override public void process(final LmlParser parser, final LmlTag tag, final Tree actor, final String rawAttributeData) { final float spacing = parser.parseFloat(rawAttributeData, actor); actor.setIconSpacing(spacing, spacing); }
@Override protected Actor getNewInstanceOfActor(final LmlActorBuilder builder) { return new Tree(getSkin(builder), builder.getStyleName()); }
/** @return casted actor. */ protected Tree getTree() { return (Tree) getActor(); }
/** @return non-null tree node containing the actor or null if the actor is not a tree node. */ public Tree.Node getNode() { return node; }
@Override public Group read(Json json, JsonValue jv, Class arg2) { Tree label = new Tree(Asset.skin); readGroup(jv, label); return label; }