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

The following examples show how to use javafx.collections.ObservableList#set() . 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: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
public void moveUp(ActionEvent event) {
    if (chaptersMode.get()) {
        ObservableList<TreeTablePosition<Organisable, ?>> selectedCells = bookStructure.getSelectionModel().getSelectedCells();
        if (selectedCells.size() == 1) {
            Organisable organisable = selectedCells.get(0).getTreeItem().getValue();
            organisable.moveUp();
            Platform.runLater(() -> updateBookStructure(ConverterApplication.getContext().getBook(), bookStructure.getRoot()));
        }
    } else {
        ObservableList<Integer> selectedIndices = fileList.getSelectionModel().getSelectedIndices();
        if (selectedIndices.size() == 1) {
            ObservableList<MediaInfo> items = fileList.getItems();
            int selected = selectedIndices.get(0);
            if (selected > 0) {
                MediaInfo upper = items.get(selected - 1);
                MediaInfo lower = items.get(selected);
                items.set(selected - 1, lower);
                items.set(selected, upper);
                fileList.getSelectionModel().clearAndSelect(selected - 1);
            }
        }
    }
}
 
Example 2
Source File: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
public void moveDown(ActionEvent event) {
    if (chaptersMode.get()) {
        ObservableList<TreeTablePosition<Organisable, ?>> selectedCells = bookStructure.getSelectionModel().getSelectedCells();
        if (selectedCells.size() == 1) {
            Organisable organisable = selectedCells.get(0).getTreeItem().getValue();
            organisable.moveDown();
            Platform.runLater(() -> updateBookStructure(ConverterApplication.getContext().getBook(), bookStructure.getRoot()));
        }
    } else {
        ObservableList<Integer> selectedIndices = fileList.getSelectionModel().getSelectedIndices();
        if (selectedIndices.size() == 1) {
            ObservableList<MediaInfo> items = fileList.getItems();
            int selected = selectedIndices.get(0);
            if (selected < items.size() - 1) {
                MediaInfo lower = items.get(selected + 1);
                MediaInfo upper = items.get(selected);
                items.set(selected, lower);
                items.set(selected + 1, upper);
                fileList.getSelectionModel().clearAndSelect(selected + 1);
            }
        }
    }
}
 
Example 3
Source File: MicroController.java    From CPUSim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * sorts the given list of Microinstructions in place by name
 * using Selection Sort.  It returns the modified ObservableList.
 *
 * @param micros a list of micro instructions to be sorted
 * @return a list of sorted micro instruction
 */
private ObservableList sortVectorByName(ObservableList micros)
{
    for (int i = 0; i < micros.size() - 1; i++) {
        //find the smallest from positions i to the end
        String nameOfSmallest =
                ((Microinstruction) micros.get(i)).getName();
        int indexOfSmallest = i;
        for (int j = i + 1; j < micros.size(); j++) {
            Microinstruction next = (Microinstruction) micros.get(j);
            if (next.getName().compareTo(nameOfSmallest) < 0) {
                indexOfSmallest = j;
                nameOfSmallest = next.getName();
            }
        }
        //swap smallest into position i
        Object temp = micros.get(i);
        micros.set(i, micros.get(indexOfSmallest));
        micros.set(indexOfSmallest, temp);
    }
    return micros;
}
 
Example 4
Source File: ListMapTest.java    From ReactFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testChanges() {
    ObservableList<String> strings = FXCollections.observableArrayList("1", "22", "333");
    LiveList<Integer> lengths = LiveList.map(strings, String::length);

    List<Integer> removed = new ArrayList<>();
    List<Integer> added = new ArrayList<>();
    lengths.observeChanges(ch -> {
        for(ListModification<? extends Integer> mod: ch.getModifications()) {
            removed.addAll(mod.getRemoved());
            added.addAll(mod.getAddedSubList());
        }
    });

    strings.set(1, "4444");

    assertEquals(Arrays.asList(2), removed);
    assertEquals(Arrays.asList(4), added);
}
 
Example 5
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 6
Source File: TableHelper.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Move currently selected item in table up
 *  @param table {@link TableView}
 *  @param items List with items
 */
public static <ITEM> void move_item_up(final TableView<ITEM> table, final ObservableList<ITEM> items)
{
    final int sel = table.getSelectionModel().getSelectedIndex();
    if (sel >= 1)
    {
        ITEM prev = items.set(sel-1, items.get(sel));
        items.set(sel, prev);
    }
}
 
Example 7
Source File: TableHelper.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Move currently selected item in table down
 *  @param table {@link TableView}
 *  @param items List with items
 */
public static <ITEM> void move_item_down(final TableView<ITEM> table, final ObservableList<ITEM> items)
{
    final int sel = table.getSelectionModel().getSelectedIndex();
    if (sel >= 0  &&  (sel+1) < items.size())
    {
        ITEM next = items.set(sel+1, items.get(sel));
        items.set(sel, next);
    }
}
 
Example 8
Source File: IndexController.java    From WIFIProbe with Apache License 2.0 5 votes vote down vote up
private void initProcessTable() {
    ObservableList<TableColumn<Process, ?>> processCols = processTable.getColumns();
    processCols.get(0).setCellValueFactory(new PropertyValueFactory<>("status"));
    TableColumn<Process,Double> processCol = new TableColumn<>("进度");
    processCol.setPrefWidth(475);
    processCol.setCellValueFactory(new PropertyValueFactory<>("progress"));
    processCol.setCellFactory(ProgressBarTableCell.forTableColumn());
    processCols.set(1,processCol);
    processCols.get(2).setCellValueFactory(new PropertyValueFactory<>("percent"));
    processCols.get(3).setCellValueFactory(new PropertyValueFactory<>("lastUpdate"));
}
 
Example 9
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 10
Source File: ResourceView.java    From sis with Apache License 2.0 5 votes vote down vote up
private void setContent(final Node content) {
    final ObservableList<Node> items = pane.getItems();
    if (items.size() >= 2) {
        items.set(1, content);
    } else {
        items.add(content);
    }
}
 
Example 11
Source File: ListRecursionTest.java    From ReactFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Tests that list changes are accumulated on recursion.
 */
@Test
public void testChangeAccumulation() {
    ObservableList<String> strings = new LiveArrayList<>("1", "22", "333");
    LiveList<Integer> lengths = LiveList.map(strings, String::length);

    IntegerProperty firstListener = new SimpleIntegerProperty(0);

    List<Integer> first1Removed = new ArrayList<>();
    List<Integer> first1Added = new ArrayList<>();
    List<Integer> first2Removed = new ArrayList<>();
    List<Integer> first2Added = new ArrayList<>();
    List<Integer> secondRemoved = new ArrayList<>();
    List<Integer> secondAdded = new ArrayList<>();

    IntFunction<ListChangeListener<Integer>> listenerFactory = id -> ch -> {
        while(ch.next()) {
            if(firstListener.get() == 0) {
                firstListener.set(id);
                first1Removed.addAll(ch.getRemoved());
                first1Added.addAll(ch.getAddedSubList());
                strings.add(2, "55555");
            } else if(firstListener.get() == id) {
                first2Removed.addAll(ch.getRemoved());
                first2Added.addAll(ch.getAddedSubList());
            } else {
                secondRemoved.addAll(ch.getRemoved());
                secondAdded.addAll(ch.getAddedSubList());
            }
        }
    };

    lengths.addListener(listenerFactory.apply(1));
    lengths.addListener(listenerFactory.apply(2));

    strings.set(1, "4444");

    assertEquals(Arrays.asList(2), first1Removed);
    assertEquals(Arrays.asList(4), first1Added);
    assertEquals(Arrays.asList(), first2Removed);
    assertEquals(Arrays.asList(5), first2Added);
    assertEquals(Arrays.asList(2), secondRemoved);
    assertEquals(Arrays.asList(4, 5), secondAdded);
}