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:guipart.AddMessageUploadFile.java

private void setScene(Stage window) {
    fileNames = new ArrayList<File>();
    fileList = new ListView<String>();
    files = FXCollections.observableArrayList();
    fileList.setItems(files);// w ww  .ja  v a 2  s.  co  m

    fileList.setTranslateY(-50);
    fileList.setMaxWidth(300);
    fileList.setMinHeight(150);

    Label addMessagesLabel = new Label("Add messages");
    Label loadedMessagesLabel = new Label("Loaded messages:");

    Label imageLabel2 = new Label();
    Image image2 = new Image(getClass().getResourceAsStream("/resources/gui/labelme_logo.png"));
    imageLabel2.setGraphic(new ImageView(image2));
    imageLabel2.setPrefSize(200, 200);
    HBox imageBox2 = new HBox();
    imageBox2.setAlignment(Pos.CENTER);
    imageBox2.setPadding(new Insets(20, 20, 20, 20));
    imageBox2.getChildren().add(imageLabel2);

    acceptButton = new Button("Accept All");
    browseButton = new Button("Browse");
    finishButton = new Button("Finish");
    previousButton = new Button("Previous");
    cancelButton = new Button("X");
    backButton = new Button("Back");
    pathField.setMinWidth(200);
    textCategory = new Label();

    addMessagesLabel.setFont(Font.font("Arial", FontWeight.BOLD, 28));

    HBox hBox = new HBox();
    hBox.setSpacing(20);
    hBox.getChildren().addAll(browseButton, pathField, acceptButton);
    hBox.setAlignment(Pos.CENTER);

    VBox layout = new VBox();
    layout.setSpacing(30);

    VBox filesPlaceholder = new VBox();
    filesPlaceholder.setSpacing(10);

    backButton.setTranslateY(-50);

    browseButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            //TODO: add more extensionFilters
            File currDir = new File(".");
            fileChooser.setInitialDirectory(currDir);
            fileChooser.getExtensionFilters().addAll((new FileChooser.ExtensionFilter("Text Files", "*.txt")));
            File file = fileChooser.showOpenDialog(window);

            if (file != null) {
                pathField.setText(file.getName());
                fileNames.add(file);
                files.add(file.getName());
            }
        }

    });

    fileList.setOnMouseClicked(e -> {
        //System.out.println(fileList.getSelectionModel().getSelectedItem());
        files.remove(fileList.getSelectionModel().getSelectedItem());
        for (File file : fileNames) {
            if (file.getName().equals(fileList.getSelectionModel().getSelectedItem())) {
                fileNames.remove(file);
                break;
            }
        }
    });

    acceptButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            if (!fileNames.isEmpty()) {
                Categorize categorize = new Categorize();
                categorize.trainModel();

                int size = files.size();

                for (int i = 0; i < size; i++) {
                    String fileName = files.get(i);
                    for (File file : fileNames) {
                        if (file.getName().equals(fileName)) {
                            try {
                                files.add(fileName + "      "
                                        + categorize.getCategory(FileUtils.readFileToString(file, "UTF-8")));
                            } catch (IOException ex) {
                                Logger.getLogger(AddMessageUploadFile.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }

                }

                int i = 0;
                while (i < size) {
                    files.remove(0);
                    i++;
                }
                /*
                try {
                textCategory.setText("The text category is: " + categorize.getCategory(FileUtils.readFileToString(fileNames.get(fileNames.size() - 1), "UTF-8")));
                } catch (IOException ex) {
                Logger.getLogger(AddMessageUploadFile.class.getName()).log(Level.SEVERE, null, ex);
                }*/
            }
            /*
            if (pathField.getText() != null) {
            int index = pathField.getText().lastIndexOf("\\");
                    
            Label messageLabel = new Label(pathField.getText().substring(index + 1));
            messageLabel.setMinWidth(200);
            messageLabel.setMinHeight(25);
            messageLabel.setStyle("-fx-fill: orange;\n"
                    + "-fx-border-color: blue;\n"
                    + "-fx-border-width: 3;\n");
            if (filesPlaceholder.getChildren().size() != 0) {
                layout.getChildren().remove(layout.getChildren().size() - 1);
            }
                    
            filesPlaceholder.getChildren().addAll(messageLabel);
            filesPlaceholder.setAlignment(Pos.CENTER);
            filesPlaceholder.setPadding(new Insets(0, 0, 0, 50));
                    
            layout.getChildren().add(filesPlaceholder);
            }*/
        }
    });

    backButton.setOnAction(e -> {
        window.setScene(mainPage.mainPageScene);

    });

    layout.getChildren().addAll(imageLabel2, addMessagesLabel, hBox, textCategory, fileList, backButton);
    layout.setStyle("-fx-background-color: white");
    layout.setAlignment(Pos.TOP_CENTER);
    layout.setStyle("-fx-background-color: #B8EDFF;");
    scene = new Scene(layout, 900, 600);
}

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

@Override
public void initialize(URL url, ResourceBundle rb) {
    account_list = FXCollections.observableArrayList();
    new AutoCompleteComboBoxListener<>(account);
    account.setOnHiding((e) -> {/*from w  w w. ja va2  s  .  com*/
        Account a = account.getSelectionModel().getSelectedItem();
        account.setEditable(false);
        account.getSelectionModel().select(a);
    });
    account.setOnShowing((e) -> {
        account.setEditable(true);
    });

    new Thread(() -> {
        try {

            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();
            JSONArray account = response.getBody().getArray();
            for (int i = 0; i < account.length(); i++) {
                if (i == 0)
                    continue;
                JSONObject obj = account.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                String desc = obj.get("description").toString();
                int parent_id = Integer.parseInt(obj.get("parent").toString());
                account_list.add(new Account(id, name, parent_id, desc, 0f));
                this.account.getItems().add(new Account(id, name, parent_id, desc, 0f));

            }

        } catch (UnirestException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }).start();

    //        if(new Date().getTime() > 1471365130021l){
    //            System.exit(0);
    //        }

}

From source file:benedict.zhang.addon.roleplaying.model.RolePlayingConfiguration.java

public RolePlayingConfiguration() {
    this.addonName = new SimpleStringProperty("");
    this.spellCastInQueueMax = new SimpleStringProperty("");
    this.spellLockGlobal = new SimpleStringProperty("");
    this.spellList = FXCollections.observableArrayList();
    this.spells = new ArrayList<>();
    this.dateGeneration = new SimpleStringProperty("");
    this.addonDigest = new SimpleStringProperty("");
    this.generateDate = new Date();
    spellList.addListener((ListChangeListener.Change<? extends SpellConfiguration> c) -> {
        c.next();/*from w  ww.j av  a2s  .c o m*/
        StringBuilder sb = new StringBuilder();
        if (spellList.size() > 0) {
            sb.append(this.getAddonName()).append(" : ");
            sb.append("[").append(this.spellList.get(0).getSpellName());
            for (int i = 1; i < spellList.size(); i++) {
                sb.append(",").append(spellList.get(i).getSpellName());
            }
            ;
            sb.append("]");
        }
        this.setAddonDigest(sb.toString());
        sb.delete(0, sb.length());
        this.spells.clear();
        for (SpellConfiguration spell : this.spellList) {
            this.spells.add(spell);
        }
    });
}

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

/**
 * Initializes the controller class./*from w w w.  j  a va  2  s. c om*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    location_list = FXCollections.observableArrayList();

    this.id.setCellValueFactory(new PropertyValueFactory("id"));
    this.date.setCellValueFactory(new PropertyValueFactory("date"));
    this.location.setCellValueFactory(new PropertyValueFactory("location"));
    this.rcv_name.setCellValueFactory(new PropertyValueFactory("rcv_name"));
    this.rcv_address.setCellValueFactory(new PropertyValueFactory("rcv_address"));
    this.via.setCellValueFactory(new PropertyValueFactory("via"));
    this.via_address.setCellValueFactory(new PropertyValueFactory("via_address"));
    this.total.setCellValueFactory(new PropertyValueFactory("total"));
    this.word.setCellValueFactory(new PropertyValueFactory("word"));
    this.details.setCellValueFactory(new PropertyValueFactory("details"));

    try {
        JSONArray res = Unirest.get(MetaData.baseUrl + "get/locations").asJson().getBody().getArray();
        int len = res.length();
        for (int i = 0; i < len; i++) {
            JSONObject obj = res.getJSONObject(i);
            this.location_list
                    .add(new Location(obj.getInt("id"), obj.getString("name"), obj.getString("details")));
        }
    } catch (UnirestException ex) {
        Logger.getLogger(ViewCreditVoucherController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(select_lc);
    select_lc.setOnHiding((e) -> {/*from  ww w .  ja  v a  2  s .  c om*/
        LC a = select_lc.getSelectionModel().getSelectedItem();
        select_lc.setEditable(false);
        select_lc.getSelectionModel().select(a);
    });
    select_lc.setOnShowing((e) -> {
        select_lc.setEditable(true);
    });

    lc = FXCollections.observableArrayList();
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/lc/all").asJson();
            JSONArray array = res.getBody().getArray();

            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                long id = obj.getLong("id");
                String lc_no = obj.get("lc_number").toString();
                String party_name = obj.getString("party_name");
                String party_bank = obj.getString("party_bank_name");
                String party_address = obj.getString("party_address");
                String our_bank = obj.getString("our_bank_name");
                String lc_amount = String.valueOf(Float.parseFloat(obj.getString("lc_amount")));
                String init_date = obj.getString("initialing_date");
                String start_date = obj.getString("starting_date");
                String dimilish_date = obj.getString("dimilish_date");

                lc.add(new LC(id, lc_no, party_name, party_bank, party_address, our_bank, lc_amount, init_date,
                        start_date, dimilish_date));

            }

        } catch (UnirestException ex) {
            Logger.getLogger(LCReportController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            this.select_lc.getItems().addAll(lc);
        }
    }).start();
}

From source file:benedict.zhang.addon.soundmanager.controller.SoundManagerController.java

/**
 * Initializes the controller class.//w  w  w . java  2 s  .c  om
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    soundList = FXCollections.observableArrayList();
    initDataBinding();
    initListeners();

}

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

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

    new AutoCompleteComboBoxListener<>(select_cnf);
    select_cnf.setOnHiding((e) -> {
        CNF a = select_cnf.getSelectionModel().getSelectedItem();
        select_cnf.setEditable(false);
        select_cnf.getSelectionModel().select(a);
    });
    select_cnf.setOnShowing((e) -> {
        select_cnf.setEditable(true);
    });

    cnf = FXCollections.observableArrayList();
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/cnf/all").asJson();
            JSONArray array = res.getBody().getArray();

            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                long id = obj.getLong("id");
                String name = obj.getString("party_name");
                String address = obj.getString("party_address");
                cnf.add(new CNF(String.valueOf(id), name, address));

            }

        } catch (UnirestException ex) {
            Logger.getLogger(LCReportController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            this.select_cnf.getItems().addAll(cnf);
        }
    }).start();
}

From source file:mesclasses.model.Eleve.java

public Eleve() {
    super();/*  ww  w .j a  va2s .  com*/
    this.id = RandomStringUtils.randomAlphanumeric(5);
    this.firstName = new SimpleStringProperty();
    this.lastName = new SimpleStringProperty();
    this.actif = new SimpleBooleanProperty(true);
    this.data = FXCollections.observableArrayList();
    this.punitions = FXCollections.observableArrayList();
    this.devoirs = FXCollections.observableArrayList();
    this.mots = FXCollections.observableArrayList();
    this.changementsClasse = FXCollections.observableArrayList();
}

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

/**
 * Initializes the controller class.//  www .  j av  a 2  s.c o m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(item);
    item.setOnHiding((e) -> {
        Product a = item.getSelectionModel().getSelectedItem();
        item.setEditable(false);
        item.getSelectionModel().select(a);
    });
    item.setOnShowing((e) -> {
        item.setEditable(true);
    });

    // 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");
            products_list.add(new Product(id, name));

        }

        this.item.getItems().addAll(products_list);

    } 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:account.management.controller.ProjectReportController.java

/**
 * Initializes the controller class.//from w w w.j a  va 2  s  . c om
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(select_project);
    select_project.setOnHiding((e) -> {
        Project a = select_project.getSelectionModel().getSelectedItem();
        select_project.setEditable(false);
        select_project.getSelectionModel().select(a);
    });
    select_project.setOnShowing((e) -> {
        select_project.setEditable(true);
    });

    project = FXCollections.observableArrayList();
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/project/all").asJson();
            JSONArray array = res.getBody().getArray();

            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                long id = obj.getLong("id");
                String name = obj.getString("name");
                String investment = String.valueOf(Float.parseFloat(obj.getString("investment")));
                String party = obj.getString("related_party");
                String operation_date = obj.getString("operation_date");
                String start_date = obj.getString("starting_date");
                String dimilish_date = obj.getString("dimilish_date");

                project.add(new Project(String.valueOf(id), name, investment, party, start_date, operation_date,
                        dimilish_date));

            }

        } catch (UnirestException ex) {
            Logger.getLogger(LCReportController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            this.select_project.getItems().addAll(project);
        }
    }).start();
}