use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class SelectionControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent) {
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent;
Point2D mousePosition = mouseEntityEvent.getCurrentMousePosition();
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) {
startPosition = new Point2D.Double(mousePosition.getX(), mousePosition.getY());
currentPosition = startPosition;
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_DRAGGED) {
currentPosition = new Point2D.Double(mousePosition.getX(), mousePosition.getY());
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_RELEASED) {
isPressed = false;
double startX = Math.min(startPosition.getX(), currentPosition.getX());
double startY = Math.min(startPosition.getY(), currentPosition.getY());
double width = Math.max(startPosition.getX(), currentPosition.getX()) - startX;
double height = Math.max(startPosition.getY(), currentPosition.getY()) - startY;
Rectangle2D rect = new Rectangle2D.Double(startX, startY, width, height);
if (rect.getWidth() > 1 && rect.getHeight() > 1) {
selectIntersection(rect, mouseEntityEvent.isShiftPressed());
} else {
selectOne(mousePosition, mouseEntityEvent.isShiftPressed());
}
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class ZoomControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent) {
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent;
isShiftPressed = mouseEntityEvent.isShiftPressed();
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) {
double zoomFactor = ZOOM_FACTOR;
if (isShiftPressed) {
zoomFactor = -zoomFactor;
}
controller.getDrawing().setScale(controller.getDrawing().getScale() + zoomFactor);
}
} else if (entityEvent instanceof KeyboardEntityEvent) {
KeyboardEntityEvent keyboardEntityEvent = (KeyboardEntityEvent) entityEvent;
if (keyboardEntityEvent.getKeyCode() == KeyEvent.VK_SHIFT) {
isShiftPressed = keyboardEntityEvent.getType() == EventType.KEY_PRESSED;
controller.getDrawing().repaint();
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent 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.gui.MouseEntityEvent 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);
}
Aggregations