@Test
 public void settingTheSelectedItemToAnItemInItemsResultsInTheCorrectSelectedIndex() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().select("Orange");
   assertEquals(1, box.getSelectionModel().getSelectedIndex());
   assertSame("Orange", box.getSelectionModel().getSelectedItem());
 }
 @Test
 public void canSetSelectedItemToAnItemEvenWhenThereAreNoItems() {
   final String randomString = new String("I AM A CRAZY RANDOM STRING");
   box.getSelectionModel().select(randomString);
   assertEquals(-1, box.getSelectionModel().getSelectedIndex());
   assertSame(randomString, box.getSelectionModel().getSelectedItem());
 }
 @Test
 public void ensureValueEqualsSelectedItemWhenNotInItemsList() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().setSelectedItem("pineapple");
   assertEquals("pineapple", box.getSelectionModel().getSelectedItem());
   assertEquals("pineapple", box.getValue());
 }
  private void signOutInDB() {
    checkAllFieldsHandled();

    ObservableList<Topics135> selectedTopics =
        topicsListView.getSelectionModel().getSelectedItems();
    ArrayList<Topics135> arrayOfTopics = new ArrayList<>();
    if (selectedTopics != null) {
      for (Topics135 t : selectedTopics) {
        arrayOfTopics.add(t);
      }
    }

    if (arrayOfTopics.isEmpty()) {
      arrayOfTopics = null;
    }

    // If not in 135, then Level of Learning will be null. Do not insert level of learning in to DB.
    int levelOfLearningValue = -1;
    if (levelOfLearning.getValue() != null) {
      levelOfLearningValue = levelOfLearning.getValue();
    }

    sod =
        new SignOutData(
            student.getEmplId(), arrayOfTopics, levelOfLearningValue, theTutor.getValue());

    Main.getMdb().signOut(sod);
    successfulSignOut = true;
    close();
  }
 @Test
 public void ensureSelectionModelUpdatesValueProperty_withSelectLast() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   assertNull(box.getValue());
   box.getSelectionModel().selectLast();
   assertEquals("Banana", box.getValue());
 }
 @Test
 public void ensureSelectionModelUpdatesWhenValueChanges() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   assertNull(box.getSelectionModel().getSelectedItem());
   box.setValue("Orange");
   assertEquals("Orange", box.getSelectionModel().getSelectedItem());
 }
 @Test
 public void canSetSelectedItemToAnItemNotInTheChoiceBoxItems() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   final String randomString = new String("I AM A CRAZY RANDOM STRING");
   box.getSelectionModel().select(randomString);
   assertEquals(-1, box.getSelectionModel().getSelectedIndex());
   assertSame(randomString, box.getSelectionModel().getSelectedItem());
 }
 @Test
 public void selectionModelCanBeBound() {
   SingleSelectionModel<String> sm = new ChoiceBox.ChoiceBoxSelectionModel<String>(box);
   ObjectProperty<SingleSelectionModel<String>> other =
       new SimpleObjectProperty<SingleSelectionModel<String>>(sm);
   box.selectionModelProperty().bind(other);
   assertSame(sm, box.getSelectionModel());
 }
 @Test
 public void
     settingTheSelectedItemToANonexistantItemAndThenSettingItemsWhichContainsItResultsInCorrectSelectedIndex() {
   box.getSelectionModel().select("Orange");
   box.getItems().setAll("Apple", "Orange", "Banana");
   assertEquals(1, box.getSelectionModel().getSelectedIndex());
   assertSame("Orange", box.getSelectionModel().getSelectedItem());
 }
 @Test
 public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex2() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().select(2);
   box.getItems().clear();
   assertEquals(-1, box.getSelectionModel().getSelectedIndex());
   assertEquals(null, box.getSelectionModel().getSelectedItem());
 }
  private void display() {
    initModality(Modality.APPLICATION_MODAL);

    setTitle("Student Review");
    setMinWidth(250);
    setMinHeight(300);

    signOutButton = new Button("SignOut");
    signOutButton.setOnAction(event -> signOutInDB());
    buttonHBox = new HBox(signOutButton);
    buttonHBox.setAlignment(Pos.CENTER_RIGHT);

    studentInfo = new RegistrationStudentInfoEntryBox();
    // Disabling all fields
    setValue(studentInfo.getEmplIdTextField(), String.valueOf(student.getEmplId()));
    setValue(studentInfo.getFirstNameTextField(), student.getFirstName());
    setValue(studentInfo.getLastNameTextField(), student.getLastName());
    studentInfo.getYearChoiceBox().setValue(student.getYear());
    studentInfo.getYearChoiceBox().setDisable(true);

    theTutor = new ChoiceBox<>();
    theTutor.getItems().addAll(Tutor.values());
    theTutorLabel = new Label("Tutor ");
    theTutorLayout = new HBox();
    theTutorLayout.getChildren().addAll(theTutorLabel, theTutor);

    is135 = new CheckBox("Discussed 135 Topics? ");
    is135.setOnAction(event -> handleListView());

    // Hidden until is135 is checked
    levelOfLearning = new ChoiceBox<>();
    levelOfLearning.getItems().addAll(1, 2, 3, 4);
    levelOfLearningLabel = new Label("Level Of Learning ");
    levelOfLearningLayout = new HBox();
    levelOfLearningLayout.getChildren().addAll(levelOfLearningLabel, levelOfLearning);
    levelOfLearningLayout.setVisible(false);
    levelOfLearningLayout.setManaged(false);

    // Hidden until is135 is checked
    topicsListView = new ListView<>();
    topicsListView.getItems().addAll(Topics135.values());
    topicsListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    topicsListView.setVisible(false);
    topicsListView.setManaged(false);

    vertical135Layout = new VBox(10);
    vertical135Layout.getChildren().addAll(is135, levelOfLearningLayout, topicsListView);

    mainVBox = new VBox(20);
    mainVBox.getChildren().addAll(studentInfo, theTutorLayout, vertical135Layout, buttonHBox);
    mainVBox.setMargin(vertical135Layout, new Insets(0, 20, 0, 20));
    mainVBox.setMargin(buttonHBox, new Insets(20));
    mainVBox.setAlignment(Pos.TOP_CENTER);

    scene = new Scene(mainVBox);
    setScene(scene);
    showAndWait();
  }
 @Test
 public void testSelectingItemBeforeFirstShow() {
   StackPane pane = new StackPane();
   pane.getChildren().add(box);
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().select("Orange");
   startApp(pane);
   assertEquals(1, box.getSelectionModel().getSelectedIndex());
 }
 @Test
 public void
     ensureSelectionClearsWhenSettingSelectionBeforePopulatingItemsAndAllItemsAreRemoved() {
   box.getSelectionModel().select("Banana");
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getItems().clear();
   assertEquals(-1, box.getSelectionModel().getSelectedIndex());
   assertEquals(null, box.getSelectionModel().getSelectedItem());
 }
  @Test
  public void ensureValueDoesNotChangeWhenBoundAndNoExceptions() {
    box.getItems().addAll("Apple", "Orange", "Banana");

    StringProperty sp = new SimpleStringProperty("empty");
    box.valueProperty().bind(sp);

    box.getSelectionModel().select(1);
    assertEquals("empty", box.getValue());
  }
예제 #15
0
 public void loadNumberChoiceBox() {
   int nr =
       (Objekte.getMapData().getMapNumberListById(Objekte.getMapData().getCurNumberId())).getNr();
   cb.getItems().clear();
   for (Data.MapNumber mapN : Objekte.getMapData().getMapNumberList()) {
     String anzeige = "";
     anzeige += "" + mapN.getNr() + ": " + mapN.getName();
     cb.getItems().add(anzeige);
   }
   cb.getSelectionModel().select(nr - 1);
 }
 @Test
 public void checkSelectedItemAfterReplacingDataWithEmptyList() {
   StackPane pane = new StackPane();
   pane.getChildren().add(box);
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().select("Orange");
   startApp(pane);
   box.getItems().clear();
   // make sure the selected item is null
   assertEquals(null, box.getSelectionModel().getSelectedItem());
 }
예제 #17
0
  void generateBackupPaths() {
    ObservableList restorePaths = FXCollections.observableArrayList();
    restorePaths.clear();
    vBarBDirs.getChildren().clear();
    //        cbRestoreDirectory.getItems().clear();
    String[] backupArr = constants.getValue("s_dumpDir").split(";");
    for (final String dir : backupArr) {
      restorePaths.add(dir);
      HBox hbox = new HBox();
      Label lbl = new Label(dir);
      Button btn = new Button("Delete");
      btn.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
              String nString = constants.getValue("s_dumpDir");
              nString = nString.replaceAll(";" + dir, "");
              nString = nString.replaceAll(dir, "");
              constants.addValue("s_dumpDir", nString);
              System.out.println(constants.getValue("s_dumpDir"));
              txtDir.setText(nString);
              generateBackupPaths();
            }
          });
      hbox.getChildren().add(lbl);
      hbox.getChildren().add(btn);
      vBarBDirs.getChildren().add(hbox);
    }

    try {

      cbRestoreDirectory.setItems(restorePaths);
      cbRestoreDirectory.setValue(restorePaths.get(0));
      generateRestore(restorePaths.get(0).toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
    cbRestoreDirectory
        .valueProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(ObservableValue ov, String t, String t1) {
                //                System.out.println(ov);
                //                System.out.println(t);
                //                System.out.println(t1);
                generateRestore(t1);
              }
            });
  }
  private void updateDistanceDistributionChart() {

    double[][] transformedTrajectory = getTransformedTrajectory();
    if (transformedTrajectory == null) return;

    double approxDiameter =
        PhaseSpaceDistribution.maxPhaseSpaceDiameterApproximate(transformedTrajectory);

    long[] histo;
    // subsequent distance distribution
    if (distanceDistributionSelector.getSelectionModel().getSelectedIndex() == 0) {
      histo =
          PhaseSpaceDistribution.approximateSubsequentDistanceDistribution(
              transformedTrajectory, 1500, approxDiameter);
    } else {
      histo =
          PhaseSpaceDistribution.approximateDistanceDistribution(
              transformedTrajectory, 1500, approxDiameter);
    }

    subsequentDistanceDistributionChart.getData().clear();
    XYChart.Series series = new XYChart.Series();
    for (int i = 0; i < histo.length; i++) {
      series.getData().add(new XYChart.Data(i, histo[i]));
    }
    subsequentDistanceDistributionChart.getData().add(series);
  }
예제 #19
0
  /** Loads the name of all ingredients and puts them in ingredientlist. */
  public void updateIngredients() {
    ArrayList<ArrayList<String>> dataSet;
    ObservableList<String> itemList =
        FXCollections.observableArrayList(); // Observable arraylist for the listview

    try {
      System.out.println("- Main updateIngredientsRecipList");

      dataSet = fetchData("Ingredients", "Name"); // Gives the arraylist the ingredientnames

      for (ArrayList<String> element : dataSet) {
        itemList.add(element.get(0)); // For every element in the array, get name
      }

      System.out.println("- end of Main updateIngredientsRecipList");
    } catch (SQLException e) {
      e.printStackTrace();
    }
    recipeIngredients.setItems(itemList); // Sets the Listview to show the obs arraylist

    itemList.clear();
    try {
      dataSet = fetchData("Units", "*");

      for (ArrayList<String> element : dataSet) {
        itemList.add(element.get(1));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    ingredientUnit.setItems(itemList);
  }
 @Test
 public void testAddingEmptyChoiceBoxToLiveScene() {
   StackPane pane = new StackPane();
   pane.getChildren().add(box);
   startApp(pane);
   assertEquals(0, box.getItems().size());
 }
 @Test
 public void checkLabelAfterCallingSetItemsFromPlatformRunLater_RT30317() {
   final String[] items = {"Apple", "Orange", "Banana"};
   StackPane pane = new StackPane();
   pane.getChildren().add(box);
   Runnable runnable =
       () -> {
         box.setItems(FXCollections.observableArrayList(items));
         box.getSelectionModel().setSelectedItem("Apple");
       };
   Platform.runLater(runnable);
   startApp(pane);
   assertEquals(0, box.getSelectionModel().getSelectedIndex());
   ChoiceBoxSkin skin = (ChoiceBoxSkin) box.getSkin();
   assertEquals("Apple", ChoiceBoxSkinNodesRetriever.getChoiceBoxSelectedText(skin));
 }
 @Test
 public void ensureSelectionModelUpdatesWhenValueChangesToNull() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.setValue("pineapple");
   assertEquals("pineapple", box.getSelectionModel().getSelectedItem());
   assertEquals("pineapple", box.getValue());
   box.setValue(null);
   assertEquals(null, box.getSelectionModel().getSelectedItem());
   assertEquals(-1, box.getSelectionModel().getSelectedIndex());
   assertEquals(null, box.getValue());
 }
  private void checkAllFieldsHandled() {
    if (theTutor.getValue() == null) {
      PopUp.display("Error", "Please select a tutor");
      throw new IllegalArgumentException("Tutor was not selected");
    } else if (is135.isSelected()) {
      if (levelOfLearning.getValue() == null) {
        PopUp.display("Error", "Please select a level of learning for the student");
        throw new IllegalArgumentException("Level of Learning was not selected");
      }

      if (topicsListView.getSelectionModel().getSelectedItems().size() == 0) {
        PopUp.display(
            "Error",
            "Select at least one topic of discussion\n\n"
                + "If you are unsure, please select \'Other\'");
        throw new IllegalArgumentException("No class topic was selected");
      }
    }
  }
  @Test
  public void ensureSelectedItemRemainsAccurateWhenItemsAreCleared() {
    box.getItems().addAll("Apple", "Orange", "Banana");
    box.getSelectionModel().select(2);
    box.getItems().clear();
    assertNull(box.getSelectionModel().getSelectedItem());
    assertEquals(-1, box.getSelectionModel().getSelectedIndex());

    box.getItems().addAll("Kiwifruit", "Mandarin", "Pineapple");
    box.getSelectionModel().select(2);
    assertEquals("Pineapple", box.getSelectionModel().getSelectedItem());
  }
예제 #25
0
  /** ButtonMethod for add ingredients from the ingredientList into the tableview */
  public void addIngredientButton() {

    String selectedIngredient = recipeIngredients.getSelectionModel().getSelectedItems().toString();
    selectedIngredient = selectedIngredient.replaceAll("\\[", "").replaceAll("\\]", "");

    items.add(
        new Ingredient(
            selectedIngredient,
            ingredientAmount.getText(),
            ingredientUnit.getSelectionModel().getSelectedItem().toString())); // Creates new
    addedIngredientTable.setItems(
        items); // Object of the type Ingredient and adds it to the tableView.
  }
 @Test
 public void ensureValueIsCorrectWhenItemsIsAddedToWithExistingSelection() {
   box.getItems().addAll("Apple", "Orange", "Banana");
   box.getSelectionModel().select(1);
   box.getItems().add(0, "pineapple");
   assertEquals(2, box.getSelectionModel().getSelectedIndex());
   assertEquals("Orange", box.getSelectionModel().getSelectedItem());
   assertEquals("Orange", box.getValue());
 }
  @Test
  public void ensureSelectionModelClearsValuePropertyWhenNegativeOneSelected() {
    box.getItems().addAll("Apple", "Orange", "Banana");
    assertNull(box.getValue());
    box.getSelectionModel().select(0);
    assertEquals("Apple", box.getValue());

    box.getSelectionModel().select(-1);
    assertEquals(null, box.getValue());
  }
  @Test
  public void ensureSelectionIsCorrectWhenItemsChange() {
    box.setItems(FXCollections.observableArrayList("Item 1"));
    box.getSelectionModel().select(0);
    assertEquals("Item 1", box.getSelectionModel().getSelectedItem());

    box.setItems(FXCollections.observableArrayList("Item 2"));
    assertEquals(-1, box.getSelectionModel().getSelectedIndex());
    assertEquals(null, box.getSelectionModel().getSelectedItem());
  }
  @Test
  public void ensureSelectionModelClearsValueProperty() {
    box.getItems().addAll("Apple", "Orange", "Banana");
    assertNull(box.getValue());
    box.getSelectionModel().select(0);
    assertEquals("Apple", box.getValue());

    box.getSelectionModel().clearSelection();
    assertNull(box.getValue());
  }
  @Test
  public void ensureValueIsCorrectWhenItemsAreRemovedWithExistingSelection() {
    box.getItems().addAll("Apple", "Orange", "Banana");
    box.getSelectionModel().select(1);

    box.getItems().remove("Apple");

    assertEquals(0, box.getSelectionModel().getSelectedIndex());
    assertEquals("Orange", box.getSelectionModel().getSelectedItem());
    assertEquals("Orange", box.getValue());
  }