Example usage for javafx.collections FXCollections observableArrayList

List of usage examples for javafx.collections FXCollections observableArrayList

Introduction

In this page you can find the example usage for javafx.collections FXCollections observableArrayList.

Prototype

@SuppressWarnings("unchecked")
public static <E> ObservableList<E> observableArrayList() 

Source Link

Document

Creates a new empty observable list that is backed by an arraylist.

Usage

From source file:Main.java

private ObservableList<XYChart.Series<String, Double>> getChartData() {
    double aValue = 17.56;
    double cValue = 17.06;
    ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList();
    Series<String, Double> aSeries = new Series<String, Double>();
    Series<String, Double> cSeries = new Series<String, Double>();
    aSeries.setName("a");
    cSeries.setName("C");

    for (int i = 2011; i < 2021; i++) {
        aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue));
        aValue = aValue + Math.random() - .5;
        cSeries.getData().add(new XYChart.Data(Integer.toString(i), cValue));
        cValue = cValue + Math.random() - .5;
    }//w w w .  j  a  va2 s. com
    answer.addAll(aSeries, cSeries);
    return answer;
}

From source file:Main.java

private ObservableList<XYChart.Series<String, Double>> getChartData() {
    double aValue = 1.56;
    double cValue = 1.06;
    ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList();
    Series<String, Double> aSeries = new Series<String, Double>();
    Series<String, Double> cSeries = new Series<String, Double>();
    aSeries.setName("a");
    cSeries.setName("C");

    for (int i = 2011; i < 2021; i++) {
        aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue));
        aValue = aValue + Math.random() - .5;
        cSeries.getData().add(new XYChart.Data(Integer.toString(i), cValue));
        cValue = cValue + Math.random() - .5;
    }/*w w  w. j a  v a2  s.c  o m*/
    answer.addAll(aSeries, cSeries);
    return answer;
}

From source file:Main.java

private ObservableList<XYChart.Series<Integer, Double>> getChartData() {
    double aValue = 1.56;
    double bValue = 1.06;
    ObservableList<XYChart.Series<Integer, Double>> answer = FXCollections.observableArrayList();
    Series<Integer, Double> aSeries = new Series<Integer, Double>();
    Series<Integer, Double> bSeries = new Series<Integer, Double>();
    aSeries.setName("A");
    bSeries.setName("B");
    for (int i = 2011; i < 2016; i++) {
        double diff = Math.random();
        aSeries.getData().add(new XYChart.Data(i, aValue, diff));
        aValue = aValue + 10 * diff - 5;
        diff = Math.random();//from   w  w w . j ava 2 s .  c om
        bSeries.getData().add(new XYChart.Data(i, bValue, diff));
        bValue = bValue + 10 * diff - 5;
        diff = Math.random();
    }
    answer.addAll(aSeries, bSeries);
    return answer;
}

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

/**
 * Initializes the controller class./*from w  ww .j a v  a  2s.com*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    bank_list = FXCollections.observableArrayList();
    id.setCellValueFactory(new PropertyValueFactory("id"));
    name.setCellValueFactory(new PropertyValueFactory("name"));
    description.setCellValueFactory(new PropertyValueFactory("description"));
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "bank").asJson();
            JSONArray array = res.getBody().getArray();
            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                int id = obj.getInt("id");
                String name = obj.getString("name");
                String desc = obj.getString("description");
                Account acc = new Account(id, name, desc);
                bank_list.add(acc);
            }
        } catch (UnirestException ex) {
            Msg.showError("");
        } finally {
            this.table.getItems().addAll(bank_list);
        }
    }).start();
}

From source file:Main.java

private TreeItem<File> createNode(final File f) {
    return new TreeItem<File>(f) {
        private boolean isLeaf;
        private boolean isFirstTimeChildren = true;
        private boolean isFirstTimeLeaf = true;

        @Override//from  w w  w.ja v a2  s . c o  m
        public ObservableList<TreeItem<File>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                File f = (File) getValue();
                isLeaf = f.isFile();
            }

            return isLeaf;
        }

        private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) {
            File f = TreeItem.getValue();
            if (f != null && f.isDirectory()) {
                File[] files = f.listFiles();
                if (files != null) {
                    ObservableList<TreeItem<File>> children = FXCollections.observableArrayList();

                    for (File childFile : files) {
                        children.add(createNode(childFile));
                    }

                    return children;
                }
            }

            return FXCollections.emptyObservableList();
        }
    };
}

From source file:account.management.controller.inventory.StockReportController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    product_list = FXCollections.observableArrayList();

    try {/*  w ww.j a v  a 2s . c  o m*/
        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson();
        JSONArray array = res.getBody().getArray();
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            int id = obj.getInt("id");
            String name = obj.getString("name");
            float p_qty = Float.parseFloat(obj.get("p_qty").toString());
            float s_qty = Float.parseFloat(obj.get("s_qty").toString());
            double last_p_rate = obj.getDouble("last_p_rate");
            double last_s_rate = obj.getDouble("last_s_rate");
            double avg_p_rate = obj.getDouble("avg_p_rate");
            double avg_s_rate = obj.getDouble("avg_s_rate");

            product_list
                    .add(new Product(id, name, p_qty, s_qty, last_p_rate, last_s_rate, avg_p_rate, avg_s_rate));

        }
    } catch (Exception e) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setHeaderText(null);
        alert.setContentText("Sorry!! there is an error in the server. Please try again.");
        alert.setGraphic(new ImageView(new Image("resources/error.jpg")));
        alert.showAndWait();
    }

}

From source file:Main.java

public void search(String oldVal, String newVal) {
    if (oldVal != null && (newVal.length() < oldVal.length())) {
        list.setItems(entries);//from   w w  w  .j av a2 s.  c  o m
    }
    String value = newVal.toUpperCase();
    ObservableList<String> subentries = FXCollections.observableArrayList();
    for (Object entry : list.getItems()) {
        boolean match = true;
        String entryText = (String) entry;
        if (!entryText.toUpperCase().contains(value)) {
            match = false;
            break;
        }
        if (match) {
            subentries.add(entryText);
        }
    }
    list.setItems(subentries);
}

From source file:javafxapplication2.FXMLDocumentController.java

public FXMLDocumentController() {
    this.rowDataList = FXCollections.observableArrayList();
}

From source file:Main.java

private TreeItem<File> createNode(final File f) {
    return new TreeItem<File>(f) {
        private boolean isLeaf;
        private boolean isFirstTimeChildren = true;
        private boolean isFirstTimeLeaf = true;

        @Override//  w  w  w  .  ja va  2s .  co  m
        public ObservableList<TreeItem<File>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                File f = (File) getValue();
                isLeaf = f.isFile();
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) {
            File f = TreeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            if (f.isFile()) {
                return FXCollections.emptyObservableList();
            }
            File[] files = f.listFiles();
            if (files != null) {
                ObservableList<TreeItem<File>> children = FXCollections.observableArrayList();
                for (File childFile : files) {
                    children.add(createNode(childFile));
                }
                return children;
            }
            return FXCollections.emptyObservableList();
        }
    };
}

From source file:account.management.controller.inventory.InsertStockController.java

/**
 * Initializes the controller class.//from w  ww.j  a v  a2  s. c o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    // get product list
    products_list = FXCollections.observableArrayList();
    try {
        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson();
        JSONArray array = res.getBody().getArray();
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            int id = obj.getInt("id");
            String name = obj.getString("name");
            float p_qty = Float.parseFloat(obj.get("p_qty").toString());
            float s_qty = Float.parseFloat(obj.get("s_qty").toString());
            double last_p_rate = obj.getDouble("last_p_rate");
            double last_s_rate = obj.getDouble("last_s_rate");
            double avg_p_rate = obj.getDouble("avg_p_rate");
            double avg_s_rate = obj.getDouble("avg_s_rate");

            products_list
                    .add(new Product(id, name, p_qty, s_qty, last_p_rate, last_s_rate, avg_p_rate, avg_s_rate));

        }

        addRow();

    } catch (Exception e) {
    }

    // voucher type (purchase/sell)
    this.voucher_type.getItems().addAll("Purchase", "Sell");
    this.voucher_type.getSelectionModel().select("Sell");

}