Java 类javafx.scene.control.ListCell 实例源码

项目:phone-simulator    文件:HostController.java   
/**
 * Initializes the controller class.
 *
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    UssdClient.impl.showData(cboChanel, cboRole, txtLocalHost, txtLocalPort, txtRemoteHost, txtRemotePort, txtPhone);
    cboChanel.setCellFactory((ListView<EnumeratedBase> param) -> new ListCell<EnumeratedBase>() {
        @Override
        protected void updateItem(EnumeratedBase item, boolean empty) {
            super.updateItem(item, empty);
            if (item == null || empty) {
                setText(null);
            } else {
                setText(item.toString());
            }
        }

    });
}
项目:Matcher    文件:ListCellFactory.java   
@Override
public ListCell<T> call(ListView<T> list) {
    return new ListCell<T>() {
        @Override
        protected void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);

            if (empty || item == null) {
                setText(null);
                setStyle("");
            } else {
                setText(ListCellFactory.this.getText(item));
                setStyle(ListCellFactory.this.getStyle(item));
            }
        }
    };
}
项目:marathonv5    文件:ListViewCellFactorySample.java   
public ListViewCellFactorySample() {
    final ListView<Number> listView = new ListView<Number>();
    listView.setItems(FXCollections.<Number>observableArrayList(
            100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00,
            430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00,
            15.00, 47.50, 12.11

    ));

    listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() {
        @Override public ListCell<Number> call(ListView<java.lang.Number> list) {
            return new MoneyFormatCell();
        }
    });        

    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    getChildren().add(listView);
}
项目:marathonv5    文件:MarathonFileChooser.java   
private void initListView() {
    if (!doesAllowChildren) {
        fillUpChildren(fileChooserInfo.getRoot());
    }
    childrenListView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
        @Override public ListCell<File> call(ListView<File> param) {
            return new ChildrenFileCell();
        }
    });
    childrenListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (fileChooserInfo.isFileCreation()) {
            return;
        }
        File selectedItem = childrenListView.getSelectionModel().getSelectedItem();
        if (selectedItem == null) {
            fileNameBox.clear();
        }
    });
}
项目:marathonv5    文件:RunHistoryStage.java   
private void initComponents() {
    VBox.setVgrow(historyView, Priority.ALWAYS);
    historyView.setItems(FXCollections.observableArrayList(runHistoryInfo.getTests()));
    historyView.setCellFactory(new Callback<ListView<JSONObject>, ListCell<JSONObject>>() {
        @Override public ListCell<JSONObject> call(ListView<JSONObject> param) {
            return new HistoryStateCell();
        }
    });

    VBox historyBox = new VBox(5);
    HBox.setHgrow(historyBox, Priority.ALWAYS);

    countField.setText(getRemeberedCount());
    if (countNeeded) {
        form.addFormField("Max count of remembered runs: ", countField);
    }
    historyBox.getChildren().addAll(new Label("Select test", FXUIUtils.getIcon("params")), historyView, form);

    verticalButtonBar.setId("vertical-buttonbar");
    historyPane.setId("history-pane");
    historyPane.getChildren().addAll(historyBox, verticalButtonBar);

    doneButton.setOnAction((e) -> onOK());
    buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE);
    buttonBar.getButtons().addAll(doneButton);
}
项目:marathonv5    文件:CompositeLayout.java   
private void initComponents() {
    optionBox.setItems(model);
    optionBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
        if (newValue != null) {
            updateTabPane();
        }
    });
    optionBox.setCellFactory(new Callback<ListView<PlugInModelInfo>, ListCell<PlugInModelInfo>>() {
        @Override public ListCell<PlugInModelInfo> call(ListView<PlugInModelInfo> param) {
            return new LauncherCell();
        }
    });
    optionTabpane.setId("CompositeTabPane");
    optionTabpane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
    optionTabpane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);
    VBox.setVgrow(optionTabpane, Priority.ALWAYS);
}
项目:marathonv5    文件:JavaFXElementPropertyAccessor.java   
protected int getIndexAt(ListView<?> listView, Point2D point) {
    if (point == null) {
        return listView.getSelectionModel().getSelectedIndex();
    }
    point = listView.localToScene(point);
    Set<Node> lookupAll = getListCells(listView);
    ListCell<?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (ListCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
项目:marathonv5    文件:ListViewCellFactorySample.java   
public ListViewCellFactorySample() {
    final ListView<Number> listView = new ListView<Number>();
    listView.setItems(FXCollections.<Number>observableArrayList(
            100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00,
            430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00,
            15.00, 47.50, 12.11

    ));

    listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() {
        @Override public ListCell<Number> call(ListView<java.lang.Number> list) {
            return new MoneyFormatCell();
        }
    });        

    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    getChildren().add(listView);
}
项目:marathonv5    文件:SimpleListViewScrollSample.java   
@Override public void start(Stage primaryStage) throws Exception {
    final ListView<String> listView = new ListView<String>();
    listView.setItems(FXCollections.observableArrayList("Row 1", "Row 2", "Long Row 3", "Row 4", "Row 5", "Row 6", "Row 7",
            "Row 8", "Row 9", "Row 10", "Row 11", "Row 12", "Row 13", "Row 14", "Row 15", "Row 16", "Row 17", "Row 18",
            "Row 19", "Row 20", "Row 21", "Row 22", "Row 23", "Row 24", "Row 25"));
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    Button button = new Button("Debug");
    button.setOnAction((e) -> {
        ObservableList<Integer> selectedIndices = listView.getSelectionModel().getSelectedIndices();
        for (Integer index : selectedIndices) {
            ListCell cellAt = getCellAt(listView, index);
            System.out.println("SimpleListViewScrollSample.SimpleListViewScrollSampleApp.start(" + cellAt + ")");
        }
    });
    VBox root = new VBox(listView, button);
    primaryStage.setScene(new Scene(root, 300, 400));
    primaryStage.show();
}
项目:javafx-qiniu-tinypng-client    文件:SiderBarView.java   
void initView() {
    listview.setCellFactory(param -> new ListCell<String>() {
        @Override
        protected void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
            if (!empty) {
                BucketItemView view = new BucketItemView();
                view.setBucketName(item);
                setGraphic(view);
            } else {
                setGraphic(null);
            }
        }
    });
    listview.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isNotEmpty(newValue)) {
            if (this.itemSelectListener != null) {
                this.itemSelectListener.onItemSelected(newValue);
            }
        }
    });
}
项目:Dr-Assistant    文件:PatientHistoryController.java   
private void loadPatientHistory() {
    prescriptions = prescriptionGetway.patientPrescriptions(patient);
    prescriptionList.getItems().addAll(prescriptions);
    prescriptionList.getSelectionModel().select(0);

    prescriptionList.setCellFactory(param -> new ListCell<Prescription>() {
        @Override
        protected void updateItem(Prescription item, boolean empty) {
            super.updateItem(item, empty);
            if (empty || item == null || item.getDate() == null) {
                setText(null);
            } else {
                setText(item.getDate());
            }
        }
    });

    showPrescription();
}
项目:ABC-List    文件:ExercisePresenter.java   
private void initializeComboBoxTimeChooser() {
    LoggerFacade.getDefault().info(this.getClass(), "Initialize [ComboBox] [TimeChooser]"); // NOI18N

    cbTimeChooser.setCellFactory((ListView<ETime> listview) -> new ListCell<ETime>() {
        @Override
        public void updateItem(ETime time, boolean empty) {
            super.updateItem(time, empty);
            this.setGraphic(null);
            this.setText(!empty ? time.toString() : null);
        }
    });

    final ObservableList<ETime> observableListTimes = FXCollections.observableArrayList();
    observableListTimes.addAll(ETime.values());
    cbTimeChooser.getItems().addAll(observableListTimes);
    cbTimeChooser.getSelectionModel().selectFirst();
}
项目:voogasalad-ltub    文件:PathSetter.java   
public PathSetter(ObservableList<Path> paths, String variableName){
    super(Path.class,variableName);
    this.myPaths=paths;     

    pathChoices= new ComboBox<>(myPaths);

    pathChoices.setCellFactory(new Callback<ListView<Path>, ListCell<Path>>(){
        @Override
        public ListCell<Path> call(ListView<Path> list){
            return new PathCell();
        }
    });
    pathChoices.setButtonCell(new PathButtonCell());

    this.getChildren().add(pathChoices);

}
项目:voogasalad-ltub    文件:ComponentSelectorPane.java   
public ComponentSelectorPane(String listTitle, ObservableList<Class<? extends Component>> displayedData, SpriteDataPane infoPane) {
    this.infoPane=infoPane;
    this.setPrefWidth(PREF_WIDTH);
    ListView<Class<? extends Component>> componentDisplay = new ListView<>();
    componentDisplay.setItems(displayedData);

    componentDisplay.setCellFactory(
            new Callback<ListView<Class<? extends Component>>, ListCell<Class<? extends Component>>>() {
                @Override
                public ListCell<Class<? extends Component>> call(ListView<Class<? extends Component>> list) {
                    return new ComponentCustomizerOption();
                }
            });

    Label title = new Label(listTitle);
    this.getChildren().addAll(title, componentDisplay);
}
项目:Java-9-Programming-Blueprints    文件:CloudNoticeManagerController.java   
@Override
public void initialize(URL url, ResourceBundle rb) {
    recips.setAll(dao.getRecipients());
    topics.setAll(sns.getTopics());

    type.setItems(types);
    recipList.setItems(recips);
    topicCombo.setItems(topics);

    recipList.setCellFactory(p -> new ListCell<Recipient>() {
        @Override
        public void updateItem(Recipient recip, boolean empty) {
            super.updateItem(recip, empty);
            if (!empty) {
                setText(String.format("%s - %s", recip.getType(), recip.getAddress()));
            } else {
                setText(null);
            }
        }
    });
    recipList.getSelectionModel().selectedItemProperty().addListener((obs, oldRecipient, newRecipient) -> {
        type.valueProperty().setValue(newRecipient != null ? newRecipient.getType() : "");
        address.setText(newRecipient != null ? newRecipient.getAddress() : "");
    });
}
项目:Incubator    文件:DailySectionChooserDialogPresenter.java   
private void initializeCombBox() {
    LoggerFacade.INSTANCE.info(this.getClass(), "Initialize ComboBox"); // NOI18N

    // Define rendering of the list of values in ComboBox drop down. 
    lvDailySections.setCellFactory(listView -> new ListCell<DailySectionModel>() {
        @Override
        public void updateItem(DailySectionModel item, boolean empty) {
            super.updateItem(item, empty);

            if (
                    item == null
                    || empty
            ) {
                super.setText(null);
            } else {
                super.setText(item.getDailyDate());
            }
        }
    });
}
项目:Incubator    文件:DebugComponentsPresenter.java   
private void initializeSimulateGameLevel() {
    DebugConsole.getDefault().info(this.getClass(), "Initialize simulate GameLevel"); // NOI18N

    cbSimulateGameLevel.getItems().addAll(EGameLevel.values());
    cbSimulateGameLevel.setCellFactory(new Callback<ListView<EGameLevel>, ListCell<EGameLevel>>() {
        @Override
        public ListCell<EGameLevel> call(ListView<EGameLevel> listView) {
            return new ListCell<EGameLevel>() {
                @Override
                protected void updateItem(EGameLevel item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item == null || empty) {
                        setText(null);
                    } else {
                        setText(item.toString());
                    }
                }
            };
        }
    });
    cbSimulateGameLevel.getSelectionModel().selectFirst();
}
项目:Incubator    文件:DebugComponentsPresenter.java   
private void initializeSimulateGameMode() {
    DebugConsole.getDefault().info(this.getClass(), "Initialize simulate GameMode"); // NOI18N

    cbSimulateGameMode.getItems().addAll(EGameMode.values());
    cbSimulateGameMode.setCellFactory(new Callback<ListView<EGameMode>, ListCell<EGameMode>>() {
        @Override
        public ListCell<EGameMode> call(ListView<EGameMode> listView) {
            return new ListCell<EGameMode>() {
                @Override
                protected void updateItem(EGameMode item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item == null || empty) {
                        setText(null);
                    } else {
                        setText(item.toString());
                    }
                }
            };
        }
    });
    cbSimulateGameMode.getSelectionModel().selectFirst();
}
项目:Gargoyle    文件:ListViewFileCellFactory.java   
@Override
public ListCell<File> call(ListView<File> param) {
    return new ListCell<File>() {

        @Override
        protected void updateItem(File item, boolean empty) {
            super.updateItem(item, empty);

            if (!empty) {
                setText(String.format("%s       ( %,d KB )", item.getName(), (item.length() / 1024)));
            } else {
                setText("");
            }
        }

    };
}
项目:chvote-1-0    文件:KeyTestingController.java   
private void customizeCipherTextCellFactory() {
    cipherTextList.setCellFactory(new Callback<ListView<AuthenticatedBallot>, ListCell<AuthenticatedBallot>>() {
        @Override
        public ListCell<AuthenticatedBallot> call(ListView<AuthenticatedBallot> param) {
            return new ListCell<AuthenticatedBallot>() {
                @Override
                protected void updateItem(AuthenticatedBallot item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(DatatypeConverter.printHexBinary(item.getAuthenticatedEncryptedBallot()));
                    }
                }
            };
        }
    });
}
项目:openjfx-8u-dev-tests    文件:HListViewAddRemoveTest.java   
protected void extraTestingForLongItem() {
    list.as(Selectable.class).selector().select("string");
    //check that right side of the long item is within the listview
    final Wrap<? extends ListCell> longCell = list.as(Parent.class, Node.class).
            lookup(ListCell.class, new LookupCriteria<ListCell>() {

        public boolean check(ListCell cntrl) {
            return cntrl.getItem() != null &&
                    cntrl.getItem().toString().contains(ListViewApp.createLongItem(0));
        }
    }).wrap();
    longCell.waitState(new State() {

        public Object reached() {
            Rectangle bounds = longCell.getScreenBounds();
            Rectangle listBounds = list.getScreenBounds();
            return ((bounds.x + bounds.width) >= listBounds.x) &&
                    ((bounds.x + bounds.width) <= (listBounds.x+ listBounds.width)) ?
                        true : null;
        }
    });
}
项目:reduxfx    文件:ListViewCellFactoryAccessor.java   
@SuppressWarnings("unchecked")
@Override
protected void updateItem(Object data, boolean empty) {
    super.updateItem(data, empty);

    if (empty || data == null) {
        setText(null);
        setGraphic(null);
    } else {
        final Object item = mapping.apply(data);
        if (item instanceof VNode) {
            final VNode newVNode = VScenegraphFactory.customNode(ListCell.class).child("graphic", (VNode) item);
            final Option<VNode> oldVNode = Option.of(getGraphic()).flatMap(node -> Option.of((VNode) node.getUserData()));
            final Map<Phase, Vector<Patch>> patches = Differ.diff(oldVNode, Option.of(newVNode));
            Patcher.patch(dispatcher, this, oldVNode, patches);
            Option.of(getGraphic()).forEach(node -> node.setUserData(newVNode));
        } else {
            this.setText(String.valueOf(item));
            this.setGraphic(null);
        }
    }
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldOpenContextMenuOnReservedPlaylist() {
    ListView<Playlist> listView = getListView();
    ListCell<Playlist> listCell = cellFactory.call(listView);

    listCell.updateListView(listView);
    listCell.updateIndex(0);

    listCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(listCell));

    MenuItem newPlaylistItem = listCell.getContextMenu().getItems().get(0);
    MenuItem deletePlaylistItem = listCell.getContextMenu().getItems().get(1);

    assertThat("New playlist item should be disabled", newPlaylistItem.isDisable(), equalTo(true));
    assertThat("Delete playlist item should be disabled", deletePlaylistItem.isDisable(), equalTo(true));
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldOpenContextMenuOnUserPlaylist() {
    ListView<Playlist> listView = getListView();
    ListCell<Playlist> listCell = cellFactory.call(listView);

    listCell.updateListView(listView);
    listCell.updateIndex(2);

    listCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(listCell));

    MenuItem newPlaylistItem = listCell.getContextMenu().getItems().get(0);
    MenuItem deletePlaylistItem = listCell.getContextMenu().getItems().get(1);

    assertThat("New playlist item should be disabled", newPlaylistItem.isDisable(), equalTo(true));
    assertThat("Delete playlist item should not be disabled", deletePlaylistItem.isDisable(), equalTo(false));
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldOpenContextMenuBelowPlaylists() {
    ListView<Playlist> listView = getListView();
    ListCell<Playlist> listCell = cellFactory.call(listView);

    listCell.updateListView(listView);
    listCell.updateIndex(10);

    listCell.onContextMenuRequestedProperty().get().handle(getContextMenuEvent(listCell));

    MenuItem newPlaylistItem = listCell.getContextMenu().getItems().get(0);
    MenuItem deletePlaylistItem = listCell.getContextMenu().getItems().get(1);

    assertThat("New playlist item should not be disabled", newPlaylistItem.isDisable(), equalTo(false));
    assertThat("Delete playlist item should be disabled", deletePlaylistItem.isDisable(), equalTo(true));
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragEntered() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should not be empty", listCell.getStyle(), not(isEmptyString()));
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnterdWithSameSource() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, listCell));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithNoContent() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithNoPlaylist() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(null);
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithReservedPlaylist() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(PLAYLIST_ID_FAVOURITES, "Favourites", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragExited() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setStyle("some-style");

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_EXITED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragExitedProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragDropped() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));

    Track mockTrack = mock(Track.class);
    when(mockTrack.clone()).thenReturn(mockTrack);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);
    when(mockDragboard.getContent(DND_TRACK_DATA_FORMAT)).thenReturn(mockTrack);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, times(1)).addTrackToPlaylist(1, mockTrack);
    verify(spyDragEvent, times(1)).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragDroppedWithNoContent() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, never()).addTrackToPlaylist(anyInt(), any());
    verify(spyDragEvent, never()).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:LuoYing    文件:SceneEntitiesConverter.java   
@Override
public ListCell<EntityData> call(ListView<EntityData> param) {
    ListCell<EntityData> lc = new ListCell<EntityData>() {
        @Override
        protected void updateItem(EntityData item, boolean empty) {
            super.updateItem(item, empty);
            setText(null);
            setGraphic(null);
            if (!empty && item != null) {
                setGraphic(new ListCellRow(item));
            }

        }
    };
    return lc;
}
项目:LuoYing    文件:ListViewPopup.java   
public ListViewPopup(List<T> items) {
    if (items != null) {
        setItems(items);
    }

    popup.getContent().add(searchListView);
    popup.setAutoHide(true);

    searchListView.getListView().setCellFactory((ListView<T> param) -> new ListCell<T>() {
        @Override
        protected void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);
            setText(null);
            setGraphic(null);
            if (!empty && item != null) {
                setText(item.toString());
            }
        }
    });
    // 匹配检查的时候要用字符串转换器
    searchListView.setPrefWidth(250);
    searchListView.setPrefHeight(250);
    searchListView.setEffect(new DropShadow());
}
项目:LuoYing    文件:ComponentSearch.java   
public ComponentSearch(List<T> items) {
    if (items != null) {
        setComponents(items);
    }

    popup.getContent().add(componentView);
    popup.setAutoHide(true);

    componentView.getListView().setCellFactory((ListView<T> param) -> new ListCell<T>() {
        @Override
        protected void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                setText(item.getId());
            }
        }
    });
    // 匹配检查的时候要用字符串转换器
    componentView.setConverter((T t) -> t.getId());
    componentView.setPrefWidth(250);
    componentView.setPrefHeight(250);
    componentView.setEffect(new DropShadow());
}
项目:LuoYing    文件:ComponentsForm.java   
public ComponentsForm() {

        setCellFactory((ListView<ComponentDefine> param) -> new ListCell<ComponentDefine>() {
            @Override
            protected void updateItem(ComponentDefine item, boolean empty) {
                super.updateItem(item, empty);
                String name = null;
                Node icon = null;
                if (item != null && !empty) {
                    name = item.getId();
                }
                setText(name);
                setGraphic(icon);
            }
        });

        setOnDragDetected(this::doDragDetected);
        setOnDragDone(this::doDragDone);

        updateAassetDir();

        // 切换资源目录的时候要重置组件面板
        Manager.getConfigManager().addListener(this);
    }
项目:LuoYing    文件:DataProcessorSearch.java   
public DataProcessorSearch(List<T> items) {
    if (items != null) {
        setItems(items);
    }

    popup.getContent().add(searchListView);
    popup.setAutoHide(true);

    searchListView.getListView().setCellFactory((ListView<T> param) -> new ListCell<T>() {
        @Override
        protected void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                setText(item.getData().getId());
            }
        }
    });
    // 匹配检查的时候要用字符串转换器
    searchListView.setConverter((T t) -> t.getData().getId());
    searchListView.setPrefWidth(250);
    searchListView.setPrefHeight(250);
    searchListView.setEffect(new DropShadow());
}
项目:osrs-private-server    文件:ItemListView.java   
private void setListViewDisplay() {
    this.setCellFactory(new Callback<ListView<Item>, ListCell<Item>>() {
        @Override
        public ListCell<Item> call(ListView<Item> p) {
            ListCell<Item> cell = new ListCell<Item>() {
                @Override
                protected void updateItem(Item item, boolean bln) {
                    super.updateItem(item, bln);

                    if (item != null)
                        setText(item.getId() + ": " + item.getName());
                    else
                        setText("");
                }
            };
            return cell;
        }
    });
}
项目:MatroskaBatch    文件:RemoteFileChooserController.java   
@Override
public void initialize(URL location, ResourceBundle resources) {
    mainList.getSelectionModel().setSelectionMode(multiselect ? SelectionMode.MULTIPLE : SelectionMode.SINGLE);
    mainList.setCellFactory(new Callback<ListView<RESTPath>, ListCell<RESTPath>>() {
        @Override
        public ListCell<RESTPath> call(ListView<RESTPath> param) {
            return new RESTPathListCell();
        }
    });
    Platform.runLater(() -> {
        try {
            currentPath = remoteUtils.getRemoteRoot();
            loadDirectory(currentPath);
        } catch (IOException e) {
            throw new RuntimeException("couldn't get root", e);
        }
    });
}