use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class OpenAction 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);
fileChooser.showOpenDialog(null);
ThreadHelper.invokeLater(() -> {
DesignReader designReader = new UgsDesignReader();
if (fileChooser.getFileFilter() == SVG_FILE_FILTER) {
designReader = new SvgReader();
} else if (fileChooser.getFileFilter() == C2D_FILE_FILTER) {
designReader = new C2dReader();
}
File selectedFile = fileChooser.getSelectedFile();
Optional<Design> optional = designReader.read(selectedFile);
if (optional.isPresent()) {
controller.setDesign(optional.get());
} else {
throw new RuntimeException("Could not open svg: " + selectedFile.getName());
}
});
}
use of com.willwinder.ugs.nbp.designer.logic.Controller in project Universal-G-Code-Sender by winder.
the class MoveControlTest method moveEntityShouldWorkOnScaledEntities.
@Test
public void moveEntityShouldWorkOnScaledEntities() {
Rectangle rectangle = new Rectangle();
rectangle.setWidth(10);
rectangle.setHeight(10);
rectangle.applyTransform(AffineTransform.getScaleInstance(2, 2));
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)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_RELEASED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
Assert.assertEquals(1, rectangle.getPosition().getX(), 0.1);
Assert.assertEquals(1, 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 moveEntityShouldUseGlobalTransform.
@Test
public void moveEntityShouldUseGlobalTransform() {
Rectangle rectangle = new Rectangle();
rectangle.setWidth(10);
rectangle.setHeight(10);
rectangle.move(new Point2D.Double(10, 10));
EntityGroup entityGroup = new EntityGroup();
entityGroup.addChild(rectangle);
entityGroup.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)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_RELEASED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
Assert.assertEquals(21, rectangle.getPosition().getX(), 0.1);
Assert.assertEquals(21, rectangle.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 addSelectionWithControlShouldNotBePossible.
@Test
public void addSelectionWithControlShouldNotBePossible() {
Controller controller = mock(Controller.class);
MoveControl control = new MoveControl(controller);
target.addSelection(control);
assertTrue(target.isEmpty());
}
Aggregations