void deleteDeadFromOfflinePlaylist(Playlist p) { if (interfaceDisabled) return; infoLabel.setText(res.getString("deleting_dead_items")); log.info("Deleting dead items from " + p.getTitle()); Integer deleted = Cache.deleteDead(p); infoLabel.setText(String.format(res.getString("deleted_dead_items"), deleted)); log.info("Deleted dead items from " + p.getTitle() + ": " + deleted); Platform.runLater( () -> { loadSelectedPlaylist(); }); }
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(); }); } }
@FXML void refreshPlaylists() { infoLabel.setText(res.getString("refreshing")); log.info("Refreshing playlists"); 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; } } infoLabel.setText(res.getString("playlists_refreshed")); log.info("Playlists refreshed"); }
void updatePlayProgress() { if (player != null && Tray.stage.isShowing()) { Duration d = player.getMedia().getDuration(); Duration t = player.getCurrentTime(); loadProgressBar.setProgress(t.toMillis() / d.toMillis()); timeUpdate++; if (timeUpdate == 10) { timeUpdate = 0; Platform.runLater( () -> { timeLabel.setText(formatTime(d, t)); }); } } }
void setupPlaylistsContextMenu() { ContextMenu cm = playlistsContextMenu; MenuItem createOffline = menuItem( res.getString("create_offline_playlist"), () -> { createOfflinePlaylist(); }); MenuItem setAsFeatured = menuItem( res.getString("set_as_featured"), () -> { Playlist selectedPlaylist = (Playlist) playlistsView.getSelectionModel().getSelectedItem(); if (selectedPlaylist != null) { rememberedPlaylist = selectedPlaylist; Settings.rememberedPlaylistId = selectedPlaylist.getId(); infoLabel.setText( String.format(res.getString("featured_set"), selectedPlaylist.getTitle())); } }); MenuItem rename = menuItem( "(...) " + res.getString("rename_playlist"), () -> { renamePlaylist(); }); MenuItem delete = menuItem( "(-) " + res.getString("delete_playlist"), () -> { deletePlaylist(); }); cm.getItems() .addAll( createOffline, new SeparatorMenuItem(), setAsFeatured, new SeparatorMenuItem(), rename, delete); }
void setupShortcuts() { Platform.runLater( () -> { stateButton .getScene() .getAccelerators() .put( new KeyCodeCombination(KeyCode.F3), (Runnable) () -> { if (!interfaceDisabled) SwingAppenderUI.getInstance().show(); }); stateButton .getScene() .getAccelerators() .put( new KeyCodeCombination(KeyCode.F), (Runnable) () -> { if (!interfaceDisabled) findPlayingTrack(); }); stateButton .getScene() .getAccelerators() .put( new KeyCodeCombination(KeyCode.F5), (Runnable) () -> { if (!interfaceDisabled) Platform.runLater(() -> refreshPlaylists()); }); stateButton .getScene() .getAccelerators() .put( new KeyCodeCombination(KeyCode.F4), (Runnable) () -> { if (numpadOff) { setupGlobalKeys(); Platform.runLater( () -> { infoLabel.setText(res.getString("global_hotkeys_on")); log.info("Global hotkeys ON"); }); } else { hotkeysProvider.reset(); Platform.runLater( () -> { infoLabel.setText(res.getString("global_hotkeys_off")); log.info("Global hotkeys OFF"); }); } numpadOff = !numpadOff; }); tracksView.setOnKeyPressed( (evt) -> { if (interfaceDisabled) return; if (evt.getCode().equals(KeyCode.DELETE)) { deleteTrackFromPlaylist(); evt.consume(); } else if (evt.getCode().equals(KeyCode.ENTER)) { playSelectedTrack(); evt.consume(); } else if (evt.getCode().equals(KeyCode.F2)) { renameTrack(); evt.consume(); } }); playlistsView.setOnKeyPressed( (evt) -> { if (interfaceDisabled) return; if (evt.getCode().equals(KeyCode.F2)) { renamePlaylist(); evt.consume(); } }); }); setupGlobalKeys(); }
@Override public void initialize(URL location, ResourceBundle resources) { AppController.instance = this; this.res = resources; ObservableList<String> modeItems = FXCollections.observableArrayList( Settings.MODE_NEXT, Settings.MODE_RANDOM, Settings.MODE_SAME); modeList.setItems(modeItems); modeList.getSelectionModel().select(Settings.currentMode); modeList .valueProperty() .addListener( (ObservableValue ov, Object oldVal, Object newVal) -> { Settings.currentMode = (String) newVal; }); setupPlaylistsView(); setupPlaylistsContextMenu(); setupTracksView(); tracksView.setContextMenu(tracksContextMenu); tracksView.setOnContextMenuRequested( (ContextMenuEvent evt) -> { setupTracksContextMenu(); evt.consume(); }); tracksView .getSelectionModel() .selectedItemProperty() .addListener( (ObservableValue observable, Object oldValue, Object newValue) -> { Settings.lastTrackId = newValue != null ? ((Track) newValue).getId() : null; }); playlistsView .getSelectionModel() .selectedItemProperty() .addListener( (ObservableValue observable, Object oldValue, Object newValue) -> { loadSelectedPlaylist(); Settings.lastPlaylistId = newValue != null ? ((Playlist) newValue).getId() : null; searching = false; searchText.setText(StringUtils.EMPTY); }); volumeSlider.setCursor(Cursor.HAND); volumeSlider .valueProperty() .addListener( (ObservableValue<? extends Number> ov, Number oldVal, Number newVal) -> { if (player != null) { player.setVolume(newVal.doubleValue()); } Settings.currentVolume = newVal.doubleValue(); volumeLabel.setText( String.valueOf((int) Math.ceil(newVal.doubleValue() * 100)) + "%"); }); volumeSlider.setValue(Settings.currentVolume); imagePlay = new ImageView(new Image(getClass().getResourceAsStream("/images/button_play.png"))); imagePlay.setScaleX(0.40); imagePlay.setScaleY(0.40); imagePause = new ImageView(new Image(getClass().getResourceAsStream("/images/button_pause.png"))); imagePause.setScaleX(0.5); imagePause.setScaleY(0.5); imageSettings = new ImageView(new Image(getClass().getResourceAsStream("/images/settings.png"))); imageSettings.setScaleX(0.5); imageSettings.setScaleY(0.5); imageUpdate = new ImageView(new Image(getClass().getResourceAsStream("/images/refresh.png"))); imageUpdate.setScaleX(0.5); imageUpdate.setScaleY(0.5); imageAdd = new ImageView(new Image(getClass().getResourceAsStream("/images/add.png"))); imageAdd.setScaleX(0.5); imageAdd.setScaleY(0.5); imageRename = new ImageView(new Image(getClass().getResourceAsStream("/images/rename.png"))); imageRename.setScaleX(0.5); imageRename.setScaleY(0.5); imageDelete = new ImageView(new Image(getClass().getResourceAsStream("/images/delete.png"))); imageDelete.setScaleX(0.5); imageDelete.setScaleY(0.5); stateButton.setGraphic(imagePlay); settingsButton.setGraphic(imageSettings); refreshButton.setGraphic(imageUpdate); refreshButton.setTooltip(new Tooltip(res.getString("tooltip_sync"))); addButton.setGraphic(imageAdd); addButton.setOnAction((evt) -> createOfflinePlaylist()); addButton.setTooltip(new Tooltip(res.getString("tooltip_add_offline"))); renameButton.setGraphic(imageRename); renameButton.setOnAction(evt -> renamePlaylist()); renameButton.setTooltip(new Tooltip(res.getString("rename_playlist"))); deleteButton.setGraphic(imageDelete); deleteButton.setOnAction(evt -> deletePlaylist()); deleteButton.setTooltip(new Tooltip(res.getString("delete_playlist"))); loadProgressBar.setCursor(Cursor.HAND); volumeSlider.setCursor(Cursor.HAND); updatePlaylists(); if (Settings.lastPlaylistId != null) { currentPlaylist = ((ObservableList<Playlist>) playlistsView.getItems()) .stream() .filter((playlist) -> playlist.getId().equals(Settings.lastPlaylistId)) .findFirst() .orElse(null); playlistsView.getSelectionModel().select(currentPlaylist); playlistsView.scrollTo(currentPlaylist); Platform.runLater( () -> { if (Settings.lastTrackId != null) { currentTrack = ((ObservableList<Track>) tracksView.getItems()) .stream() .filter((track) -> track.getId().equals(Settings.lastTrackId)) .findFirst() .orElse(null); tracksView.getSelectionModel().select(currentTrack); tracksView.scrollTo(currentTrack); } }); } new Timer() .scheduleAtFixedRate( new TimerTask() { @Override public void run() { updatePlayProgress(); } }, 100, 100); setupTracksContextMenu(); setupShortcuts(); Platform.runLater( () -> { tracksView.requestFocus(); }); }
@FXML void playTrack(Track t) { if (tweenBlock) return; tweenBlock = true; stop( () -> { currentPlaylist = (Playlist) playlistsView.getSelectionModel().getSelectedItem(); currentTrack = t; if (player != null) { player.dispose(); } if (t == null) { return; } timeUpdate = 9; if (currentPlaylist != null) { Tray.announce("[" + currentPlaylist.getTitle() + "] " + t.getTitle()); } Platform.runLater( () -> { infoLabel.setText(res.getString("playing_offline") + t.getTitle()); log.info("Playing offline: " + t.getTitle()); }); try { Media media = new Media(Cache.getContent(t).toURI().toString()); player = new MediaPlayer(media); player.setVolume(Settings.currentVolume); player.play(); } catch (MediaException ex) { Platform.runLater( () -> { infoLabel.setText( String.format(res.getString("cant_play_offline_not_exist"), t.getTitle())); log.error("Can't play: seems that track does not exist - " + t.getTitle()); }); } if (player != null) { pushToPlayStack(getSelectedPlaylist(), t); player.setOnEndOfMedia( () -> { String mode = Settings.currentMode; if (mode.equals(Settings.MODE_NEXT)) { playNext(); } else if (mode.equals(Settings.MODE_RANDOM)) { playRandom(); } else if (mode.equals(Settings.MODE_SAME)) { playSame(); } }); } Platform.runLater( () -> { isPlaying = true; tweenBlock = false; titleLabel.setText(t.getTitle()); stateButton.setGraphic(imagePause); }); }); }
private void infoAndAnnounce(String message) { infoLabel.setText(message); Tray.announce(message); }
public entryView(Object object) { getChildren().clear(); getStylesheets().add("css/entryView.css"); giveNode(object); BorderPane mainpane = new BorderPane(); BorderPane centerpane = new BorderPane(); BorderPane bottompane = new BorderPane(); GridPane divgrid = new GridPane(); GridPane maingrid = new GridPane(); Label emptylab = new Label(); Label divlab = new Label(); VBox options = new VBox(); VBox tlist = new VBox(); Button ok = new Button("ok"); Periods periods = new Periods(); TList loadteacher = new TList(); DatePicker date = new DatePicker(); BorderPane datepane = new BorderPane(); BorderPane nextpane = new BorderPane(); Button next = new Button("next"); options.setId("options"); tlist.setId("tlist"); divgrid.setId("divgrid"); bottompane.setId("bottompane"); periods.setId("period"); divlab.setId("divlabel"); datepane.setId("datepane"); nextpane.setId("nextpane"); emptylab.setPrefHeight(100); bottompane.setStyle("-fx-background-color:#ecf0f1;"); StringConverter converter = new StringConverter<LocalDate>() { DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @Override public String toString(LocalDate date) { if (date != null) { return dateFormatter.format(date); } else { return ""; } } @Override public LocalDate fromString(String string) { if (string != null && !string.isEmpty()) { return LocalDate.parse(string, dateFormatter); } else { return null; } } }; date.setConverter(converter); date.setPromptText("dd-MM-yyyy".toLowerCase()); date.setValue(LocalDate.now()); maingrid = div.loadDiv(); list = (ListView) div.takelist(); periods.period(); list.getSelectionModel().select(0); divlab.setText((String) list.getItems().get(0)); list.setOnMouseClicked( e -> { divlab.setText((String) list.getSelectionModel().getSelectedItem()); periods.getChildren().clear(); periods.period(); }); final Node node = maingrid.getChildren().get(0); Platform.runLater( new Runnable() { @Override public void run() { node.requestFocus(); } }); next.setOnAction( e -> { // list.getSelectionModel().getSelectedIndex()+1 list.getSelectionModel().select(list.getSelectionModel().getSelectedIndex() + 1); divlab.setText((String) list.getSelectionModel().getSelectedItem()); }); nextpane.setRight(next); datepane.setRight(date); options.getChildren().clear(); options.getChildren().add(maingrid); divgrid.setHgap(5); // divgrid.add(emptylab, 0, 1); divgrid.add(datepane, 1, 0); divgrid.add(divlab, 0, 2); divgrid.add(periods, 1, 2); divgrid.add(nextpane, 1, 3); divgrid.setAlignment(Pos.TOP_CENTER); mainpane.setCenter(centerpane); mainpane.setLeft(options); mainpane.setRight(loadteacher); centerpane.setCenter(divgrid); centerpane.setBottom(bottompane); bottompane.setRight(ok); addCloseButton cb = new addCloseButton(); cb.addxb(1); setTop(cb); setCenter(mainpane); }