Search in sources :

Example 6 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class UgsDesignWriter method write.

@Override
public void write(OutputStream outputStream, Controller controller) {
    try {
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        DesignV1 design = new DesignV1();
        design.setSettings(convertSettings(controller));
        EntityGroup rootEntity = (EntityGroup) controller.getDrawing().getRootEntity();
        design.setEntities(rootEntity.getChildren().stream().map(this::convertToEntity).collect(Collectors.toList()));
        IOUtils.write(gson.toJson(design), outputStream, StandardCharsets.UTF_8);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup) Gson(com.google.gson.Gson) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class EntitiesTree method onSelectionEvent.

@Override
public void onSelectionEvent(SelectionEvent selectionEvent) {
    EntityGroup rootEntity = (EntityGroup) controller.getDrawing().getRootEntity();
    List<TreePath> treePathList = EntityTreeUtils.getSelectedPaths(controller, rootEntity, Collections.emptyList());
    TreePath[] treePaths = treePathList.toArray(new TreePath[0]);
    tree.setSelectionPaths(treePaths);
}
Also used : TreePath(javax.swing.tree.TreePath) EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup)

Example 8 with EntityGroup

use of com.willwinder.ugs.nbp.designer.entities.EntityGroup in project Universal-G-Code-Sender by winder.

the class UgsDesignReaderTest method convertEntityToString.

private String convertEntityToString(Entity entity) {
    when(controller.getSettings()).thenReturn(new Settings());
    when(controller.getDrawing()).thenReturn(drawing);
    EntityGroup group = new EntityGroup();
    group.addChild(entity);
    when(drawing.getRootEntity()).thenReturn(group);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    UgsDesignWriter writer = new UgsDesignWriter();
    writer.write(baos, controller);
    return new String(baos.toByteArray());
}
Also used : EntityGroup(com.willwinder.ugs.nbp.designer.entities.EntityGroup) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Settings(com.willwinder.ugs.nbp.designer.model.Settings)

Aggregations

EntityGroup (com.willwinder.ugs.nbp.designer.entities.EntityGroup)8 Entity (com.willwinder.ugs.nbp.designer.entities.Entity)4 SelectionManager (com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager)2 TreePath (javax.swing.tree.TreePath)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Settings (com.willwinder.ugs.nbp.designer.model.Settings)1 Point2D (java.awt.geom.Point2D)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1