Пример #1
0
 /**
  * Finds the ancestor of the node which its type class name ends with String classNameEndWith and
  * before it reaches a node that is of type classToStop.
  *
  * @param node the node that we will look for the ancestor.
  * @param classNameEndWith the ancestor class name that ends with this String
  * @param classToStop the ancestor type which will stop looking for further if seeing a node of
  *     this type.
  * @return the ancestor node if any.
  */
 @SuppressWarnings("unchecked")
 public static Node findAncestor(Node node, String classNameEndWith, Class classToStop) {
   while (node != null) {
     if (classToStop != null && classToStop.isAssignableFrom(node.getClass())) {
       return null;
     }
     if (node.getClass().getName().endsWith(classNameEndWith)) {
       return node;
     }
     node = node.getParent();
   }
   return null;
 }
Пример #2
0
 /**
  * Finds the ancestor of the node which is the type of the classToFind and before it reaches a
  * node that is of type classToStop.
  *
  * @param node the node that we will look for the ancestor.
  * @param classToFind the ancestor type we will try to look for
  * @param classToStop the ancestor type which will stop looking for further if seeing a node of
  *     this type.
  * @return the ancestor node if any.
  */
 @SuppressWarnings("unchecked")
 public static Node findAncestor(Node node, Class classToFind, Class classToStop) {
   node = node.getParent();
   while (node != null) {
     if (classToStop != null && classToStop.isAssignableFrom(node.getClass())) {
       return null;
     }
     if (classToFind.isAssignableFrom(node.getClass())) {
       return node;
     }
     node = node.getParent();
   }
   return null;
 }
Пример #3
0
  public void parseItems(List<Node> nodes, Pattern pattern, int defaultGroup) {
    List<Node> newNodes = new ArrayList<>();

    for (Node node : nodes) {
      if (node.getClass() != Text.class) {
        newNodes.add(node);
        continue;
      }

      String str = ((Text) node).getText();
      Matcher matcher = pattern.matcher(str);
      int lastIndex = 0;
      while (matcher.find()) {
        newNodes.add(new Text(str.substring(lastIndex, matcher.start())));
        SelectableMember sm = SelectableMember.fromMatcher(this, matcher);
        if (sm != null) {
          newNodes.add(sm);
        } else {
          newNodes.add(new Text(StringHelper.unqualify(matcher.group(defaultGroup))));
        }
        lastIndex = matcher.end();
      }
      newNodes.add(new Text(str.substring(lastIndex)));
    }

    nodes.clear();
    nodes.addAll(newNodes);
  }
Пример #4
0
  @Test
  public void testKnobExists() throws Exception {
    controller.click("#generators").drag("Fixed Rate").by(150, -50).drop();
    TestUtils.awaitCondition(
        new Callable<Boolean>() {
          @Override
          public Boolean call() throws Exception {
            return GuiTest.findAll(".canvas-object-view").size() == 1;
          }
        });

    System.gc();
    System.gc();
    System.gc();

    Node component = controller.find(".component-view");
    assertNotNull(component);

    ArrayList<Node> knobs = new ArrayList<>(GuiTest.findAll(".knob", component));

    assertFalse(knobs.isEmpty());

    Node knob = knobs.get(0);

    assertThat(knob.getClass().getSimpleName(), is("Knob"));

    ComponentItem cItem = FxIntegrationBase.getProjectItem().getComponentByLabel("Fixed Rate 1");

    // using reflection to get value of a knob because dependency problems are making impossible
    // to add loadui-fx-interface as a dependency and consequently get access to the knob class
    Method getValue = knob.getClass().getMethod("getValue");

    // initial value should be the same
    assertThat(getRate(cItem), is(getKnobValue(knob, getValue)));

    controller.drag(knob).by(0, 20).drop();
    TestUtils.awaitEvents(cItem);
    assertThat(getRate(cItem), is(getKnobValue(knob, getValue)));

    controller.drag(knob).by(0, -100).drop();
    TestUtils.awaitEvents(cItem);
    assertThat(getRate(cItem), is(getKnobValue(knob, getValue)));

    controller.drag(knob).by(0, 100).by(0, -200).by(0, 200).by(0, -200).by(0, 205).drop();
    TestUtils.awaitEvents(cItem);
    assertThat(getRate(cItem), is(getKnobValue(knob, getValue)));
  }
Пример #5
0
  private boolean nodeHasLabel(Node node) {
    checkArgument(
        node instanceof Labeled || node instanceof TextInputControl || node instanceof Text,
        "Target node must be Labeled or TextInputControl or Text, was ("
            + node.getClass().getName()
            + ").");

    if (node instanceof Labeled) {
      Labeled labeled = (Labeled) node;
      actualText = labeled.getText();
    } else if (node instanceof TextInputControl) {
      TextInputControl textInput = (TextInputControl) node;
      actualText = textInput.getText();
    } else {
      Text textInput = (Text) node;
      actualText = textInput.getText();
    }
    return label.equals(actualText);
  }