use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class MoveControlTest method moveShouldMoveWhenDragged.
@Test
public void moveShouldMoveWhenDragged() {
Rectangle rectangle = new Rectangle();
rectangle.setWidth(10);
rectangle.setHeight(10);
rectangle.move(new Point2D.Double(10, 10));
SelectionManager selectionManager = new SelectionManager();
selectionManager.addSelection(rectangle);
Controller controller = new Controller(selectionManager, new SimpleUndoManager());
MoveControl target = new MoveControl(controller);
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_PRESSED, new Point2D.Double(10, 10), new Point2D.Double(10, 10)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(12, 12)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
Assert.assertEquals(11, rectangle.getPosition().getX(), 0.1);
Assert.assertEquals(11, rectangle.getPosition().getY(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class MoveControlTest method moveShouldMoveMultipleSelectedEntitiesFromSelectionManager.
@Test
public void moveShouldMoveMultipleSelectedEntitiesFromSelectionManager() {
Rectangle rectangle1 = new Rectangle();
rectangle1.setWidth(10);
rectangle1.setHeight(10);
rectangle1.move(new Point2D.Double(10, 10));
Rectangle rectangle2 = new Rectangle();
rectangle2.setWidth(10);
rectangle2.setHeight(10);
SelectionManager selectionManager = new SelectionManager();
selectionManager.addSelection(rectangle1);
selectionManager.addSelection(rectangle2);
Assert.assertEquals(0, selectionManager.getPosition().getX(), 0.1);
Assert.assertEquals(0, selectionManager.getPosition().getY(), 0.1);
Controller controller = new Controller(selectionManager, new SimpleUndoManager());
MoveControl target = new MoveControl(controller);
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_PRESSED, new Point2D.Double(10, 10), new Point2D.Double(10, 10)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(12, 12)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(20, 20)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_RELEASED, new Point2D.Double(10, 10), new Point2D.Double(20, 20)));
Assert.assertEquals(10, selectionManager.getPosition().getX(), 0.1);
Assert.assertEquals(10, selectionManager.getPosition().getY(), 0.1);
Assert.assertEquals(20, rectangle1.getPosition().getX(), 0.1);
Assert.assertEquals(20, rectangle1.getPosition().getY(), 0.1);
Assert.assertEquals(10, rectangle2.getPosition().getX(), 0.1);
Assert.assertEquals(10, rectangle2.getPosition().getY(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class SelectionManagerTest method setSelectionWithControlShouldNotBePossible.
@Test
public void setSelectionWithControlShouldNotBePossible() {
Controller controller = mock(Controller.class);
MoveControl control = new MoveControl(controller);
target.setSelection(Collections.singletonList(control));
assertTrue(target.isEmpty());
}
use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class NewAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
UndoManager undoManager = CentralLookup.getDefault().lookup(UndoManager.class);
undoManager.clear();
SelectionManager selectionManager = CentralLookup.getDefault().lookup(SelectionManager.class);
selectionManager.clearSelection();
Controller controller = CentralLookup.getDefault().lookup(Controller.class);
controller.newDrawing();
}
use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class ExportGcodeAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Optional<File> fileOptional = SwingHelpers.createFile("");
if (fileOptional.isPresent()) {
String path = fileOptional.get().getAbsolutePath();
boolean hasGcodeFileEnding = path.endsWith(".gcode") || path.endsWith(".nc") || path.endsWith(".txt");
if (!hasGcodeFileEnding) {
path = path + ".gcode";
}
Controller controller = CentralLookup.getDefault().lookup(Controller.class);
DesignWriter designWriter = new GcodeDesignWriter();
designWriter.write(new File(path), controller);
}
}
Aggregations