@Test
  public void testConceptNewJump() {
    // given
    Set<Node> newButtons = conceptMapView.lookupAll(".newBtnTop");
    Node firstNewButton = newButtons.iterator().next();

    moveTo(firstNewButton).press(MouseButton.PRIMARY).release(MouseButton.PRIMARY);
    Node concept = conceptMapView.lookup(".concept");

    double expectedX = concept.getLayoutX() + concept.getTranslateX();
    double expectedY = concept.getLayoutY() + concept.getTranslateY();

    // when

    super.interact(
        () -> {
          stage.setFullScreen(false);
          stage.setWidth(stage.getWidth() - 40);
          stage.setHeight(stage.getHeight() - 40);
        });

    // then

    double actualX = concept.getLayoutX() + concept.getTranslateX();
    double actualY = concept.getLayoutY() + concept.getTranslateY();

    assertEquals(expectedX, actualX, 50);
    assertEquals(expectedY, actualY, 50);
  }
  @Test
  public void testLayoutWithConceptAdded() {
    int conceptCount = map.getConceptCount();

    Concept c =
        new Concept(
            new CollaborativeString(map.getExperiment().getParticipants().get(0), FIRST_CONCEPT));
    double x = 0.4;
    double y = 0.4;
    c.setPosition(x, y, 0);

    map.addConcept(c);

    // when
    super.interact(
        () -> {
          controller.setConceptMap(map);
          controller.layout();
        });

    // then

    Set<Node> concepts = conceptMapView.lookupAll(".concept");

    assertEquals(conceptCount + 1, concepts.size());
    assertEquals(conceptCount + 1, map.getConceptCount());
    Node addedConcept = concepts.iterator().next();

    double xScaled = addedConcept.getLayoutX() + addedConcept.getTranslateX();
    double yScaled = addedConcept.getLayoutY() + addedConcept.getTranslateY();

    assertEquals(x * scene.getWidth(), xScaled, 0.5);
    assertEquals(y * scene.getHeight(), yScaled, 0.5);

    Label caption = (Label) addedConcept.lookup("#caption");
    assertEquals(FIRST_CONCEPT, caption.getText());
  }
Exemplo n.º 3
0
  public String savefile(AnchorPane right_pane) {

    String xmlString = null;
    try {

      StringWriter stringWriter = new StringWriter();

      XMLOutputFactory xMLOutputFactory = XMLOutputFactory.newInstance();
      XMLStreamWriter xMLStreamWriter = xMLOutputFactory.createXMLStreamWriter(stringWriter);

      xMLStreamWriter.writeStartDocument();

      xMLStreamWriter.writeStartElement("Circuit");

      for (Node aNode : right_pane.getChildren()) {

        if (aNode instanceof Wire) {

          Wire wire = (Wire) aNode;

          xMLStreamWriter.writeStartElement("Wire");
          xMLStreamWriter.writeAttribute("ID", wire.getId());

          xMLStreamWriter.writeStartElement("source");
          xMLStreamWriter.writeCharacters(String.valueOf(wire.getSource().getId()));
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeStartElement("target");
          xMLStreamWriter.writeCharacters(String.valueOf(wire.getTarget().getId()));
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeStartElement("type");
          xMLStreamWriter.writeCharacters("WIRE");
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeEndElement();
        }

        if (!(aNode.getLayoutX() > 0.0)) {
          continue;
        }

        if (aNode instanceof Text) {
          continue;
        }

        if (aNode instanceof Component) {

          Component c = (Component) aNode;

          xMLStreamWriter.writeStartElement("Node");
          xMLStreamWriter.writeAttribute("ID", c.getId());

          xMLStreamWriter.writeStartElement("xCoord");
          xMLStreamWriter.writeCharacters(String.valueOf(c.getLayoutX()));
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeStartElement("yCoord");
          xMLStreamWriter.writeCharacters(String.valueOf(c.getLayoutY()));
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeStartElement("type");
          xMLStreamWriter.writeCharacters((c.getType().toString()));
          xMLStreamWriter.writeEndElement();

          xMLStreamWriter.writeEndElement();
        }
      }

      xMLStreamWriter.writeEndElement();
      xMLStreamWriter.writeEndDocument();

      xMLStreamWriter.flush();
      xMLStreamWriter.close();

      xmlString = stringWriter.getBuffer().toString();

      stringWriter.close();

    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return xmlString;
  }