@FXML void loadSelectedPlaylist() { Playlist p = (Playlist) playlistsView.getSelectionModel().getSelectedItem(); if (p == null) return; tracksView.setPlaceholder(offlinePlaceHolder); Platform.runLater( () -> { List<Track> tracks = p.getTracks(); tracksView.getItems().clear(); for (int i = tracks.size() - 1; i >= 0; i--) { tracksView.getItems().add(tracks.get(i)); } if (findTrack) { Platform.runLater( () -> { tracksView.getSelectionModel().select(currentTrack); tracksView.scrollTo(currentTrack); tracksView.requestFocus(); findTrack = false; }); } else { if (tracksView.getItems().size() > 0) { tracksView.scrollTo(0); } } }); }
private void deleteSelectedSkillFilter() { SkillFilter selectedItem = skillFiltersTableView.getSelectionModel().getSelectedItem(); if (selectedItem != null) { skillFiltersTableView.getItems().remove(selectedItem); skillFiltersTableView.getSelectionModel().clearSelection(); updateOfficialFiltersResult(); } }
void playRandom() { List<Track> tracks = tracksView.getItems(); Random random = new Random(); int size = tracks.size(); int r = random.nextInt(size - 1); tracksView.getSelectionModel().select(r); tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex()); Track nextTrack = (Track) tracksView.getSelectionModel().getSelectedItem(); playTrack(nextTrack); }
public void setFddObjectModel(FddObjectModel fddObjectModel) { logger.entry(); if (fddObjectModel != null) { fddObjectModel .getInteractionClasses() .values() .stream() .forEach( (value) -> { interactions.add(new InteractionState(value)); }); InteractionTableView.setItems(interactions); interactions.forEach( (interaction) -> { interaction .onProperty() .addListener( (observable, oldValue, newValue) -> { if (!newValue) { cb.setSelected(false); } else if (interactions.stream().allMatch(a -> a.isOn())) { cb.setSelected(true); } }); }); InteractionTableColumn.setCellValueFactory(new PropertyValueFactory<>("interactionName")); CheckTableColumn.setCellValueFactory( new Callback< TableColumn.CellDataFeatures<InteractionState, Boolean>, ObservableValue<Boolean>>() { @Override public ObservableValue<Boolean> call( TableColumn.CellDataFeatures<InteractionState, Boolean> param) { return param.getValue().onProperty(); } }); CheckTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(CheckTableColumn)); cb.setUserData(CheckTableColumn); cb.setOnAction( (ActionEvent event) -> { CheckBox cb1 = (CheckBox) event.getSource(); TableColumn tc = (TableColumn) cb1.getUserData(); InteractionTableView.getItems() .stream() .forEach( (item) -> { item.setOn(cb1.isSelected()); }); }); CheckTableColumn.setGraphic(cb); } logger.exit(); }
void playPrevious() { if (playStack.size() < 2) return; System.out.println("------------"); for (PlaylistAndTrack pnt : playStack) { System.out.println(pnt.track.getTitle()); } playStack.removeFirst(); PlaylistAndTrack prevPlaylistAndTrack = playStack.removeFirst(); playlistsView.getSelectionModel().select(prevPlaylistAndTrack.playlist); tracksView.getSelectionModel().select(prevPlaylistAndTrack.track); tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex()); playTrack(prevPlaylistAndTrack.track); }
private void hideTablesHeaders() { List<Pane> headers = Arrays.asList( (Pane) tracksView.lookup("TableHeaderRow"), (Pane) playlistsView.lookup("TableHeaderRow")); headers.forEach( header -> { header.setMaxHeight(0); header.setMinHeight(0); header.setPrefHeight(0); header.setVisible(false); }); }
// TODO try to use a binding private void updateSkills() { skillsTableView.getItems().clear(); Official selectedMember = officialsFilteredTableView.getSelectionModel().getSelectedItem(); if (selectedMember != null) { skillsTableView.getItems().addAll(selectedMember.getSkillLevels().values()); Collections.sort( skillsTableView.getItems(), new Comparator<SkillLevel>() { @Override public int compare(SkillLevel arg0, SkillLevel arg1) { return arg0.getSkill().getName().compareTo(arg1.getSkill().getName()); } }); } }
void addToPlaylist(List<File> files, Playlist p) { if (interfaceDisabled) return; new Thread( () -> { setInterfaceDisabled(true); int total = files.size(); AtomicInteger current = new AtomicInteger(0); Cache.pushToPlaylist( files, p, (Track t) -> { Platform.runLater( () -> { infoLabel.setText( String.format( res.getString("processed"), current.incrementAndGet(), total, t.getTitle())); if (p == getSelectedPlaylist()) { tracksView.getItems().remove(t); tracksView.getItems().add(0, t); } }); }); setInterfaceDisabled(false); }) .start(); if (p == getSelectedPlaylist()) { Platform.runLater( () -> { loadSelectedPlaylist(); }); } }
// Handler for MenuItem[fx:id="assignOfficialMenuItem"] onAction public void assignOfficial(ActionEvent event) { // TODO add assertions to be sure that no null value are passed to the // controller officialsController.assignOfficialTo( officialsFilteredTableView.getSelectionModel().getSelectedItem(), assigmentsListView.getSelectionModel().getSelectedItem()); }
/** * Sets up the remove button, which is used to remove filters from the table view and the graph. * * @param tableView The table view needed to get the currently selected filter. * @return The fully configured remove button. */ private Button setRemoveButton(TableView tableView) { final Button removeButton = new ImageButton("remove.png"); removeButton.setOnAction( actionEvent -> { final FilterInput filterInput = (FilterInput) tableView.getSelectionModel().getSelectedItem(); if (!data.isEmpty() && filterInput != null) { // Update model final IUserCommand updateGraphFilterCommand = interactionMap.get(FilterInteraction.REMOVE); if (updateGraphFilterCommand != null) { filterInput.setDeleted(); updateGraphFilterCommand.setSelection(filterInput); notifyListeners(updateGraphFilterCommand); logger.debug( "Removed FilterInput: " + filterInput.getName() + " from table view and database."); } else { logger.warn("no remove command mapped"); } } }); removeButton.setScaleX(0.5); removeButton.setScaleY(0.5); return removeButton; }
private void initializeFilteredPersonnelTableView() { personnelNameColumn.setCellValueFactory(new PropertyValueFactory<Official, String>("name")); personnelRankColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<Official, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<Official, String> arg0) { final Official official = arg0.getValue(); final StringExpression concat = Bindings.selectString(official.rankProperty(), "designation"); return concat; } }); Bindings.bindContent(officialsFilteredTableView.getItems(), officialFilteredList); gameData .getOfficials() .addListener( new ListChangeListener<Official>() { @Override public void onChanged(Change<? extends Official> arg0) { updateOfficialFiltersResult(); } }); // TODO initialize assignOfficialMenuItem to be sure that it's not // enable if not correct values are selected }
/** * Sets up the OverlayMenu with all buttons from the existing table view. * * @param tableView The table view to put on the overlay menu. * @return A {@link BorderPane} containing the full menu. */ private BorderPane setUpMenu(TableView<FilterInput> tableView) { final Button addButton = setAddButton(); final Button removeButton = setRemoveButton(tableView); final Button editButton = setEditButton(tableView); final Button selectionButton = setSelectionButton(); // Set up components on overlay final BorderPane borderPane = new BorderPane(); borderPane.setCenter(tableView); tableView.setMinHeight(300); AnchorPane anchorPane = new AnchorPane(); anchorPane.getChildren().addAll(addButton, removeButton, editButton, selectionButton); borderPane.setBottom(anchorPane); AnchorPane.setBottomAnchor(addButton, 0d); AnchorPane.setRightAnchor(addButton, 0d); AnchorPane.setBottomAnchor(removeButton, 0d); AnchorPane.setRightAnchor(removeButton, 30d); AnchorPane.setBottomAnchor(editButton, 0d); AnchorPane.setRightAnchor(editButton, 60d); AnchorPane.setBottomAnchor(selectionButton, 0d); AnchorPane.setRightAnchor(selectionButton, 95d); return borderPane; }
/** * Create the type column, which holds the type of the filter and also creates a callback to the * string property behind it. */ private void setUpTypeColumn(TableView<FilterInput> tableView) { // Set up type column final TableColumn<FilterInput, String> typeColumn = new TableColumn<>("Selection Model"); typeColumn.setMinWidth(90); typeColumn.setPrefWidth(90); tableView.getColumns().add(typeColumn); typeColumn.setCellValueFactory(p -> p.getValue().getSelectionModelProperty()); }
/** * Create the priority column, which holds the priority of a filter and also creates a callback to * the integer property behind it. */ private void setUpPriorityColumn(TableView<FilterInput> tableView) { // Set up priority column final TableColumn<FilterInput, Integer> priorityColumn = new TableColumn<>("Priority"); priorityColumn.setMinWidth(50); priorityColumn.setPrefWidth(50); tableView.getColumns().add(priorityColumn); priorityColumn.setCellValueFactory(p -> p.getValue().getPriorityProperty().asObject()); }
/** * Create the legalality column, which holds the legality of a filter and also creates a callback * to the string property behind it. */ private void setUpLegalityColumn(TableView<FilterInput> tableView) { // Set up priority column final TableColumn<FilterInput, Boolean> legalColumn = new TableColumn<>("Authorized"); legalColumn.setMinWidth(70); legalColumn.setPrefWidth(70); tableView.getColumns().add(legalColumn); legalColumn.setCellValueFactory(p -> p.getValue().getLegalProperty()); }
/** * Create the origin column, which holds the type of the origin and also creates a callback to the * string property behind it. */ private void setUpOriginColumn(TableView<FilterInput> tableView) { // Set up origin column final TableColumn<FilterInput, String> originColumn = new TableColumn<>("Filtered By"); originColumn.setMinWidth(90); originColumn.setPrefWidth(90); tableView.getColumns().add(originColumn); originColumn.setCellValueFactory(p -> p.getValue().getFilterTypeProperty()); }
/** * Create the filter column, which holds the name of the filter and also creates a callback to the * string property behind it. */ private void setUpFilterColumn(TableView<FilterInput> tableView) { // Set up filter column final TableColumn<FilterInput, String> filterColumn = new TableColumn<>("Filter"); filterColumn.setMinWidth(120); filterColumn.setPrefWidth(120); tableView.getColumns().add(filterColumn); filterColumn.setCellValueFactory(p -> p.getValue().getNameProperty()); }
private void setupTracksView() { TableColumn titleColumn = new TableColumn("Title"); titleColumn.setSortable(false); titleColumn.setMinWidth(USE_COMPUTED_SIZE); titleColumn.setCellValueFactory(new PropertyValueFactory<>("title")); TableColumn durationColumn = new TableColumn("Duration"); durationColumn.setMinWidth(60); durationColumn.setMaxWidth(60); durationColumn.setSortable(false); durationColumn.setCellValueFactory(new PropertyValueFactory<>("durationFormatted")); durationColumn.getStyleClass().add("text-layout-center"); tracksView.getColumns().clear(); tracksView.getColumns().addAll(titleColumn, durationColumn); tracksView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); }
void menuAddToPlaylist() { Track t = getSelectedTrack(); if (t == null) { return; } ChoiceDialog<Playlist> dialog = playlistSelectionDialog(playlistsView.getItems()); Optional<Playlist> result = dialog.showAndWait(); result.ifPresent(playlist -> addToPlaylist(t, playlist)); }
@FXML void search() { searching = true; new Thread( () -> { List<Track> tracks = Cache.search(searchText.getText()); tracksView.setPlaceholder(searchPlaceholder); Platform.runLater( () -> { if (tracksView.getItems().size() > 0) { tracksView.scrollTo(0); } tracksView.getItems().clear(); tracksView.getItems().addAll(tracks.toArray()); }); }) .start(); }
private void setInterfaceDisabled(boolean disabled) { playlistsView.setDisable(disabled); searchButton.setDisable(disabled); searchText.setDisable(disabled); addButton.setDisable(disabled); renameButton.setDisable(disabled); deleteButton.setDisable(disabled); refreshButton.setDisable(disabled); interfaceDisabled = disabled; }
private void setupPlaylistsView() { TableColumn titleColumn = new TableColumn("Title"); titleColumn.setMinWidth(USE_COMPUTED_SIZE); titleColumn.setSortable(false); titleColumn.setCellValueFactory(new PropertyValueFactory<>("title")); TableColumn countColumn = new TableColumn("Tracks"); countColumn.setMinWidth(60); countColumn.setMaxWidth(60); countColumn.setSortable(false); countColumn.setCellValueFactory(new PropertyValueFactory<>("count")); countColumn.getStyleClass().add("text-layout-right"); playlistsView.getColumns().clear(); playlistsView.getColumns().addAll(titleColumn, countColumn); playlistsView.setContextMenu(playlistsContextMenu); playlistsView.setPlaceholder(playlistPlaceholder); playlistsView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); }
void updatePlaylists() { if (interfaceDisabled) return; final ObservableList<Playlist> items = playlistsView.getItems(); items.clear(); items.addAll(Cache.playlists()); if (Settings.rememberedPlaylistId != null) for (Playlist p : items) { if (p.getId().equals(Settings.rememberedPlaylistId)) { rememberedPlaylist = p; break; } } }
/** * Create the active column, which holds the activity state and also creates a callback to the * string property behind it. */ private void setUpActiveColumn(TableView<FilterInput> tableView) { // Set up active column final TableColumn<FilterInput, Boolean> activeColumn = new TableColumn<>("Active"); activeColumn.setMinWidth(50); activeColumn.setPrefWidth(50); tableView.getColumns().add(activeColumn); activeColumn.setSortable(false); activeColumn.setCellFactory( CheckBoxTableCell.forTableColumn( (Callback<Integer, ObservableValue<Boolean>>) param -> { final FilterInput input = tableView.getItems().get(param); input .getActiveProperty() .addListener( l -> { notifyUpdateCommand(input); }); return input.getActiveProperty(); })); }
void createOfflinePlaylist() { if (interfaceDisabled) return; TextInputDialog dialog = new TextInputDialog(res.getString("new_offline_playlist")); dialog.setTitle(res.getString("create_new_offline_playlist")); dialog.setHeaderText(res.getString("create_new_playlist")); dialog.setContentText(res.getString("enter_playlist_name")); dialog.getDialogPane().getStylesheets().add("/styles/dialogs.css"); ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(logoImages); Optional<String> result = dialog.showAndWait(); result.ifPresent( title -> { Platform.runLater( () -> { Playlist newPlaylist = Cache.createPlaylist(title); Platform.runLater( () -> { playlistsView.getItems().add(newPlaylist); playlistsView.getSelectionModel().select(newPlaylist); }); }); }); }
/** * Set up the edit button. This button is used to edit existing filters. * * @param tableView The table view needed to get the currently selected filter. * @return The fully configured edit button. */ private Button setEditButton(TableView tableView) { final Button editButton = new ImageButton("edit.png"); editButton.setOnAction( actionEvent -> { final FilterInput filterInput = (FilterInput) tableView.getSelectionModel().getSelectedItem(); if (!data.isEmpty() && filterInput != null) { filterEditingMenu.showMenu(filterInput); } }); editButton.setScaleX(0.45); editButton.setScaleY(0.45); return editButton; }
public void addSkillFilter(ActionEvent event) { final Skill skill = skillFilterComboBox.getSelectionModel().getSelectedItem(); SkillFilter skillFilter = new SkillFilter(); skillFilter.setSkill(skill); String minValueText = skillFilterMinValueComponent.getText(); skillFilter.setMinValue( (minValueText == null || minValueText.isEmpty()) ? null : Integer.parseInt(minValueText)); String maxValueText = skillFilterMaxValueComponent.getText(); skillFilter.setMaxValue( (maxValueText == null || maxValueText.isEmpty()) ? null : Integer.parseInt(maxValueText)); skillFiltersTableView.getItems().add(skillFilter); // We don't need to update #skillFiltersMatcher because of the biding // betwen skillFiltersMatcher' matchers and the items of // skillFiltersTableView updateOfficialFiltersResult(); }
/** * Sets up the entire TableView with all its functionalities. * * @return The created TableView. */ private TableView<FilterInput> setUpTableView() { // Set up table view final TableView<FilterInput> tableView = new TableView<>(); tableView.setEditable(true); tableView.setMinWidth(522); tableView.setMinHeight(280); // Set up columns setUpFilterColumn(tableView); setUpTypeColumn(tableView); setUpOriginColumn(tableView); setUpColorColumn(tableView); setUpPriorityColumn(tableView); setUpLegalityColumn(tableView); setUpActiveColumn(tableView); // Insert data from database into table tableView.setItems(data); // Set select/deselect on mouse click tableView.setRowFactory( tableViewLambda -> { final TableRow<FilterInput> row = new TableRow<>(); row.addEventFilter( MouseEvent.MOUSE_PRESSED, event -> { final int index = row.getIndex(); if (index >= 0 && index < tableView.getItems().size() && tableView.getSelectionModel().isSelected(index)) { tableView.getSelectionModel().clearSelection(); event.consume(); } }); return row; }); return tableView; }
void playNext() { List<Track> tracks = tracksView.getItems(); int selected = tracksView.getSelectionModel().getSelectedIndex(); int next = selected + 1; if (next >= tracks.size()) { next = 0; } tracksView.getSelectionModel().select(next); tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex()); Track nextTrack = (Track) tracksView.getSelectionModel().getSelectedItem(); playTrack(nextTrack); }
void findPlayingTrack() { if (currentPlaylist == playlistsView.getSelectionModel().getSelectedItem()) { tracksView.getSelectionModel().select(currentTrack); tracksView.scrollTo(currentTrack); tracksView.requestFocus(); } else { findTrack = true; Platform.runLater( () -> { playlistsView.getSelectionModel().select(currentPlaylist); playlistsView.scrollTo(currentPlaylist); }); } }