@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); } } }); }
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); }
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); }); }
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(); }); } }
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 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); }); }); }); }
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; } } }
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); }); } }
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); }
@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"); }
@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); }); }); }
Playlist getSelectedPlaylist() { if (searching) return null; return (Playlist) playlistsView.getSelectionModel().getSelectedItem(); }
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(); }); }
void fillTracks(List<Track> tracks) { ObservableList<Track> items = FXCollections.observableArrayList(tracks); tracksView.setItems(items); }
Track getSelectedTrack() { return (Track) tracksView.getSelectionModel().getSelectedItem(); }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Demo"); /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Save", imageFile("images/save.png"))); fileMenu.getItems().add(new MenuItem("Save As...", imageFile("images/save_as.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); /* create the table (for the center of the user interface) */ table = new TableView<>(); table.setItems(DataSource.getAllStudents()); table.setEditable(true); /* create the table's columns */ TableColumn<Student, Integer> sidColumn = null; sidColumn = new TableColumn<>("SID"); sidColumn.setMinWidth(100); sidColumn.setCellValueFactory(new PropertyValueFactory<>("sid")); TableColumn<Student, String> firstNameColumn = null; firstNameColumn = new TableColumn<>("First Name"); firstNameColumn.setMinWidth(200); firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName")); firstNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); firstNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setFirstName(event.getNewValue()); }); TableColumn<Student, String> lastNameColumn = null; lastNameColumn = new TableColumn<>("Last Name"); lastNameColumn.setMinWidth(200); lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName")); lastNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn()); lastNameColumn.setOnEditCommit( (CellEditEvent<Student, String> event) -> { ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow())) .setLastName(event.getNewValue()); }); TableColumn<Student, Double> gpaColumn = null; gpaColumn = new TableColumn<>("GPA"); gpaColumn.setMinWidth(100); gpaColumn.setCellValueFactory(new PropertyValueFactory<>("gpa")); table.getColumns().add(sidColumn); table.getColumns().add(lastNameColumn); table.getColumns().add(firstNameColumn); table.getColumns().add(gpaColumn); /* create an edit form (for the bottom of the user interface) */ GridPane editArea = new GridPane(); editArea.setPadding(new Insets(10, 10, 10, 10)); editArea.setVgap(10); editArea.setHgap(10); Label sidLabel = new Label("SID:"); editArea.add(sidLabel, 0, 0); TextField sidField = new TextField(); sidField.setPromptText("SID"); editArea.add(sidField, 1, 0); Label fnameLabel = new Label("First name:"); editArea.add(fnameLabel, 0, 1); TextField fnameField = new TextField(); fnameField.setPromptText("First Name"); editArea.add(fnameField, 1, 1); Label lnameLabel = new Label("Last name:"); editArea.add(lnameLabel, 0, 2); TextField lnameField = new TextField(); lnameField.setPromptText("Last Name"); editArea.add(lnameField, 1, 2); Label gpaLabel = new Label("GPA:"); editArea.add(gpaLabel, 0, 3); TextField gpaField = new TextField(); gpaField.setPromptText("GPA"); editArea.add(gpaField, 1, 3); Button addButton = new Button("Add"); addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { int sid = Integer.parseInt(sidField.getText()); String firstName = fnameField.getText(); String lastName = lnameField.getText(); double gpa = Double.parseDouble(gpaField.getText()); table.getItems().add(new Student(sid, firstName, lastName, gpa)); sidField.setText(""); fnameField.setText(""); lnameField.setText(""); gpaField.setText(""); } }); editArea.add(addButton, 1, 4); /* arrange all components in the main user interface */ layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(editArea); Scene scene = new Scene(layout, 600, 600); primaryStage.setScene(scene); primaryStage.show(); }
void playSelectedTrack() { Track t = (Track) tracksView.getSelectionModel().getSelectedItem(); if (t != null) Settings.lastTrackId = t.getId(); playTrack(t); }
@Override public void start(Stage primaryStage) throws Exception { /* create the menu (for the top of the user interface) */ Menu fileMenu = new Menu("File"); MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png")); newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N")); fileMenu.getItems().add(newMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png"))); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem saveMenuItem = new MenuItem("Save", imageFile("images/save.png")); fileMenu.getItems().add(saveMenuItem); MenuItem saveAsMenuItem = new MenuItem("Save As...", imageFile("images/save_as.png")); fileMenu.getItems().add(saveAsMenuItem); fileMenu.getItems().add(new SeparatorMenuItem()); MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png")); fileMenu.getItems().add(exitMenuItem); exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q")); exitMenuItem.setOnAction(e -> System.exit(0)); Menu editMenu = new Menu("Edit"); editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png"))); editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png"))); editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png"))); Menu helpMenu = new Menu("Help"); helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png"))); helpMenu.getItems().add(new SeparatorMenuItem()); helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png"))); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(fileMenu); menuBar.getMenus().add(editMenu); menuBar.getMenus().add(helpMenu); primaryStage.setTitle("Lab08"); // grid contains all of the textfeilds, labels , buttons, ect.. GridPane grid = new GridPane(); // the tableview puts all of our data into a exel like format TableView<StudentRecord> table = new TableView<>(); table.setItems(DataSource.getAllMarks()); table.setEditable(true); TableColumn<StudentRecord, String> IDColumn = null; IDColumn = new TableColumn<>("SID"); IDColumn.setMinWidth(100); // the thing in quotes is what it will search for in the StudentRecords.java (MAKE SURE THERE IS // A GET FUNCTION FOR THAT VARIBALE) IDColumn.setCellValueFactory(new PropertyValueFactory<>("ID")); TableColumn<StudentRecord, Double> AssignmentColumn = null; AssignmentColumn = new TableColumn<>("Assignment"); AssignmentColumn.setMinWidth(100); AssignmentColumn.setCellValueFactory(new PropertyValueFactory<>("Assign")); TableColumn<StudentRecord, Float> MidtermColumn = null; MidtermColumn = new TableColumn<>("Midterm"); MidtermColumn.setMinWidth(100); MidtermColumn.setCellValueFactory(new PropertyValueFactory<>("Midterm")); TableColumn<StudentRecord, Float> FinalColumn = null; FinalColumn = new TableColumn<>("Final Exam"); FinalColumn.setMinWidth(100); FinalColumn.setCellValueFactory(new PropertyValueFactory<>("Final")); TableColumn<StudentRecord, String> GradeColumn = null; GradeColumn = new TableColumn<>("Letter Grade"); GradeColumn.setMinWidth(100); GradeColumn.setCellValueFactory(new PropertyValueFactory<>("Grade")); table.getColumns().add(IDColumn); table.getColumns().add(AssignmentColumn); table.getColumns().add(MidtermColumn); table.getColumns().add(FinalColumn); table.getColumns().add(GradeColumn); Label IDLabel = new Label("SID:"); grid.add(IDLabel, 0, 0); TextField IDField = new TextField(); IDField.setPromptText("SID"); grid.add(IDField, 1, 0); Label AssignLabel = new Label("Assignments:"); grid.add(AssignLabel, 2, 0); TextField AssignField = new TextField(); AssignField.setPromptText("Assignment"); grid.add(AssignField, 3, 0); Label MidLabel = new Label("Midterm:"); grid.add(MidLabel, 0, 1); TextField midField = new TextField(); midField.setPromptText("Midterm"); grid.add(midField, 1, 1); Label FinalLabel = new Label("Final:"); grid.add(FinalLabel, 2, 1); TextField FinalField = new TextField(); FinalField.setPromptText("Final"); grid.add(FinalField, 3, 1); Button AddButton = new Button("Add"); AddButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { char Grade; String SID = IDField.getText(); Float Assignment = Float.parseFloat(AssignField.getText()); Float Midterm = Float.parseFloat(midField.getText()); Float Final = Float.parseFloat(FinalField.getText()); table.getItems().add(new StudentRecord(SID, Assignment, Midterm, Final)); IDField.setText(""); AssignField.setText(""); midField.setText(""); FinalField.setText(""); } }); grid.add(AddButton, 0, 2); layout = new BorderPane(); layout.setTop(menuBar); layout.setCenter(table); layout.setBottom(grid); Scene scene = new Scene(layout); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(10); grid.setHgap(10); primaryStage.setScene(scene); primaryStage.show(); }
void deleteFromOfflinePlaylist(Track t, Playlist p) { if (interfaceDisabled) return; tracksView.getItems().remove(t); Cache.deleteFromPlaylist(t, p); }