java类javafx.collections.ObservableListBase的实例源码

AppPresenter.java 文件源码 项目:musicdroid 阅读 17 收藏 0 点赞 0 评论 0
private ObservableListBase<AlbumDirectory> getAlbumObservableList(String searchSequence) {
    return new ObservableListBase<AlbumDirectory>() {

        private List<AlbumDirectory> list = getAlbumDirectories();

        private List<AlbumDirectory> getAlbumDirectories() {
            if (StringUtils.isNotBlank(searchSequence)) {
                return getFilteredAlbumList();
            } else {
                return albumList.stream().map(AlbumDirectory::new).collect(Collectors.toList());
            }
        }

        private List<AlbumDirectory> getFilteredAlbumList() {
            return albumList.stream()
                    .filter(file -> file.getAbsolutePath().toLowerCase().contains(searchSequence))
                    .map(AlbumDirectory::new)
                    .sorted(Comparator.comparing(o -> o.getFile().getAbsolutePath()))
                    .collect(Collectors.toList());
        }

        @Override
        public AlbumDirectory get(int index) {
            try {
                return list.get(index);
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        public int size() {
            return list.size();
        }
    };
}
AppPresenter.java 文件源码 项目:musicdroid 阅读 17 收藏 0 点赞 0 评论 0
@Override
public void initialize(URL location, ResourceBundle resources) {
    mediaConverterService = new MediaConverterService();
    mediaConverterService.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            conversionProcessLabel.setText(String.format("Processing \"%s\" ...", newValue.getName()));
        }
    });
    mediaConverterService.setOnSucceeded(event -> {
        conversionProcessLabel.setText("Conversion finished");
        exportButton.setDisable(false);
    });
    mediaConverterService.setOnFailed(event -> {
        conversionProcessLabel.setText("Conversion failed!");
        exportButton.setDisable(false);
        LOGGER.error(event.getSource().exceptionProperty().getValue().toString());
    });

    final List<JadbDevice> devices = getJadbDevices();
    LOGGER.info("Devices [{}]", devices);
    devicesComboBox.setItems(new ObservableListBase<JadbDevice>() {
        @Override
        public JadbDevice get(int index) {
            return devices.get(index);
        }

        @Override
        public int size() {
            return devices.size();
        }
    });
    devicesComboBox.setConverter(new StringConverter<JadbDevice>() {
        @Override
        public String toString(JadbDevice device) {
            return device.getSerial();
        }

        @Override
        public JadbDevice fromString(String string) {
            return null;
        }
    });
    if (!devicesComboBox.getItems().isEmpty()) {
        devicesComboBox.setValue(devices.get(0));
        exportButton.setDisable(false);
    }
    loadAlbumList();
}


问题


面经


文章

微信
公众号

扫码关注公众号