Example usage for javafx.collections ObservableList add

List of usage examples for javafx.collections ObservableList add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:fr.ericlab.sondy.core.DataManipulation.java

public ObservableList<String> getAvailableStopwords(AppVariables appVariables) {
    ObservableList<String> stopwordsList = FXCollections.observableArrayList();
    File dir = new File(appVariables.configuration.getWorkspace() + "/stopwords/");
    boolean error = false;
    if (!dir.exists()) {
        try {/*from  w w w. ja va2s. c o  m*/
            dir.mkdirs();
            InputStream twitterInputStream = DataManipulation.class
                    .getResource("/resources/stopwords/twitter(en)").openStream();
            InputStream commonInputStream = DataManipulation.class
                    .getResource("/resources/stopwords/common(en)").openStream();
            OutputStream twitterOutStream = new FileOutputStream(
                    new File(appVariables.configuration.getWorkspace() + "/stopwords/twitter(en)"));
            OutputStream commonOutStream = new FileOutputStream(
                    new File(appVariables.configuration.getWorkspace() + "/stopwords/common(en)"));
            IOUtils.copy(twitterInputStream, twitterOutStream);
            IOUtils.copy(commonInputStream, commonOutStream);
            IOUtils.closeQuietly(twitterInputStream);
            IOUtils.closeQuietly(twitterOutStream);
            IOUtils.closeQuietly(commonInputStream);
            IOUtils.closeQuietly(commonOutStream);
        } catch (IOException ex) {
            Logger.getLogger(DataManipulation.class.getName()).log(Level.SEVERE, null, ex);
            error = true;
            appVariables.addLogEntry("[global] can't access workspace");
        }
    }
    if (!error) {
        List<File> files = (List<File>) FileUtils.listFiles(dir, HiddenFileFilter.VISIBLE, null);
        for (File file : files) {
            stopwordsList.add("stopwords: " + file.getName());
        }
    }
    return stopwordsList;
}

From source file:de.bayern.gdi.gui.Controller.java

private ObservableList<ItemModel> collectServiceTypes(boolean isWfs2) {
    ReferencedEnvelope extendWFS = null;
    List<WFSMeta.Feature> features = dataBean.getWFSService().getFeatures();
    ObservableList<ItemModel> types = FXCollections.observableArrayList();
    if (!dataBean.getWFSService().isSimple()) {
        for (WFSMeta.Feature f : features) {
            if (isWfs2) {
                types.add(new FeatureModel(f, FILTER));
                types.add(new FeatureModel(f, BBOX));
            } else {
                types.add(new FeatureModel(f));
            }//from w  ww  .j a  v a  2  s . c o  m
            if (f.getBBox() != null) {
                if (extendWFS == null) {
                    extendWFS = f.getBBox();
                } else {
                    extendWFS.expandToInclude(f.getBBox());
                }
            }
        }
        types.add(new OverallFeatureTypeModel(features));
    }
    if (extendWFS != null) {
        wmsWfsMapHandler.setExtend(extendWFS);
    }
    return types;
}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Handle search and filter the service list.
 *
 * @param event the event/* ww w .  j  a v  a2  s.  com*/
 */
@FXML
protected void handleSearch(KeyEvent event) {
    if (!catalogReachable) {
        setStatusTextUI(I18n.getMsg("status.catalog-not-available"));
    }
    String currentText = this.searchField.getText();
    this.serviceList.getItems().clear();
    dataBean.resetCatalogLists();
    if (currentText == null || currentText.isEmpty()) {
        this.serviceList.setItems(this.dataBean.getServicesAsList());
    }

    String searchValue = currentText == null ? "" : currentText.toUpperCase();

    ObservableList<ServiceModel> subentries = FXCollections.observableArrayList();
    ObservableList<ServiceModel> all = this.dataBean.getServicesAsList();
    for (ServiceModel entry : all) {
        boolean match = entry.getName().toUpperCase().contains(searchValue);
        if (match) {
            subentries.add(entry);
        }
    }
    if (currentText != null && currentText.length() > 2) {
        Task task = new Task() {
            @Override
            protected Integer call() throws Exception {
                Platform.runLater(() -> {
                    searchButton.setVisible(false);
                    searchButton.setManaged(false);
                    progressSearch.setVisible(true);
                    progressSearch.setManaged(true);
                });
                if (catalogReachable) {
                    List<Service> catalog = dataBean.getCatalogService().getServicesByFilter(currentText);
                    for (Service entry : catalog) {
                        dataBean.addCatalogServiceToList(entry);
                    }
                    Platform.runLater(() -> {
                        for (Service entry : catalog) {
                            subentries.add(new ServiceModel(entry));
                        }
                    });
                }
                Platform.runLater(() -> {
                    progressSearch.setVisible(false);
                    progressSearch.setManaged(false);
                    searchButton.setManaged(true);
                    searchButton.setVisible(true);
                });
                return 0;
            }
        };
        Thread th = new Thread(task);
        if (catalogReachable) {
            setStatusTextUI(I18n.getMsg("status.calling-service"));
        }
        th.setDaemon(true);
        th.start();
    }
    this.serviceList.setItems(subentries);
}

From source file:ui.main.MainViewController.java

private void showConversations() {
    //show conversations in the conversaation list view
    try {/*from w w  w.j  ava 2 s  .c o  m*/
        ObservableList<HostedRoom> convs = FXCollections.observableArrayList();
        Collection<HostedRoom> c = MultiUserChat.getHostedRooms(connectionManager.getXMPPConnection(),
                "conference.".concat(connectionManager.getXMPPConnection().getServiceName()));
        if (c == null) {

        } else if (c.isEmpty()) {

        } else {
            Iterator<HostedRoom> i = c.iterator();
            while (i.hasNext()) {
                convs.add(i.next());
            }
            conversations.setItems(convs);
            conversations.setCellFactory(new GroupCellRenderer());
        }
    } catch (XMPPException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

private void updateProjectTabs(ProjectSettings projectSettings) {

    if (selectedIndexListener != null) {
        projectTabPane.getSelectionModel().selectedIndexProperty().removeListener(selectedIndexListener);
    }//  w w w.j av a2s.  co  m

    menuTabBindingSourceCode.setSettings(projectSettings, true);
    menuTabBindingHelp.setSettings(projectSettings, false);

    if (projectSettings != null) {
        selectedIndexListener = (obs, oldValue, newValue) -> projectSettings
                .setProperty(PROP_SELECTED_TAB_INDEX, newValue);
        projectTabPane.getSelectionModel().selectedIndexProperty().addListener(selectedIndexListener);

        selectedItemListener = (obs, oldTab, newTab) -> {
            butSaveFile.disableProperty().unbind();
            mnuSaveFile.disableProperty().unbind();
            butSaveFile.setDisable(true);
            mnuSaveFile.setDisable(true);
            if (newTab != null) {
                CodeTabData tabData = getData(newTab);
                Platform.runLater(() -> {
                    BooleanBinding scriptChangedBinding = Bindings.createBooleanBinding(
                            () -> !tabData.isDirty(), tabData.getTextProperty(),
                            tabData.getInitialTextProperty());
                    butSaveFile.disableProperty().bind(scriptChangedBinding);
                    mnuSaveFile.disableProperty().bind(scriptChangedBinding);

                    StringBinding tabTextBinding = Bindings.createStringBinding(() -> {
                        String text = tabData.getTabText();
                        if (tabData.isDirty()) {
                            text = "*" + text;
                        }
                        return text;
                    }, tabData.getTextProperty(), tabData.getInitialTextProperty());
                    newTab.textProperty().bind(tabTextBinding);
                });
            }

            Platform.runLater(() -> {
                menuTabBindingSourceCode.setSettings(projectSettings, true);
                menuTabBindingHelp.setSettings(projectSettings, false);

                butSaveAll.disableProperty().unbind();
                mnuSaveAll.disableProperty().unbind();
                butSaveAll.setDisable(true);
                mnuSaveAll.setDisable(true);

                List<BooleanBinding> saveBindings = new ArrayList<>();
                projectTabPane.getTabs().forEach(tab -> {
                    CodeTabData tabData = getData(tab);
                    saveBindings.add(Bindings.createBooleanBinding(() -> !tabData.isDirty(),
                            tabData.getTextProperty(), tabData.getInitialTextProperty()));
                });
                if (!saveBindings.isEmpty()) {
                    BooleanBinding binding = saveBindings.get(0);
                    for (int i = 1; i < saveBindings.size(); i++) {
                        binding = Bindings.and(binding, saveBindings.get(i));
                    }
                    mnuSaveAll.disableProperty().bind(binding);
                    butSaveAll.disableProperty().bind(binding);
                }
            });
        };
        projectTabPane.getSelectionModel().selectedItemProperty().addListener(selectedItemListener);
    }

    int selectedTabIndex = (projectSettings == null) ? 0
            : projectSettings.getProperty(PROP_SELECTED_TAB_INDEX, 0, false);

    ObservableList<Tab> tabs = projectTabPane.getTabs();
    tabs.clear();

    Tab selectedTab = null;
    List<String> openFiles = getOpenFiles(projectSettings);
    for (int i = 0; i < openFiles.size(); i++) {
        String filePath = openFiles.get(i);
        Tab addedTab = null;
        if (filePath.equals(FILE_ALIAS_SOURCE_CODE)) {
            addedTab = tabSourceCode;
            String projectPath = projectPathProperty.get();
            String tabText = (projectPath == null) ? "Code" : new File(projectPath).getName();
            tabSourceCode.setUserData(new CodeTabData(tabText));
        } else if (filePath.equals(FILE_ALIAS_HELP)) {
            addedTab = tabHelp;
        } else {
            try {
                File file = new File(filePath);
                addedTab = CodeAreaTab.fromFile(file);
                final Tab tab = addedTab;
                tab.setOnCloseRequest(ev -> {
                    if (!tryClose(tab))
                        ev.consume();
                });
            } catch (Exception e) {
                addedTab = null;
            }
        }
        if (addedTab != null) {
            tabs.add(addedTab);
            getData(addedTab).setFilePath(filePath);
            if (i == selectedTabIndex) {
                selectedTab = addedTab;
            }
        }
    }
    if (!tabs.isEmpty()) {
        if (selectedTab == null) {
            selectedTab = tabs.get(0);
        }
        projectTabPane.getSelectionModel().select(null);
        projectTabPane.getSelectionModel().select(selectedTab);
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public void renderRows() {
    guiAnimationQueue.submit(() -> {/*from  www . ja  v a  2s.  c om*/
        ObservableList<Row> generatedRows = FXCollections.observableArrayList();

        for (int r = 0; r < board.getRowCount(); r++) {
            List<String> values = new ArrayList<>();

            for (int c = 0; c < board.getColumnCount(); c++) {
                if (board.getPlayerAt(r, c) == null) {
                    values.add("");
                } else if (board.getPlayerAt(r, c) == board.getPlayer1()) {
                    values.add(player1Letter);
                } else if (board.getPlayerAt(r, c) == board.getPlayer2()) {
                    values.add(player2Letter);
                }
            }

            generatedRows.add(new Row(values));
        }

        gameTable.setItems(generatedRows);

        double effectiveHeight = gameTable.getHeight() - 5;
        long fontSize = Math.round((effectiveHeight - 250) / board.getRowCount());

        // get letter widths;
        if (rowFont != null) {
            Font font = new Font(rowFont.getName(), fontSize);
            double player1SymbolWidth = Toolkit.getToolkit().getFontLoader().computeStringWidth(player1Letter,
                    font);
            double player2SymbolWidth = Toolkit.getToolkit().getFontLoader().computeStringWidth(player2Letter,
                    font);

            // make the font smaller so that it fits the cell even if the width is very small
            while (player1SymbolWidth > (gameTable.getWidth() / board.getColumnCount())
                    || player2SymbolWidth + 10 > (gameTable.getWidth() / board.getColumnCount())) {
                fontSize = fontSize - 1;
                font = new Font(rowFont.getName(), fontSize);
                player1SymbolWidth = Toolkit.getToolkit().getFontLoader().computeStringWidth(player1Letter,
                        font);
                player2SymbolWidth = Toolkit.getToolkit().getFontLoader().computeStringWidth(player2Letter,
                        font);
            }
            style.set("-fx-font-size:" + fontSize + "px; -fx-padding: 0;");
        }

        gameTable.setFixedCellSize(effectiveHeight / board.getRowCount());
        gameTable.refresh();
    });
}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Sets the Service Types.//from   w w  w  . ja v a  2s . c o  m
 */
public void setServiceTypes() {
    if (dataBean.isWebServiceSet()) {
        switch (dataBean.getServiceType()) {
        case WFS_ONE:
        case WFS_TWO:
            boolean isWfs2 = WFS_TWO.equals(dataBean.getServiceType());
            ObservableList<ItemModel> types = collectServiceTypes(isWfs2);
            addStoredQueries(types);
            serviceTypeChooser.getItems().retainAll();
            serviceTypeChooser.setItems(types);
            serviceTypeChooser.setValue(types.get(0));
            chooseType(serviceTypeChooser.getValue());
            break;
        case ATOM:
            List<Atom.Item> items = dataBean.getAtomService().getItems();
            ObservableList<ItemModel> opts = FXCollections.observableArrayList();
            List<FeaturePolygon> polygonList = new ArrayList<>();
            //Polygons are always epsg:4326
            // (http://www.georss.org/gml.html)
            try {
                ReferencedEnvelope extendATOM = null;
                CoordinateReferenceSystem atomCRS = CRS.decode(ATOM_CRS_STRING);
                Geometry all = null;
                for (Atom.Item i : items) {
                    opts.add(new AtomItemModel(i));
                    FeaturePolygon polygon = new FeaturePolygon(i.getPolygon(), i.getTitle(), i.getID(),
                            atomCRS);
                    polygonList.add(polygon);
                    all = all == null ? i.getPolygon() : all.union(i.getPolygon());
                }
                if (wmsAtomMapHandler != null) {
                    if (all != null) {
                        extendATOM = new ReferencedEnvelope(all.getEnvelopeInternal(), atomCRS);
                        wmsAtomMapHandler.setExtend(extendATOM);
                    }
                    wmsAtomMapHandler.drawPolygons(polygonList);
                }
            } catch (FactoryException e) {
                log.error(e.getMessage(), e);
            }
            serviceTypeChooser.getItems().retainAll();
            serviceTypeChooser.setItems(opts);
            if (!opts.isEmpty()) {
                serviceTypeChooser.setValue(opts.get(0));
                chooseType(serviceTypeChooser.getValue());
            }
            break;
        default:
        }
    }
}