diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..f4f7a99 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,10 @@ package sbu.javafx; import javafx.application.Application; -public class Launcher{ +public class Launcher { public static void main(String[] args) { - // TODO: Launch the JavaFX application by calling Application.launch(Main.class) } + // TODO: Launch the JavaFX application by calling Application.launch(Main.class) + + Application.launch(Main.class); + } } diff --git a/src/main/java/sbu/javafx/Main.java b/src/main/java/sbu/javafx/Main.java new file mode 100644 index 0000000..1385424 --- /dev/null +++ b/src/main/java/sbu/javafx/Main.java @@ -0,0 +1,39 @@ +package sbu.javafx; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + @Override + public void start(Stage primaryStage) throws Exception { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("/sbu/javafx/App-view.fxml")); + Parent root = loader.load(); + + MusicController controller = loader.getController(); + + controller.musicsListView.getItems().addAll( + new Song("Blinding Lights", "The Weeknd"), + new Song("Flowers", "Miley Cyrus"), + new Song("As It Was", "Harry Styles") + ); + + controller.setupListView(controller.musicsListView); + + Scene scene = new Scene(root, 600, 500); + scene.getStylesheets().add( + getClass().getResource("/css/light.css").toExternalForm() + ); + + primaryStage.setTitle("Music Player"); + primaryStage.setScene(scene); + primaryStage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..b97a82c 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -2,30 +2,189 @@ package sbu.javafx; import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.*; +import javafx.scene.Scene; import javafx.scene.layout.VBox; + public class MusicController { + @FXML + public ListView playlistListView; + @FXML + public ListView musicsListView; + @FXML + private VBox root; + @FXML + Label nowPlayingLabel; + @FXML + Button playPauseBtn; + @FXML + Button openPlaylistBtn; + @FXML + Button themeToggleBtn; + private boolean isDarkMode=true; + private boolean isPlaying=false; + private Song currentSong = null; + ImageView playIcon; + ImageView pauseIcon; + // TODO: Define your UI components using the @FXML annotation. + @FXML + public void initialize() { + Image playImg = new Image(getClass().getResourceAsStream("/image/play.png")); + Image pauseImg = new Image(getClass().getResourceAsStream("/image/pause.png")); + + playIcon = new ImageView(playImg); + pauseIcon = new ImageView(pauseImg); + + playIcon.setFitWidth(35); + playIcon.setFitHeight(35); + pauseIcon.setFitWidth(35); + pauseIcon.setFitHeight(35); + + playPauseBtn.setGraphic(playIcon); + + } + + public void setupListView(ListView listView) { + + listView.setCellFactory(param -> new ListCell() { + @Override + protected void updateItem(Song song, boolean empty) { + super.updateItem(song, empty); + + if (empty || song == null) { + setText(null); + setGraphic(null); + return; + } + + Label nameLabel = new Label(song.getName()); + nameLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 14px;"); + + Label singerLabel = new Label(song.getSinger()); + singerLabel.setStyle("-fx-text-fill: gray; -fx-font-size: 12px;"); + + VBox songInfo = new VBox(3); + songInfo.setAlignment(Pos.CENTER_LEFT); + + songInfo.getChildren().addAll(nameLabel, singerLabel); + + Button addToPlaylistBtn = new Button("Add to playlist"); + addToPlaylistBtn.getStyleClass().add("playlist-button"); + addToPlaylistBtn.setOnAction(e -> { + addToPlaylist(e, song); + }); + + Button playBtn = new Button("Play"); + playBtn.getStyleClass().add("play-button"); + playBtn.setOnAction(e -> { + play(e, song); + }); + + HBox row = new HBox(10); + row.setPadding(new Insets(10)); + row.setAlignment(Pos.CENTER_LEFT); + + Region spacer = new Region(); + HBox.setHgrow(spacer, Priority.ALWAYS); + + row.getChildren().addAll(songInfo, spacer, playBtn, addToPlaylistBtn); + + setGraphic(row); + } + }); + } + + @FXML + public void toggleTheme(ActionEvent event) { + if (isDarkMode) { + themeToggleBtn.setText("Light"); + changeTheme(); + isDarkMode = false; + } else { + themeToggleBtn.setText("Dark"); + changeTheme(); + isDarkMode = true; + } + } + + public void changeTheme(){ + + + Scene scene = root.getScene(); + + scene.getStylesheets().clear(); + + if(isDarkMode){ + scene.getStylesheets().add( + getClass().getResource("/css/dark.css").toExternalForm() + ); + + }else{ + scene.getStylesheets().add( + getClass().getResource("/css/light.css").toExternalForm() + ); + } + + isDarkMode=!isDarkMode; + } + //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. + @FXML public void handlePlayAction() { //Update labels, change button icons, etc. } + public void play(ActionEvent event, Song song){ + currentSong=song; + nowPlayingLabel.setText(song.getName()); + if (!isPlaying) + playPause(event); + //کد پخش + } + + @FXML + public void playPause(ActionEvent a){ + if(isPlaying){ + playPauseBtn.setGraphic(playIcon); + isPlaying=false; + //کد توقف اینجاست چون برای هر توقفی دکمه ی پاز رو میزنیم ولی برای پلی ممکنه از بین آهنگ ها بزنیم + } + else{ + playPauseBtn.setGraphic(pauseIcon); + isPlaying=true; + } + } + //TODO: Logic to add a specific song to the user's playlist. - public void addToPlaylist(String songName) { + public void addToPlaylist(ActionEvent event, Song song) { //Add the song to a list or update a ListView. + playlistListView.getItems().add(song); } // TODO:This method should open a new window or change the current scene to display the "Playlist" page. public void openPlaylistWindow() { //Create a new stage and show the playlist UI. + musicsListView.setVisible(false); + if(playlistListView!=null) + playlistListView.setVisible(true); + else + throw new RuntimeException("Playlist is empty"); } + } diff --git a/src/main/java/sbu/javafx/Song.java b/src/main/java/sbu/javafx/Song.java new file mode 100644 index 0000000..d24ae61 --- /dev/null +++ b/src/main/java/sbu/javafx/Song.java @@ -0,0 +1,18 @@ +package sbu.javafx; + +public class Song { + private String name; + private String singer; + public Song(String name, String singer) + { + this.name=name; + this.singer=singer; + } + + public String getName() { + return name; + } + public String getSinger() { + return singer; + } +} diff --git a/src/main/resources/css/dark.css b/src/main/resources/css/dark.css new file mode 100644 index 0000000..e23df1d --- /dev/null +++ b/src/main/resources/css/dark.css @@ -0,0 +1,47 @@ +.root{ + -fx-background-color: #0f172a; +} + +.label{ + -fx-text-fill: #f8fafc; +} + +.button{ + -fx-background-color: #334155;; + -fx-text-fill: white; + -fx-background-radius: 14px; + -fx-cursor: hand; +} + +.button:hover{ + -fx-background-color: #475569; +} + +.list-view{ + -fx-background-color: #111827; + -fx-control-inner-background: #111827; + -fx-background-radius: 16px; +} + +.list-cell{ + -fx-background-color: transparent; + -fx-text-fill: white; +} + +.list-cell:selected{ + -fx-background-color: #2563eb; +} + +.button.circle-button{ + + -fx-background-color: #dbeafe; + + -fx-background-radius: 100em; + -fx-background-insets: 0; + + -fx-padding: 0; + + -fx-pref-width: 34px; + -fx-pref-height: 34px; + +} \ No newline at end of file diff --git a/src/main/resources/css/light.css b/src/main/resources/css/light.css new file mode 100644 index 0000000..961717f --- /dev/null +++ b/src/main/resources/css/light.css @@ -0,0 +1,46 @@ +.root{ + -fx-background-color: #f8fafc; +} + +.label{ + -fx-text-fill: #1e293b; +} + +.button{ + -fx-background-color: #dbeafe; + -fx-text-fill: #1e3a8a; + -fx-background-radius: 14px; + -fx-cursor: hand; +} + +.button:hover{ + -fx-background-color: #bfdbfe; +} + +.list-view{ + -fx-background-color: #ffffff; + -fx-control-inner-background: #ffffff; + -fx-background-radius: 16px; +} + +.list-cell{ + -fx-background-color: transparent; +} + +.list-cell:selected { + -fx-background-color: #93c5fd; +} + +.button.circle-button{ + + -fx-background-color: #dbeafe; + + -fx-background-radius: 100em; + -fx-background-insets: 0; + + -fx-padding: 0; + + -fx-pref-width: 35px; + -fx-pref-height: 35px; + +} \ No newline at end of file diff --git a/src/main/resources/image/forward.png b/src/main/resources/image/forward.png new file mode 100644 index 0000000..2b0e588 Binary files /dev/null and b/src/main/resources/image/forward.png differ diff --git a/src/main/resources/image/pause.png b/src/main/resources/image/pause.png new file mode 100644 index 0000000..19024c7 Binary files /dev/null and b/src/main/resources/image/pause.png differ diff --git a/src/main/resources/image/play.png b/src/main/resources/image/play.png new file mode 100644 index 0000000..d61293b Binary files /dev/null and b/src/main/resources/image/play.png differ diff --git a/src/main/resources/image/rewind.png b/src/main/resources/image/rewind.png new file mode 100644 index 0000000..c09cd59 Binary files /dev/null and b/src/main/resources/image/rewind.png differ diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..ec21eaa 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,76 @@ - - + + + - + + + + + + + + + + + + + + + + +