Java Code Examples for javafx.collections.ObservableList#indexOf()

The following examples show how to use javafx.collections.ObservableList#indexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigController.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
/**
 * 删除配置
 *
 * @param generatorConfig 配置信息
 */
private void deleteConfig(Button button, GeneratorConfig generatorConfig) {
    ObservableList<Node> children = centerVBox.getChildren();
    int size = children.size();
    if (size == 1) {
        exportController.clearPane();
    } else {
        int i = children.indexOf(button);
        if (i == 0) {
            exportController.showConfig(configNameConfigMap.get(((Button) children.get(1)).getText()));
        } else {
            exportController.showConfig(configNameConfigMap.get(((Button) children.get(0)).getText()));
        }
    }
    children.remove(button);
    configService.deleteConfig(generatorConfig);
}
 
Example 2
Source File: EQUsController.java    From CPUSim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Duplicates the currently selected item in
 * the table of EQUs, if there is one. Called
 * when the "Duplicate" button is clicked.
 */
public void onDuplicateButtonClicked() {
    ObservableList<EQU> data = equsTable.getItems();
    int index = data.indexOf(selectedSet);
    if (index >= 0) {
        // Make new EQU and add to table
        EQU newSet = (EQU) (selectedSet.clone());
        String orig = newSet.getName() + "_copy";
        String s = newSet.getName() + "_copy";
        List<String> names = getNames();
        int i = 1;
        while (names.contains(s)) {
            s = s.substring(0, orig.length()) + String.valueOf(i);
            i++;
        }
        newSet.setName(s);
        data.add(0, newSet);

        // Select and Scroll to
        equsTable.getSelectionModel().clearSelection();
        equsTable.getSelectionModel().selectFirst();
        equsTable.scrollTo(0);
    }
    updateButtonEnabling();
}
 
Example 3
Source File: EQUsController.java    From CPUSim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Deletes the currently selected item from
 * the table of EQUs, if there is one. Called
 * when the "Delete" button is clicked.
 */
public void onDeleteButtonClicked() {
    ObservableList<EQU> data = equsTable.getItems();
    int index = data.indexOf(selectedSet);
    if (index >= 0) {
        data.remove(index);
        equsTable.setItems(data);
    }

    // Select Correctly
    int indexToSelect = index - 1 < 0 ? index : index - 1;
    if (equsTable.getItems().size() > 0) {
        equsTable.getSelectionModel().clearSelection();
        equsTable.getSelectionModel().select(indexToSelect);
    }

    updateButtonEnabling();
}
 
Example 4
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void bringForward(ActionEvent event) {
	if (cursorRegion.isPresent() && !targetRegions.contains(cursorRegion.get())) return;

	int selectedIndex = targetRegions.indexOf(cursorRegion.get());

	if (selectedIndex < targetRegions.size() - 1) {
		Collections.swap(targetRegions, selectedIndex, selectedIndex + 1);

		// Get the index separately for the shapes list because the target
		// region
		// list has fewer items (e.g. no background)
		final ObservableList<Node> shapesList = canvasPane.getChildren();
		selectedIndex = shapesList.indexOf(cursorRegion.get());

		// We have to do this dance instead of just calling
		// Collections.swap otherwise we get an IllegalArgumentException
		// from the Scene for duplicating a child node
		final Node topShape = shapesList.get(selectedIndex + 1);
		final Node bottomShape = shapesList.get(selectedIndex);
		shapesList.remove(selectedIndex + 1);
		shapesList.remove(selectedIndex);
		shapesList.add(selectedIndex, topShape);
		shapesList.add(selectedIndex + 1, bottomShape);
	}
}
 
Example 5
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleKey(final KeyEvent event)
{
    if (event.getCode() == KeyCode.TAB)
    {
        // Commit value from combo's text field into combo's value...
        combo.commitValue();
        // .. and use that for the cell
        commitEdit(combo.getValue());

        // Edit next/prev column in same row
        final ObservableList<TableColumn<List<ObservableCellValue>, ?>> columns = getTableView().getColumns();
        final int col = columns.indexOf(getTableColumn());
        final int next = event.isShiftDown()
                       ? (col + columns.size() - 1) % columns.size()
                       : (col + 1) % columns.size();
        editCell(getIndex(), columns.get(next));
        event.consume();
    }
}
 
Example 6
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void sendBackward(ActionEvent event) {
	if (cursorRegion.isPresent() && !targetRegions.contains(cursorRegion.get())) return;

	int selectedIndex = targetRegions.indexOf(cursorRegion.get());

	if (selectedIndex > 0) {
		Collections.swap(targetRegions, selectedIndex - 1, selectedIndex);

		final ObservableList<Node> shapesList = canvasPane.getChildren();
		selectedIndex = shapesList.indexOf(cursorRegion.get());

		final Node topShape = shapesList.get(selectedIndex);
		final Node bottomShape = shapesList.get(selectedIndex - 1);
		shapesList.remove(selectedIndex);
		shapesList.remove(selectedIndex - 1);
		shapesList.add(selectedIndex - 1, topShape);
		shapesList.add(selectedIndex, bottomShape);
	}
}
 
Example 7
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private String getTreeTableItemText(TreeTableView<?> treeTableView, TreeItem<?> lastPathComponent) {
    @SuppressWarnings("rawtypes")
    TreeTableColumn treeTableColumn = treeTableView.getTreeColumn();
    if (treeTableColumn == null) {
        treeTableColumn = treeTableView.getColumns().get(0);
    }
    ObservableValue<?> cellObservableValue = treeTableColumn.getCellObservableValue(lastPathComponent);
    String original = cellObservableValue.getValue().toString();
    String itemText = original;
    int suffixIndex = 0;
    TreeItem<?> parent = lastPathComponent.getParent();
    if (parent == null)
        return itemText;
    ObservableList<?> children = parent.getChildren();
    for (int i = 0; i < children.indexOf(lastPathComponent); i++) {
        TreeItem<?> child = (TreeItem<?>) children.get(i);
        cellObservableValue = treeTableColumn.getCellObservableValue(child);
        String current = cellObservableValue.getValue().toString();
        if (current.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example 8
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private String getTreeItemText(TreeItem<?> lastPathComponent) {
    if (lastPathComponent == null || lastPathComponent.getValue() == null) {
        return "";
    }
    String original = lastPathComponent.getValue().toString();
    String itemText = original;
    int suffixIndex = 0;
    TreeItem<?> parent = lastPathComponent.getParent();
    if (parent == null)
        return itemText;
    ObservableList<?> children = parent.getChildren();
    for (int i = 0; i < children.indexOf(lastPathComponent); i++) {
        TreeItem<?> child = (TreeItem<?>) children.get(i);
        String current = child.getValue().toString();
        if (current.equals(original)) {
            itemText = String.format("%s(%d)", original, ++suffixIndex);
        }
    }
    return itemText;
}
 
Example 9
Source File: TabDockingContainer.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    ObservableList<Tab> tabs = getTabs();
    Tab found = null;
    for (Tab tab : tabs) {
        if (tab.getContent() == base) {
            found = tab;
            break;
        }
    }
    if (found != null) {
        int index = tabs.indexOf(found);
        tabs.remove(index);
        found.setContent(indc.get());
        tabs.add(index, found);
    }
}
 
Example 10
Source File: TestCollectionController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteTestCase(LiveTestCase tc) {
    ObservableList<LiveTestCase> items = testsListView.getItems();
    int idx = items.indexOf(tc);

    if (idx >= 0) {
        items.remove(idx);
        if (!tc.isFrozen()) {
            unloadTestCase();

            if (!items.isEmpty()) {
                if (idx == 0) {
                    loadTestCase(0);
                } else {
                    loadTestCase(idx - 1);
                }
            }
        }
    }
}
 
Example 11
Source File: ListPickerDialog.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Create list picker dialog
 *  @param choices Options to show
 *  @param initial Initial selection (null will select first item)
 */
public ListPickerDialog(final Collection<String> choices, final String initial)
{
    final ObservableList<String> items = FXCollections.observableArrayList(choices);
    list = new ListView<>(items);

    int sel = initial != null ? items.indexOf(initial) : -1;
    list.selectionModelProperty().get().clearAndSelect(sel > 0 ? sel : 0);

    // Size list to number of items
    // .. based on guess of about 30 pixels per item ..
    list.setPrefHeight(items.size() * 30.0);

    list.setOnMouseClicked(event ->
    {
        if (event.getClickCount() >= 2)
        {
            setResult(list.getSelectionModel().getSelectedItem());
            close();
        }
    });

    getDialogPane().setContent(new BorderPane(list));
    getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    setResizable(true);

    setResultConverter(button ->
    {
        return button == ButtonType.OK ? list.getSelectionModel().getSelectedItem() : null;
    });
}
 
Example 12
Source File: VBoxDockingContainer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    ObservableList<Node> children = getChildren();
    int baseIndex = children.indexOf(base);
    children.remove(base);
    children.add(baseIndex, indc.get());
}
 
Example 13
Source File: FlowGridPane.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void relayout() {
    ObservableList<Node> children = getChildren();
    int    lastColSpan = 0;
    int    lastRowSpan = 0;
    for (Node child : children ) {
        int offs = children.indexOf(child);
        GridPane.setConstraints(child, offsetToCol(offs + lastColSpan), offsetToRow(offs + lastRowSpan));
        //lastColSpan = GridPane.getColumnSpan(child) == null ? 0 : GridPane.getColumnSpan(child);
        //lastRowSpan = GridPane.getRowSpan(child) == null ? 0 : GridPane.getRowSpan(child);
    }
}
 
Example 14
Source File: FxSchema.java    From FxDock with Apache License 2.0 5 votes vote down vote up
private static void storeTableView(String prefix, TableView t)
{
	ObservableList<TableColumn<?,?>> cs = t.getColumns();
	int sz = cs.size();
	ObservableList<TableColumn<?,?>> sorted = t.getSortOrder();
	
	// columns: count,[id,width,sortOrder(0 for none, negative for descending, positive for ascending)
	SStream s = new SStream();
	s.add(sz);
	for(int i=0; i<sz; i++)
	{
		TableColumn<?,?> c = cs.get(i);
		
		int sortOrder = sorted.indexOf(c);
		if(sortOrder < 0)
		{
			sortOrder = 0;
		}
		else
		{
			sortOrder++;
			if(c.getSortType() == TableColumn.SortType.DESCENDING)
			{
				sortOrder = -sortOrder;
			}
		}
		
		s.add(c.getId());
		s.add(c.getWidth());
		s.add(sortOrder);
	}
	// FIX separate columns and width/sort
	GlobalSettings.setStream(prefix + SFX_COLUMNS, s);
	
	// selection
	int ix = t.getSelectionModel().getSelectedIndex();
	GlobalSettings.setInt(prefix + SFX_SELECTION, ix);
}
 
Example 15
Source File: ScheduleList.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Refresh the display of the items in the schedule list.
 *
 * @param song the song of which the display should be refreshed in the
 *             listview.
 */
public void refreshSong(SongDisplayable song) {
    ObservableList<Displayable> itemp = listView.itemsProperty().get();
    int selectedIndex = listView.selectionModelProperty().get().getSelectedIndex();
    int index = itemp.indexOf(song);
    if (index != -1) {
        itemp.set(index, new SongDisplayable("", ""));
        itemp.set(index, song);
    }
    listView.getSelectionModel().clearSelection();
    listView.selectionModelProperty().get().select(selectedIndex);
}
 
Example 16
Source File: JFXUtil.java    From jfxutils with Apache License 2.0 5 votes vote down vote up
/**
 * Make a best attempt to replace the original component with the replacement, and keep the same
 * position and layout constraints in the container.
 * <p>
 * Currently this method is probably not perfect. It uses three strategies:
 * <ol>
 *   <li>If the original has any properties, move all of them to the replacement</li>
 *   <li>If the parent of the original is a {@link BorderPane}, preserve the position</li>
 *   <li>Preserve the order of the children in the parent's list</li>
 * </ol>
 * <p>
 * This method does not transfer any handlers (mouse handlers for example).
 *
 * @param original    non-null Node whose parent is a {@link Pane}.
 * @param replacement non-null Replacement Node
 */
public static void replaceComponent( Node original, Node replacement ) {
	Pane parent = (Pane) original.getParent();
	//transfer any properties (usually constraints)
	replacement.getProperties().putAll( original.getProperties() );
	original.getProperties().clear();

	ObservableList<Node> children = parent.getChildren();
	int originalIndex = children.indexOf( original );
	if ( parent instanceof BorderPane ) {
		BorderPane borderPane = (BorderPane) parent;
		if ( borderPane.getTop() == original ) {
			children.remove( original );
			borderPane.setTop( replacement );

		} else if ( borderPane.getLeft() == original ) {
			children.remove( original );
			borderPane.setLeft( replacement );

		} else if ( borderPane.getCenter() == original ) {
			children.remove( original );
			borderPane.setCenter( replacement );

		} else if ( borderPane.getRight() == original ) {
			children.remove( original );
			borderPane.setRight( replacement );

		} else if ( borderPane.getBottom() == original ) {
			children.remove( original );
			borderPane.setBottom( replacement );
		}
	} else {
		//Hope that preserving the properties and position in the list is sufficient
		children.set( originalIndex, replacement );
	}
}
 
Example 17
Source File: FlowGridPane.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void relayout() {
    ObservableList<Node> children = getChildren();
    int    lastColSpan = 0;
    int    lastRowSpan = 0;
    for (Node child : children ) {
        int offs = children.indexOf(child);
        GridPane.setConstraints(child, offsetToCol(offs + lastColSpan), offsetToRow(offs + lastRowSpan));
        //lastColSpan = GridPane.getColumnSpan(child) == null ? 0 : GridPane.getColumnSpan(child);
        //lastRowSpan = GridPane.getRowSpan(child) == null ? 0 : GridPane.getRowSpan(child);
    }
}
 
Example 18
Source File: RecordingListController.java    From archivo with GNU General Public License v3.0 4 votes vote down vote up
private int findItemIndex(TreeItem<Recording> item) {
    ObservableList<TreeItem<Recording>> siblings = item.getParent().getChildren();
    return siblings.indexOf(item);
}
 
Example 19
Source File: VBoxDockingContainer.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void replaceBaseWith(Dockable base, INewDockingContainer dc) {
    ObservableList<Node> children = getChildren();
    int baseIndex = children.indexOf(base.getComponent());
    children.remove(base.getComponent());
    children.add(baseIndex, dc.get());
}
 
Example 20
Source File: SplitDockingContainer.java    From marathonv5 with Apache License 2.0 2 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    double[] dividerPositions = getDividerPositions();
    ObservableList<Node> items = getItems();
    int indexOf = items.indexOf(base);
    items.remove(indexOf);
    items.add(indexOf, indc.get());
    setDividerPositions(dividerPositions);
}