diff --git a/fmframework/src/sarsoo/fmframework/fx/AlbumTab.java b/fmframework/src/sarsoo/fmframework/fx/AlbumTab.java new file mode 100644 index 0000000..9bb27ab --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/AlbumTab.java @@ -0,0 +1,38 @@ +package sarsoo.fmframework.fx; + +import java.io.IOException; + +import javafx.scene.control.*; +import javafx.scene.layout.*; +import sarsoo.fmframework.fx.controller.AlbumPaneController; +import sarsoo.fmframework.music.Album; + + +import javafx.fxml.FXMLLoader; + +public class AlbumTab extends Tab { + + public AlbumTab(Album album) throws IOException { + + setText(album.getName()); + + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/AlbumPane.fxml")); + + AnchorPane pane = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(pane, 0.0); + AnchorPane.setLeftAnchor(pane, 0.0); + AnchorPane.setRightAnchor(pane, 0.0); + AnchorPane.setBottomAnchor(pane, 0.0); + + setContent(pane); + + AlbumPaneController control = (AlbumPaneController) loader.getController(); + + control.populate(album); + + + + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/ArtistTab.java b/fmframework/src/sarsoo/fmframework/fx/ArtistTab.java new file mode 100644 index 0000000..107a802 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/ArtistTab.java @@ -0,0 +1,38 @@ +package sarsoo.fmframework.fx; + +import java.io.IOException; + +import javafx.scene.control.*; +import javafx.scene.layout.*; +import sarsoo.fmframework.fx.controller.AlbumPaneController; +import sarsoo.fmframework.fx.controller.ArtistPaneController; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import javafx.fxml.FXMLLoader; + +public class ArtistTab extends Tab { + + public ArtistTab(Artist artist) throws IOException { + + setText(artist.getName()); + + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/ArtistPane.fxml")); + + AnchorPane pane = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(pane, 0.0); + AnchorPane.setLeftAnchor(pane, 0.0); + AnchorPane.setRightAnchor(pane, 0.0); + AnchorPane.setBottomAnchor(pane, 0.0); + + setContent(pane); + + ArtistPaneController control = (ArtistPaneController) loader.getController(); + + control.populate(artist); + + + + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java index 4c48ad2..a04939d 100644 --- a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java +++ b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java @@ -7,25 +7,33 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; +import sarsoo.fmframework.fx.controller.ControllerMain; import sarsoo.fmframework.util.Reference; public class FmFramework extends Application { private Stage stage; private Scene rootScene; + + private static ControllerMain control; @Override public void start(Stage stage) throws Exception { this.stage = stage; - Parent root = FXMLLoader.load(getClass().getResource("ui/main.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/main.fxml")); + +// Parent root = FXMLLoader.load(getClass().getResource("ui/main.fxml")); + Parent root = (Parent)loader.load(); Scene scene = new Scene(root, 800, 400); rootScene = scene; // scene.getStylesheets().add("styles/style.css"); - stage.setTitle("FM Framework"); + control = (ControllerMain)loader.getController(); + + stage.setTitle("fm framework"); stage.setScene(scene); stage.show(); @@ -38,8 +46,10 @@ public class FmFramework extends Application { public void changeScene() throws IOException { Parent root = FXMLLoader.load(getClass().getResource("ui/changed.fxml")); - - + } + + public static ControllerMain getController() { + return control; } } diff --git a/fmframework/src/sarsoo/fmframework/fx/TrackTab.java b/fmframework/src/sarsoo/fmframework/fx/TrackTab.java new file mode 100644 index 0000000..e18ecfd --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/TrackTab.java @@ -0,0 +1,5 @@ +package sarsoo.fmframework.fx; + +public class TrackTab { + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/AlbumPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/AlbumPaneController.java new file mode 100644 index 0000000..9597388 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/controller/AlbumPaneController.java @@ -0,0 +1,146 @@ +package sarsoo.fmframework.fx.controller; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Locale; + +import javax.swing.JOptionPane; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.text.Text; +import sarsoo.fmframework.fx.ArtistTab; +import sarsoo.fmframework.fx.FmFramework; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Wiki; +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.util.FMObjList; +import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Maths; +import sarsoo.fmframework.util.Reference; +import javafx.scene.control.*; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.GridPane; +import javafx.scene.chart.*; +import javafx.collections.ObservableList; +import javafx.collections.FXCollections; + +public class AlbumPaneController { + + @FXML + private Label labelAlbumName; + + @FXML + private Label labelArtistName; + + @FXML + private Label labelUserScrobbles; + + @FXML + private Label labelRatio; + + @FXML + private Label labelTotalListeners; + + @FXML + private Label labelTotalScrobbles; + + @FXML + private TextArea textAreaWiki; + + @FXML + public void initialize() { + + labelAlbumName.setText("Hello World"); + + } + + Album album; + + public void populate(Album album) { + + this.album = album; + + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelAlbumName.setText(album.getName()); + labelArtistName.setText(album.getArtist().getName()); + labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); + + labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); + labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles"); + + double ratio = album.getTimeListenRatio(); + + + if (ratio > 1) { + labelRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + labelRatio.setText("listen every day"); + } else { + labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + + Wiki wiki = album.getWiki(); + + if(wiki != null) { + + textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); + } + } + + @FXML + protected void handleRefresh(ActionEvent event) { + refresh(); + } + + @FXML + protected void viewOnline(ActionEvent event) { + Network.openURL(album.getUrl()); + } + + @FXML + protected void viewArtist(ActionEvent event) throws IOException { + FmFramework.getController().addTab(new ArtistTab(album.getArtist())); + } + + @FXML + protected void viewRYM(ActionEvent event) { + Network.openURL(album.getRymURL()); + } + + public void refresh() { + album.refresh(); + + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); + + labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); + labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles"); + + double ratio = album.getTimeListenRatio(); + + + if (ratio > 1) { + labelRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + labelRatio.setText("listen every day"); + } else { + labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + + Wiki wiki = album.getWiki(); + + if(wiki != null) { + + textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); + } + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java b/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java deleted file mode 100644 index 8f1e489..0000000 --- a/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java +++ /dev/null @@ -1,76 +0,0 @@ -package sarsoo.fmframework.fx.controller; - -import java.io.IOException; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Locale; - -import javax.swing.JOptionPane; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.text.Text; -import sarsoo.fmframework.music.Album; -import sarsoo.fmframework.util.FMObjList; -import sarsoo.fmframework.util.Getter; -import sarsoo.fmframework.util.Maths; -import sarsoo.fmframework.util.Reference; -import javafx.scene.control.*; -import javafx.scene.layout.GridPane; -import javafx.scene.chart.*; -import javafx.collections.ObservableList; -import javafx.collections.FXCollections; - -public class AlbumTabController { - - @FXML - private Label labelAlbumName; - - @FXML - private Label labelArtistName; - - @FXML - private Label labelUserScrobbles; - - @FXML - private Label labelRatio; - - @FXML - private Label labelTotalListeners; - - @FXML - private Label labelTotalScrobbles; - - @FXML - public void initialize() { - - labelAlbumName.setText("Hello World"); - - } - - public void populateTab(Album album) { - NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - - labelAlbumName.setText(album.getName()); - labelArtistName.setText(album.getArtist().getName()); - labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) - + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); - - labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); - labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles"); - - double ratio = album.getTimeListenRatio(); - - - if (ratio > 1) { - labelRatio.setText(String.format("listen every %.2f days", ratio)); - } else if (ratio == 1) { - labelRatio.setText("listen every day"); - } else { - labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); - } - - } - -} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java new file mode 100644 index 0000000..54e3748 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java @@ -0,0 +1,138 @@ +package sarsoo.fmframework.fx.controller; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Locale; + +import javax.swing.JOptionPane; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.text.Text; +import sarsoo.fmframework.fx.FmFramework; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.Wiki; +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.util.FMObjList; +import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Maths; +import sarsoo.fmframework.util.Reference; +import javafx.scene.control.*; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.GridPane; +import javafx.scene.chart.*; +import javafx.collections.ObservableList; +import javafx.collections.FXCollections; + +public class ArtistPaneController { + + @FXML + private Label labelArtistName; + + @FXML + private Label labelUserScrobbles; + + @FXML + private Label labelRatio; + + @FXML + private Label labelTotalListeners; + + @FXML + private Label labelTotalScrobbles; + + @FXML + private TextArea textAreaWiki; + + @FXML + public void initialize() { + + + + } + + Artist artist; + + public void populate(Artist artist) { + + this.artist = artist; + + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelArtistName.setText(artist.getName()); + labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName()))); + + labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners"); + labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles"); + + double ratio = artist.getTimeListenRatio(); + + + if (ratio > 1) { + labelRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + labelRatio.setText("listen every day"); + } else { + labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + + Wiki wiki = artist.getWiki(); + + if(wiki != null) { + + textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); + } + } + + @FXML + protected void handleRefresh(ActionEvent event) { + refresh(); + } + + @FXML + protected void viewOnline(ActionEvent event) { + Network.openURL(artist.getUrl()); + } + + + @FXML + protected void viewRYM(ActionEvent event) { + Network.openURL(artist.getRymURL()); + } + + public void refresh() { + artist.refresh(); + + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName()))); + + labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners"); + labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles"); + + double ratio = artist.getTimeListenRatio(); + + + if (ratio > 1) { + labelRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + labelRatio.setText("listen every day"); + } else { + labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + + Wiki wiki = artist.getWiki(); + + if(wiki != null) { + + textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); + } + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index 9d05623..984782e 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -12,6 +12,8 @@ import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.text.Text; +import sarsoo.fmframework.fx.AlbumTab; +import sarsoo.fmframework.fx.ArtistTab; import sarsoo.fmframework.fx.FMObjListTab; import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Tag; @@ -139,6 +141,14 @@ public class ControllerMain { // "rock"))); // tabPane.getTabs().add(tab); // + + tabPane.getTabs().add(new AlbumTab(Getter.getAlbum())); + } + + @FXML + protected void handleLookupArtist(ActionEvent event) throws IOException { + + tabPane.getTabs().add(new ArtistTab(Getter.getArtist())); } @FXML @@ -230,4 +240,7 @@ public class ControllerMain { } } + public void addTab(Tab tab) { + tabPane.getTabs().add(tab); + } } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java index 49db885..33eb772 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java @@ -38,7 +38,7 @@ public class FMObjListPaneController { FMObj obj = list.get(counter); - Label name = new Label(obj.getName()); + Label name = new Label(obj.getName().toLowerCase()); Label userScrobbles = new Label(numberFormat.format(obj.getUserPlayCount())); Label totalScrobbles = new Label(numberFormat.format(obj.getPlayCount())); diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml new file mode 100644 index 0000000..40dfdbb --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml @@ -0,0 +1,85 @@ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +