Ejemplo n.º 1
0
  public String begin() {

    String returnValue = null;
    done = false;
    Set<Element> selection = null;
    try {
      selection = br.org.archimedes.Utils.getController().getCurrentSelectedElements();
    } catch (NoActiveDrawingException e) {
      // Shouldn't happen since I am an active factory
      e.printStackTrace();
    }

    boolean needsAValidSelection = true;
    if (selection != null && !selection.isEmpty()) {
      try {
        returnValue = next(selection);
        needsAValidSelection = false;
      } catch (InvalidParameterException e) {
        // Can happen if the selection is not valid.
        // Just work like if nothing was selected.
      }
    }

    if (needsAValidSelection) {
      parser = new SimpleSelectionParser();
      returnValue = Messages.SelectorFactory_Select;
    }

    return returnValue;
  }
Ejemplo n.º 2
0
  /** @param drawing True if the interpreter is enabled, false otherwise. */
  public void setDrawing(Drawing drawing) {

    Controller controller = br.org.archimedes.Utils.getController();
    if (!controller.isThereActiveDrawing()) {
      controller.setActiveDrawing(drawing);
    } else if (this.getCurrentFactory() == null || this.getCurrentFactory().isDone()) {
      controller.setActiveDrawing(drawing);
      controller.deselectAll();
    }

    changeState(currentState.changedDrawing(drawing));
    setChanged();
    notifyObservers(drawing);
  }
/** Belongs to package br.org.archimedes.gui.model. */
public class MousePositionManagerTest extends Tester {

  private Drawing drawing;

  private MousePositionManager manager;

  private Controller controller = br.org.archimedes.Utils.getController();

  @Before
  public void setUp() {

    drawing = new Drawing("Test");
    controller.setActiveDrawing(drawing);
    manager = new MousePositionManager();
    controller.deselectAll();
    br.org.archimedes.Utils.getWorkspace().setWindowSize(new Rectangle(-1000, -1000, 1000, 1000));
  }

  @Test
  public void testNoGrips() throws InvalidArgumentException {

    Point mouse, grip, actual;
    ReferencePoint refPoint;
    mouse = new Point(100, 50);
    manager.setMousePosition(mouse);
    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    Assert.assertEquals(null, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);

    // TODO Arrumar
    // putSafeElementOnDrawing(new Line(0, 0, 100, 100), drawing);

    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    Assert.assertEquals(null, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);
  }

  @Test
  public void testWithOneLine() throws InvalidArgumentException {

    ReferencePoint refPoint;
    Point mouse, grip, actual, expected;
    putSafeElementOnDrawing(new Line(0, 0, 100, 100), drawing);

    // Grip to an extreme
    mouse = new Point(0.1, 0.1);
    manager.setMousePosition(mouse);

    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    expected = new Point(0, 0);
    Assert.assertEquals(expected, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);

    // Grip to a central point
    mouse = new Point(50.1, 50.1);
    manager.setMousePosition(mouse);
    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    expected = new Point(50, 50);
    Assert.assertEquals(expected, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);

    // Grip perpendicular point
    Point firstPoint = new Point(80, 70);
    manager.setPerpendicularGripReferencePoint(firstPoint);
    mouse = new Point(74.9, 74.9);
    manager.setMousePosition(mouse);
    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    expected = new Point(75, 75);
    Assert.assertEquals(expected, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);
  }

  @Test
  public void testWithTwoLines() throws InvalidArgumentException {

    Point mouse, grip, actual, expected;
    putSafeElementOnDrawing(new Line(0, 0, 100, 100), drawing);
    putSafeElementOnDrawing(new Line(50, 75, 150, 75), drawing);

    // Grip to intersection
    mouse = new Point(74.9, 74.9);
    manager.setMousePosition(mouse);
    ReferencePoint refPoint;
    refPoint = manager.getGripMousePosition();
    grip = (refPoint == null ? null : refPoint.getPoint());
    expected = new Point(75, 75);
    Assert.assertEquals(expected, grip);
    actual = manager.getActualMousePosition();
    Assert.assertEquals(mouse, actual);
  }
}