Example usage for javafx.collections ObservableList get

List of usage examples for javafx.collections ObservableList get

Introduction

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

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.bekwam.examples.javafx.memorytests.BigTableController.java

static <T, S> T getObjectAtEvent(CellEditEvent<T, S> evt) {

    TableView<T> tableView = evt.getTableView();

    ObservableList<T> items = tableView.getItems();

    TablePosition<T, S> tablePosition = evt.getTablePosition();

    int rowId = tablePosition.getRow();

    T obj = items.get(rowId);

    return obj;//  w  w w  . j av a 2s  .c om
}

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  www .  j av a2s . co 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.eclipse.jubula.rc.javafx.tester.adapter.ListViewAdapter.java

/** {@inheritDoc} **/
public String getText() {
    String result = EventThreadQueuerJavaFXImpl.invokeAndWait("getText", //$NON-NLS-1$
            new Callable<String>() {

                /** {@inheritDoc} **/
                public String call() throws Exception {
                    ObservableList sItems = getRealComponent().getSelectionModel().getSelectedItems();
                    if (!sItems.isEmpty()) {
                        return String.valueOf(sItems.get(0));
                    }/*from   w w  w .  j a  va2s . c  o  m*/
                    throw new StepExecutionException("No selection found", //$NON-NLS-1$
                            EventFactory.createActionError(TestErrorEvent.NO_SELECTION));
                }
            });
    return result;
}

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// w w  w  .j a  v  a2  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);

}

From source file:com.ggvaidya.scinames.tabulardata.TabularDataViewController.java

/**
 * Initializes the controller class./*  w w  w  .j av a2s .co  m*/
 */
public void initialize() {
    tableView.itemsProperty().addListener((ObservableValue observable, Object oldValue, Object newValue) -> {
        ObservableList<Object> list;

        if (ObservableList.class.isAssignableFrom(newValue.getClass())) {
            list = (ObservableList<Object>) newValue;

            if (list.isEmpty()) {
                statusTextField.setText("Table contains an empty list.");
            } else {
                Object example = list.get(0);
                statusTextField.setText("Table contains " + list.size() + " items of " + example.getClass());
            }

        } else {
            statusTextField.setText("Table contains " + newValue);
        }
    });
}

From source file:account.management.controller.ReportLedgerController.java

@FXML
private void onLedgerIdInsert(KeyEvent event) {
    Platform.runLater(() -> {/*from   w ww . j  a  v a 2s. co m*/
        ObservableList<Account> account_list = this.account.getItems();
        Pattern p = Pattern.compile("(?:[A-Za-z 0]+)?([0-9]+).*");
        Matcher m = p.matcher(this.ledger_id.getText());
        if (m.find()) {
            System.out.println("2: " + m.group(1));
            int len = account_list.size();
            for (int i = 0; i < len; i++) {
                if (account_list.get(i).getId() == Integer.parseInt(m.group(1))) {
                    this.account.getSelectionModel().select(i);
                    break;
                }
            }
        }

    });

}

From source file:main.Content.java

public void setData(ObservableList<String> treeData) {
    temp = FXCollections.observableArrayList();
    for (int i = 0; i < treeData.size(); i++) {
        String index = treeData.get(i).toString();
        System.out.println(treeData.size());
        index = index.substring(0, 4);//from   w  ww  .ja va  2s . c om
        int parent = Integer.parseInt(index.substring(0, 1));
        int id;
        if (index.charAt(3) == ' ')
            id = Integer.parseInt(index.substring(2, 3));
        else
            id = Integer.parseInt(index.substring(2, 4));

        for (int j = 0; j < data.size(); j++) {
            Activity tempData = data.get(j);
            if (tempData.getParentValue() == parent && tempData.getID() == id) {
                temp.add(tempData);
                break;
            }
        }
    }
}

From source file:de.ifsr.adam.ImageGenerator.java

/**
 * Takes a snapshot of the Pane and prints it to a pdf.
 *
 * @return True if no IOException occurred
 *//*from w w w . j av a  2  s.  c o  m*/
private boolean printToPDF(String filePath, Pane pane) {
    //Scene set up
    Group root = new Group();
    Scene printScene = new Scene(root);
    printScene.getStylesheets().add(this.stylesheetURI.toString());

    //Snapshot generation
    ArrayList<WritableImage> images = new ArrayList<>();
    try {
        ObservableList<Node> panes = pane.getChildren();
        for (int i = 0; i < panes.size(); i++) {
            GridPane gridPane = (GridPane) panes.get(i);
            ((Group) printScene.getRoot()).getChildren().clear();
            ((Group) printScene.getRoot()).getChildren().addAll(gridPane);
            images.add(printScene.snapshot(null));
            panes.add(i, gridPane);
        }
    } catch (Exception e) {
        log.error(e);
        return false;
    }

    //PDF Setup
    File outFile = new File(filePath + "." + "pdf");
    Iterator<WritableImage> iterImages = images.iterator();
    PDDocument doc = new PDDocument();

    try {

        while (iterImages.hasNext()) {
            //Page setup
            PDPage page = new PDPage();
            doc.addPage(page);
            PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
            //Image setup
            BufferedImage bufImage = SwingFXUtils.fromFXImage(iterImages.next(), null);
            PDPixelMap pixelMap = new PDPixelMap(doc, bufImage);

            int width = (int) (page.getMediaBox().getWidth());
            int height = (int) (page.getMediaBox().getHeight());
            Dimension dim = new Dimension(width, height);
            contentStream.drawXObject(pixelMap, 0, 0, dim.width, dim.height);
            contentStream.close();
        }

        doc.save(outFile);
        return true;
    } catch (IOException | COSVisitorException e) {
        log.error(e);
        return false;
    }
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualization.java

/** iterate through the list of tick-marks building a two level structure of
 * replacement tick marl labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time. Second level has rest of
 * date/time grouped by unchanging part.
 * eg://from   w  ww.  jav a  2  s  . c  o m
 *
 *
 * october-30_october-31_september-01_september-02_september-03
 *
 * becomes
 *
 * _________30_________31___________01___________02___________03
 *
 * _________october___________|_____________september___________
 *
 *
 * NOTE: This method should only be invoked on the JFX thread
 */
public synchronized void layoutDateLabels() {

    //clear old labels
    branchPane.getChildren().clear();
    leafPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a clone of the list sorted by position along axis
    ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks());
    tickMarks.sort(
            (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition()));

    if (tickMarks.isEmpty() == false) {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenBranchLabel = dateTime.branch;
        //cumulative width of the current branch label

        //x-positions (pixels) of the current branch and leaf labels
        double leafLabelX = 0;

        if (dateTime.branch.equals("")) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX,
                        isTickBold(t.getValue()));

                leafLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state 
            double branchLabelX = 0;
            double branchLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) { //for each tick

                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still on the same branch
                if (lastSeenBranchLabel.equals(dateTime.branch)) {
                    //increment branch width
                    branchLabelWidth += spacing;
                } else {// we are on to a new branch, so ...
                    assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
                    //and then update label, x-pos, and width
                    lastSeenBranchLabel = dateTime.branch;
                    branchLabelX += branchLabelWidth;
                    branchLabelWidth = spacing;
                }
                //add the label for the leaf (highest frequency part)
                assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue()));

                //increment leaf position
                leafLabelX += spacing;
            }
            //we have reached end so add branch label for current branch
            assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane.java

/**
 * iterate through the list of tick-marks building a two level structure of
 * replacement tick marl labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time. Second level has rest of
 * date/time grouped by unchanging part. eg:
 *
 *
 * october-30_october-31_september-01_september-02_september-03
 *
 * becomes/*from   ww w .ja v  a2 s. c  o  m*/
 *
 * _________30_________31___________01___________02___________03
 *
 * _________october___________|_____________september___________
 *
 *
 * NOTE: This method should only be invoked on the JFX thread
 */
public synchronized void layoutDateLabels() {

    //clear old labels
    branchPane.getChildren().clear();
    leafPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a clone of the list sorted by position along axis
    ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks());
    tickMarks.sort(
            (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition()));

    if (tickMarks.isEmpty() == false) {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenBranchLabel = dateTime.branch;
        //cumulative width of the current branch label

        //x-positions (pixels) of the current branch and leaf labels
        double leafLabelX = 0;

        if (dateTime.branch.isEmpty()) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX,
                        isTickBold(t.getValue()));

                leafLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state
            double branchLabelX = 0;
            double branchLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) { //for each tick

                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still on the same branch
                if (lastSeenBranchLabel.equals(dateTime.branch)) {
                    //increment branch width
                    branchLabelWidth += spacing;
                } else {// we are on to a new branch, so ...
                    assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
                    //and then update label, x-pos, and width
                    lastSeenBranchLabel = dateTime.branch;
                    branchLabelX += branchLabelWidth;
                    branchLabelWidth = spacing;
                }
                //add the label for the leaf (highest frequency part)
                assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue()));

                //increment leaf position
                leafLabelX += spacing;
            }
            //we have reached end so add branch label for current branch
            assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}