/** * Build the components and its children in this recursive array. * * @param parent The parent component. * @param components The child component list. */ public void build(Component parent, List<Component> components) { if (parent.getDefinition().getParentId() != -1) { components .stream() .filter( component -> component.getDefinition().getFullWidgetId() == parent.getDefinition().getParentId()) .forEach( component -> { component.add(parent); build(component, parent.getList()); }); } }
/** * Draw all components and its children. * * @param repository The cache repository. * @param parent The parent component. */ public void draw(CacheRepository repository, Component parent) { final TreeItem<Component> parentTreeItem = new TreeItem<Component>(parent); parent.draw(repository); for (Component component : parent.getList()) { if (!component.getList().isEmpty()) { throw new RuntimeException("Interface with more than three layers detected."); } else { component.draw(repository); parentTreeItem.getChildren().add(new TreeItem<Component>(component)); parent.getGroup().getChildren().add(component.getGroup()); } } stage.getController().getCenterRoot().getChildren().add(parentTreeItem); stage.getController().getPane().getChildren().add(parent.getGroup()); }
/** * Build the widget from the UI pane. * * @param repository The cache repository. */ public void buildWidget(CacheRepository repository) { for (Component component : list) { final WidgetComponentDefinition definition = component.getDefinition(); if (definition.hasScripts()) { continue; // TODO Fix object arrays. } final BorderPane pane = component.getBorderPane(); switch (component.getDefinition().getType()) { case 5: if (definition.getSpriteId() == 0) { continue; } final Sprite sprite = repository.get(SpriteDefinition.class, definition.getSpriteId()).get(0); definition.setWidth((int) component.getContentPane().getPrefWidth()); definition.setHeight((int) component.getContentPane().getPrefHeight()); break; } repository.pack(definition); } }