@FXML void seek(MouseEvent evt) { if (player != null) { Duration d = player.getMedia().getDuration(); double millis = (evt.getX() / loadProgressBar.getWidth()) * d.toMillis(); Duration s = new Duration(millis); player.seek(s); } }
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)); }); } } }
@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(); }); }
public DownloadGUI() { setTitle("Rav's Download Manager"); setSize(640, 480); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { actionExit(); } }); JPanel addPanel = new JPanel(); pauseButton = new JButton("", new ImageIcon("icons/pause.gif")); pauseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionPause(); } }); pauseButton.setEnabled(false); addPanel.add(pauseButton); resumeButton = new JButton("", new ImageIcon("icons/resume.gif")); resumeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionResume(); } }); resumeButton.setEnabled(false); addPanel.add(resumeButton); cancelButton = new JButton("", new ImageIcon("icons/cancel.gif")); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionCancel(); } }); cancelButton.setEnabled(false); addPanel.add(cancelButton); clearButton = new JButton("", new ImageIcon("icons/clear.gif")); clearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionClear(); } }); clearButton.setEnabled(false); addPanel.add(clearButton); JPanel addPane2 = new JPanel(); addTextField = new JTextField(30); addPane2.add(addTextField); JButton addButton = new JButton("", new ImageIcon("icons/add.gif")); addButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { actionAdd(); } }); addPane2.add(addButton); tableModel = new DownloadList(); table = new JTable(tableModel); table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { tableSelectionChanged(); } }); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ProgressBar renderer = new ProgressBar(0, 100); renderer.setStringPainted(true); table.setDefaultRenderer(JProgressBar.class, renderer); table.setRowHeight((int) renderer.getPreferredSize().getHeight()); JPanel downloadsPanel = new JPanel(); downloadsPanel.setBorder(BorderFactory.createTitledBorder("Downloads")); downloadsPanel.setLayout(new BorderLayout()); downloadsPanel.add(new JScrollPane(table), BorderLayout.CENTER); getContentPane().setLayout(new GridLayout(3, 1)); getContentPane().add(addPane2); getContentPane().add(addPanel); getContentPane().add(downloadsPanel); }
protected void reset() { fCounterPanel.reset(); fProgressIndicator.reset(); fFailureView.clear(); fFailures.clear(); }
public static EventHandler<ActionEvent> getUploadHandler( FXController controller, ProgressBar progressBar, CheckBox stem) { return e -> { Alert a; if (selectedFiles != null) { controller.selectedFiles = new File[selectedFiles.size()]; for (int i = 0; i < selectedFiles.size(); i++) { String filepath = selectedFiles.get(i).getAbsolutePath(); if (lastUpload.contains(filepath)) { a = new Alert(Alert.AlertType.CONFIRMATION); a.setTitle("Are you sure?"); a.setContentText( "You just uploaded " + filepath + ", are you sure you want to upload it again?"); Optional<ButtonType> result = a.showAndWait(); if (result.get() != ButtonType.OK) { return; } } if (selectedFiles.get(i).isAbsolute() && selectedFiles.get(i).exists()) { controller.selectedFiles[i] = selectedFiles.get(i); } else { a = new Alert(Alert.AlertType.INFORMATION, "Invalid path to file.", ButtonType.OK); a.setTitle("Information"); a.showAndWait(); return; } } } else { a = new Alert(Alert.AlertType.INFORMATION, "Please select a file.", ButtonType.OK); a.initStyle(StageStyle.UTILITY); a.setTitle("Information"); a.showAndWait(); return; } progressBar.setProgress(0); controller.writeLog("Uploading file(s)..."); Button source = (Button) e.getSource(); source.setDisable(true); SwingWorker<Boolean, Double> worker = new SwingWorker<Boolean, Double>() { @Override protected Boolean doInBackground() throws Exception { String[] key = new String[FXController.selectedFiles.length]; publish(0.05); for (int i = 0; i < FXController.selectedFiles.length; i++) { key[i] = UUID.randomUUID().toString(); FileUtils.uploadFile(FXController.selectedFiles[i], key[i], AESCTR.secretKey); } publish(0.4); Map<String, ArrayList<StringPair>> map = SSE.EDBSetup( FXController.selectedFiles, AESCTR.secretKey, key, stem.isSelected()); publish(0.6); ObjectMapper mapper = new ObjectMapper(); try { String json = mapper.writeValueAsString(map); publish(0.8); HttpUtil.HttpPost(json); } catch (JsonProcessingException e1) { e1.printStackTrace(); return false; } publish(1.0); return true; } @Override protected void done() { Platform.runLater( new TimerTask() { @Override public void run() { Alert a; try { if (get()) { controller.writeLog("Upload successful!"); a = new Alert( Alert.AlertType.INFORMATION, "Upload successful!", ButtonType.OK); a.setTitle("Success!"); a.showAndWait(); lastUpload.clear(); for (File f : FXController.selectedFiles) { lastUpload.add(f.getAbsolutePath()); } } else { controller.writeLog("Upload failed!"); a = new Alert(Alert.AlertType.ERROR, "Upload failed!", ButtonType.OK); a.setTitle("Error!"); a.showAndWait(); } } catch (Exception ex) { a = new Alert(Alert.AlertType.ERROR, "Upload error!", ButtonType.OK); a.setTitle("Error!"); a.showAndWait(); ex.printStackTrace(); } source.setDisable(false); } }); } @Override protected void process(List<Double> n) { progressBar.setProgress(n.get(n.size() - 1)); } }; worker.execute(); }; }