Example usage for javafx.collections ObservableList size

List of usage examples for javafx.collections ObservableList size

Introduction

In this page you can find the example usage for javafx.collections ObservableList size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    ObservableList<String> observableList = FXCollections.observableList(list);
    observableList.addListener(new ListChangeListener() {
        @Override/*  w  w w  . j  a  v  a  2 s .c o  m*/
        public void onChanged(ListChangeListener.Change change) {
            System.out.println("change!");
        }
    });
    observableList.add("item one");
    list.add("item two");
    System.out.println("Size: " + observableList.size());

}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    ObservableList<String> observableList = FXCollections.observableList(list);
    observableList.addListener(new ListChangeListener() {

        @Override//from  ww  w .j av  a2 s  .  c  o m
        public void onChanged(ListChangeListener.Change change) {
            System.out.println("Detected a change! ");
            while (change.next()) {
                System.out.println("Was added? " + change.wasAdded());
                System.out.println("Was removed? " + change.wasRemoved());
                System.out.println("Was replaced? " + change.wasReplaced());
                System.out.println("Was permutated? " + change.wasPermutated());
            }
        }
    });
    observableList.add("item one");
    list.add("item two");
    System.out.println("Size: " + observableList.size());

}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Split Views");
    Group root = new Group();
    Scene scene = new Scene(root, 350, 250, Color.WHITE);

    SplitPane splitPane = new SplitPane();
    splitPane.prefWidthProperty().bind(scene.widthProperty());
    splitPane.prefHeightProperty().bind(scene.heightProperty());

    VBox leftArea = new VBox(10);
    HBox rowBox = new HBox(20);
    final Text leftText = TextBuilder.create().text("Left ").translateX(20).fill(Color.RED)
            .font(Font.font(null, FontWeight.BOLD, 20)).build();

    rowBox.getChildren().add(leftText);//from ww  w  .  jav a  2s .  c  o m
    leftArea.getChildren().add(rowBox);

    leftArea.setAlignment(Pos.CENTER);

    SplitPane splitPane2 = new SplitPane();
    splitPane2.setOrientation(Orientation.VERTICAL);
    splitPane2.prefWidthProperty().bind(scene.widthProperty());
    splitPane2.prefHeightProperty().bind(scene.heightProperty());

    HBox centerArea = new HBox();

    final Text upperRight = TextBuilder.create().text("Text").x(100).y(50).fill(Color.RED)
            .font(Font.font(null, FontWeight.BOLD, 35)).translateY(50).build();
    centerArea.getChildren().add(upperRight);

    HBox rightArea = new HBox();

    final Text lowerRight = TextBuilder.create().text("Lower Right").x(100).y(50).fill(Color.RED)
            .font(Font.font(null, FontWeight.BOLD, 35)).translateY(50).build();
    rightArea.getChildren().add(lowerRight);

    splitPane2.getItems().add(centerArea);
    splitPane2.getItems().add(rightArea);

    splitPane.getItems().add(leftArea);

    splitPane.getItems().add(splitPane2);

    ObservableList<SplitPane.Divider> dividers = splitPane.getDividers();
    for (int i = 0; i < dividers.size(); i++) {
        dividers.get(i).setPosition((i + 1.0) / 3);
    }
    HBox hbox = new HBox();
    hbox.getChildren().add(splitPane);
    root.getChildren().add(hbox);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:org.pdfsam.ui.selection.multiple.move.MoveType.java

boolean isSubselection(Integer[] toMove, ObservableList<?> items) {
    return !ArrayUtils.isEmpty(toMove) && toMove.length < items.size();
}

From source file:org.pdfsam.ui.selection.multiple.move.MoveType.java

boolean isSingleSelection(Integer[] toMove, ObservableList<?> items) {
    return !ArrayUtils.isEmpty(toMove) && toMove.length == 1 && items.size() > 1;
}

From source file:ninja.eivind.hotsreplayuploader.window.nodes.UploaderNode.java

private void bindList() {
    final ObservableList<ReplayFile> files = uploaderService.getFiles();
    newReplaysCount.setText(String.valueOf(files.size()));
    files.addListener(/*ww  w.  jav a2  s.  c o  m*/
            (ListChangeListener<ReplayFile>) c -> newReplaysCount.setText(String.valueOf(files.size())));
    newReplaysView.setItems(files.sorted(new ReplayFileComparator()));
    newReplaysView.setCellFactory(new CustomListCellFactory(uploaderService));

    uploadedReplays.textProperty().bind(uploaderService.getUploadedCount());
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.ListViewAdapter.java

/** {@inheritDoc} **/
public String[] getValues() {
    return EventThreadQueuerJavaFXImpl.invokeAndWait("getValues", //$NON-NLS-1$
            new Callable<String[]>() {
                /** {@inheritDoc} **/
                public String[] call() throws Exception {
                    List<String> values = new LinkedList<String>();
                    final T listView = getRealComponent();
                    ObservableList items = listView.getItems();
                    int itemCount = items != null ? items.size() : -1;
                    for (int i = 0; i < itemCount; i++) {
                        listView.scrollTo(i);
                        listView.layout();
                        TraverseHelper<ListCell> helper = new TraverseHelper<ListCell>();
                        List<ListCell> lCells = helper.getInstancesOf(listView, ListCell.class);
                        for (ListCell cell : lCells) {
                            if (cell.getIndex() == i && cell.getListView() == listView) {
                                values.add(cell.getText());
                                break;
                            }//from   w  ww  . j  av  a2  s .c o m
                        }
                    }
                    return values.toArray(new String[0]);
                }
            });
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.ListViewAdapter.java

/** {@inheritDoc} **/
public void clickOnIndex(final Integer index, ClickOptions co) {
    final int actualItemCount = EventThreadQueuerJavaFXImpl.invokeAndWait("scrollIndexVisible", //$NON-NLS-1$
            new Callable<Integer>() {
                public Integer call() throws Exception {
                    final ObservableList items = getRealComponent().getItems();
                    int itemCount = items != null ? items.size() : -1;
                    return new Integer(itemCount);
                }// www.  j  a v a 2 s.  c o  m
            }).intValue();

    if (index >= actualItemCount || (index < 0)) {
        throw new StepExecutionException("List index '" + index //$NON-NLS-1$
                + "' is out of range", //$NON-NLS-1$
                EventFactory.createActionError(TestErrorEvent.INVALID_INDEX));
    }

    Rectangle r = EventThreadQueuerJavaFXImpl.invokeAndWait("scrollIndexVisible", //$NON-NLS-1$
            new Callable<Rectangle>() {
                public Rectangle call() throws Exception {
                    final T listView = getRealComponent();
                    listView.scrollTo(index.intValue());
                    listView.layout();
                    TraverseHelper<ListCell> helper = new TraverseHelper<ListCell>();
                    List<ListCell> lCells = helper.getInstancesOf(listView, ListCell.class);
                    for (ListCell cell : lCells) {
                        if (cell.getIndex() == index.intValue() && cell.getListView() == listView) {

                            Bounds b = cell.getBoundsInParent();
                            Point2D pos = cell.localToScreen(0, 0);
                            Point2D parentPos = listView.localToScreen(0, 0);
                            return new Rectangle(Rounding.round(pos.getX() - parentPos.getX()),
                                    Rounding.round(pos.getY() - parentPos.getY()), Rounding.round(b.getWidth()),
                                    Rounding.round(b.getHeight()));
                        }
                    }
                    return null;
                }
            });

    getRobot().click(getRealComponent(), r, co.setClickType(ClickOptions.ClickType.RELEASED));
}

From source file:com.github.naoghuman.testdata.abclist.service.ExerciseTermService.java

@Override
protected Task<Void> createTask() {
    return new Task<Void>() {
        {/* www .j  a v a 2s  .  c  om*/
            updateProgress(0, saveMaxEntities);
        }

        @Override
        protected Void call() throws Exception {
            LoggerFacade.getDefault().deactivate(Boolean.TRUE);

            final StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
            final ObservableList<Term> terms = SqlProvider.getDefault().findAllTerms();
            final int sizeTerms = terms.size();
            final AtomicInteger index = new AtomicInteger(0);

            final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName);
            final AtomicLong id = new AtomicLong(
                    -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName));
            topics.stream().forEach(topic -> {
                final ObservableList<Exercise> exercises = SqlProvider.getDefault()
                        .findAllExercisesWithTopicId(topic.getId());
                exercises.stream().filter(exercise -> exercise.isReady()).forEach(exercise -> {
                    final int maxExerciseTerms = TestdataGenerator.RANDOM.nextInt(70) + 10;
                    for (int i = 0; i < maxExerciseTerms; i++) {
                        final Term term = terms.get(TestdataGenerator.RANDOM.nextInt(sizeTerms));
                        final ExerciseTerm exerciseTerm = ModelProvider.getDefault().getExerciseTerm();
                        exerciseTerm.setExerciseId(exercise.getId());
                        exerciseTerm.setId(id.getAndIncrement());
                        exerciseTerm.setTermId(term.getId());

                        crudService.create(exerciseTerm);
                    }
                });

                updateProgress(index.getAndIncrement(), saveMaxEntities);
            });

            LoggerFacade.getDefault().deactivate(Boolean.FALSE);
            stopWatch.split();
            LoggerFacade.getDefault().debug(this.getClass(),
                    "  + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " ExerciseTerms."); // NOI18N
            stopWatch.stop();

            return null;
        }
    };
}

From source file:com.cyberlogix.mist6020biometrics.RosterController.java

public void printsListener() {

    long delay = 5 * 1000;
    final long period = 5 * 1000;
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override//from  w w w.j  a  v  a 2  s  .c o  m
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    String b64Print = bio.getImage(rosterImage, rosterPbar, rosterPin, new Stage(), period);
                    System.out.println("Print: " + b64Print);
                    try {
                        if (!b64Print.equalsIgnoreCase("error")) {
                            String url = ServerConnect.STUDENTS_URL + "/verify";
                            ServerConnect sc = new ServerConnect();
                            JSONObject req = new JSONObject();
                            req.put("print", b64Print);
                            ServerResponse msg = sc.processRequest(req.toString(), url,
                                    ServerConnect.METHOD_POST);
                            if (msg.getStatusCode() == 200 || msg.getStatusCode() == 201) {
                                ObjectMapper jackson = new ObjectMapper();
                                Student student = jackson.readValue(
                                        msg.getResponse().getJSONObject("payload").toString(), Student.class);
                                //update table
                                int pos = -1;
                                ObservableList<Student> students = tblRoster.getItems();
                                for (int i = 0; i < students.size(); i++) {
                                    if (students.get(i).getId() == student.getId()) {
                                        System.out.println("Student Matched...");
                                        student.setSignedIn("Present");
                                        students.remove(students.get(i));
                                        pos = i;
                                    }
                                }
                                if (pos >= 0) {
                                    students.add(pos, student);
                                }
                                System.out.println("Students Size: " + students.size());
                                tblRoster.setItems(students);

                                //                                    Dialogs.showConfirmDialog(new Stage(), msg.getResponse().getString("message") + " " + student.getName());
                                alertBox.setText(
                                        msg.getResponse().getString("message") + " " + student.getName());
                                alertBox.setStyle("-fx-text-fill: green; -fx-font-weight: bold;");
                            } else {
                                //                                    Dialogs.showErrorDialog(new Stage(), msg.getResponse().getString("message"), "Error " + msg.getStatusCode(), "Error");
                                alertBox.setText(msg.getResponse().getString("message"));
                                alertBox.setStyle("-fx-text-fill: red; -fx-font-weight: bold;");
                            }
                        }

                    } catch (JSONException | IOException e) {
                        UtilHelper.debugTrace(e);
                    }
                }
            });
        }
    }, delay, period);

}