Example usage for javafx.collections ObservableList indexOf

List of usage examples for javafx.collections ObservableList indexOf

Introduction

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

Prototype

int indexOf(Object o);

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:de.micromata.mgc.javafx.launcher.gui.AbstractConfigDialog.java

protected void addCss() {
    ObservableList<String> list = getParent().getScene().getStylesheets();
    if (list.indexOf(FXCssUtil.CSS) == -1) {
        list.add(FXCssUtil.CSS);//  w  ww .ja v  a 2s .  c om
    }
    list = getScene().getStylesheets();
    if (list.indexOf(FXCssUtil.CSS) == -1) {
        list.add(FXCssUtil.CSS);
    }
}

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

/**
 * Resets all marks at the processing chain container, items are kept.
 *///from ww  w. j  a  va2 s  . co m
private void resetProcessingChainContainer() {
    for (Node o : chainContainer.getChildren()) {
        if (o instanceof VBox) {
            VBox v = (VBox) o;
            HBox hbox = (HBox) v.getChildren().get(0);
            Node cBox = hbox.getChildren().get(0);
            if (cBox instanceof ComboBox) {
                cBox.setStyle(FX_BORDER_COLOR_NULL);
                ComboBox box = (ComboBox) cBox;
                ObservableList<ProcessingStepConfiguration> confs = (ObservableList<ProcessingStepConfiguration>) box
                        .getItems();
                for (ProcessingStepConfiguration cfgI : confs) {
                    cfgI.setCompatible(true);
                    confs.set(confs.indexOf(cfgI), cfgI);
                }
            }
        }
    }
}

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

/**
 * Validates the chain items of a ComboBox
 * and marks the box according to the chosen item.
 *
 * @param box Item to validate/*from   w  w  w. j  av  a2  s  .  c  o m*/
 * @return True if chosen item is valid, else false
 */
private boolean validateChainContainer(ComboBox box) {
    String format = this.dataBean.getAttributeValue(OUTPUTFORMAT);
    if (format == null) {
        box.setStyle(FX_BORDER_COLOR_RED);
        setStatusTextUI(I18n.format(GUI_PROCESS_NO_FORMAT));
    }
    MIMETypes mtypes = Config.getInstance().getMimeTypes();
    MIMEType mtype = mtypes.findByName(format);

    ProcessingStepConfiguration cfg = (ProcessingStepConfiguration) box.getValue();
    ObservableList<ProcessingStepConfiguration> items = (ObservableList<ProcessingStepConfiguration>) box
            .getItems();

    if (format != null && mtype == null) {
        box.setStyle(FX_BORDER_COLOR_RED);
        for (ProcessingStepConfiguration cfgI : items) {
            cfgI.setCompatible(false);
            //Workaround to force cell update
            items.set(items.indexOf(cfgI), cfgI);
        }
        setStatusTextUI(I18n.format(GUI_PROCESS_FORMAT_NOT_FOUND));
        return false;
    }

    //Mark items that are incompatible
    for (ProcessingStepConfiguration cfgI : items) {
        if (format != null) {
            cfgI.setCompatible(cfgI.isCompatibleWithFormat(mtype.getType()));
        } else {
            cfgI.setCompatible(false);
        }
        items.set(items.indexOf(cfgI), cfgI);
    }

    if (format == null) {
        return false;
    }

    if (cfg == null) {
        box.setStyle(FX_BORDER_COLOR_NULL);
        return true;
    }

    if (cfg.isCompatible()) {
        box.setStyle(FX_BORDER_COLOR_NULL);
    } else {
        box.setStyle(FX_BORDER_COLOR_RED);
        setStatusTextUI(I18n.format(GUI_PROCESS_NOT_COMPATIBLE, box.getValue()));
    }
    return cfg.isCompatible();
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.drawableviews.GroupPane.java

@ThreadConfined(type = ThreadType.JFX)
private void scrollToFileID(final Long newFileID) {
    if (newFileID == null) {
        return; //scrolling to no file doesn't make sense, so abort.
    }//from   w w  w  .ja  va 2  s  . c om

    final ObservableList<Long> fileIds = gridView.getItems();

    int selectedIndex = fileIds.indexOf(newFileID);
    if (selectedIndex == -1) {
        //somehow we got passed a file id that isn't in the curent group.
        //this should never happen, but if it does everything is going to fail, so abort.
        return;
    }

    getScrollBar().ifPresent(scrollBar -> {
        DrawableCell cell = cellMap.get(newFileID);

        //while there is no tile/cell for the given id, scroll based on index in group
        while (isNull(cell)) {
            //TODO:  can we maintain a cached mapping from fileID-> index to speed up performance
            //get the min and max index of files that are in the cellMap
            Integer minIndex = cellMap.keySet().stream().mapToInt(fileID -> fileIds.indexOf(fileID)).min()
                    .getAsInt();
            Integer maxIndex = cellMap.keySet().stream().mapToInt(fileID -> fileIds.indexOf(fileID)).max()
                    .getAsInt();

            //[minIndex, maxIndex] is the range of indexes in the fileIDs list that are currently displayed
            if (selectedIndex < minIndex) {
                scrollBar.decrement();
            } else if (selectedIndex > maxIndex) {
                scrollBar.increment();
            } else {
                //sometimes the cellMap isn't up to date, so move the position arbitrarily to update the cellMap
                //TODO: this is clunky and slow, find a better way to do this
                scrollBar.adjustValue(.5);
            }
            cell = cellMap.get(newFileID);
        }

        final Bounds gridViewBounds = gridView.localToScene(gridView.getBoundsInLocal());
        Bounds tileBounds = cell.localToScene(cell.getBoundsInLocal());

        //while the cell is not within the visisble bounds of the gridview, scroll based on screen coordinates
        int i = 0;
        while (gridViewBounds.contains(tileBounds) == false && (i++ < 100)) {

            if (tileBounds.getMinY() < gridViewBounds.getMinY()) {
                scrollBar.decrement();
            } else if (tileBounds.getMaxY() > gridViewBounds.getMaxY()) {
                scrollBar.increment();
            }
            tileBounds = cell.localToScene(cell.getBoundsInLocal());
        }
    });
}