diff --git a/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java b/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java index 82bc040..becb958 100644 --- a/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java +++ b/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java @@ -8,6 +8,7 @@ import java.util.Locale; import javafx.scene.control.*; import javafx.scene.layout.*; import sarsoo.fmframework.fx.controller.FMObjListPaneController; +import sarsoo.fmframework.fx.controller.FMObjListPaneEditController; import sarsoo.fmframework.music.FMObj; import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.Maths; @@ -39,6 +40,28 @@ public class FMObjListTab extends Tab { + } + + public FMObjListTab() throws IOException { + + setText("List"); + + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/FMObjListPaneEdit.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); + +// BorderPane + + setContent(pane); + + FMObjListPaneEditController control = (FMObjListPaneEditController) loader.getController(); + + } } diff --git a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java index 2b64a8b..c548ecd 100644 --- a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java +++ b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java @@ -34,7 +34,7 @@ public class FmFramework extends Application { control = (ControllerMain)loader.getController(); // (new Thread(new TagCaller())).start(); stage.setMinHeight(800); - stage.setMinWidth(1000); + stage.setMinWidth(960); stage.setTitle("fm framework"); stage.setScene(scene); stage.show(); diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java index 54e3748..107ab5a 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ArtistPaneController.java @@ -11,6 +11,8 @@ 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.FMObjListTab; import sarsoo.fmframework.fx.FmFramework; import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Artist; @@ -105,6 +107,16 @@ public class ArtistPaneController { Network.openURL(artist.getRymURL()); } + @FXML + protected void handleViewTracks(ActionEvent event) { + + try { + FmFramework.getController().addTab(new FMObjListTab(Getter.getArtistTracks(artist.getName(), Reference.getUserName()))); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void refresh() { artist.refresh(); diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index 4a265a5..5c2969b 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -76,7 +76,7 @@ public class ControllerMain { String scrobblesToday = numberFormat.format(Getter.getScrobblesToday(Reference.getUserName())); String scrobbles = numberFormat.format(Getter.getScrobbles(Reference.getUserName())); - tags = Getter.getUserTags(Reference.getUserName()); + TrackTab tab = new TrackTab(Getter.getLastTrack()); @@ -93,55 +93,7 @@ public class ControllerMain { addTab(tab); refreshPieCharts(); - - int counter; - for (counter = 0; counter < tags.size(); counter++) { - - String name = tags.get(counter).getName().toLowerCase(); - - // System.out.println(name); - - MenuItem item = new MenuItem(name); - - item.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent e) { - - // TAG ITEM HANDLER SERVICE - Service service = new Service() { - @Override - protected Task createTask() { - return new Task() { - @Override - protected Void call() throws Exception { - - FMObjListTab tab = new FMObjListTab(Getter - .getUserTag(Reference.getUserName(), name)); - - final CountDownLatch latch = new CountDownLatch(1); - Platform.runLater(new Runnable() { - @Override - public void run() { - try { - tabPane.getTabs().add(tab); - } finally { - latch.countDown(); - } - } - }); - latch.await(); - // Keep with the background work - return null; - } - }; - } - }; - service.start(); - } - }); - - menuTag.getItems().add(item); - } + updateTagMenu(); } finally { latch.countDown(); @@ -158,6 +110,63 @@ public class ControllerMain { service.start(); } + + private ArrayList tags; + public void updateTagMenu() { + tags = Getter.getUserTags(Reference.getUserName()); + + Collections.sort(tags); + + int counter; + for (counter = 0; counter < tags.size(); counter++) { + + String name = tags.get(counter).getName().toLowerCase(); + + + // System.out.println(name); + + MenuItem item = new MenuItem(name); + + item.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent e) { + + // TAG ITEM HANDLER SERVICE + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Void call() throws Exception { + + FMObjListTab tab = new FMObjListTab(Getter + .getUserTag(Reference.getUserName(), name)); + + final CountDownLatch latch = new CountDownLatch(1); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + tabPane.getTabs().add(tab); + } finally { + latch.countDown(); + } + } + }); + latch.await(); + // Keep with the background work + return null; + } + }; + } + }; + service.start(); + } + }); + + menuTag.getItems().add(item); + } + } public void updateGenrePieChart() { @@ -295,8 +304,6 @@ public class ControllerMain { @FXML private Menu menuTag; - private ArrayList tags; - // @FXML // protected void handleTagClick(ActionEvent event) throws IOException { // // System.out.println("clicked"); @@ -587,5 +594,17 @@ public class ControllerMain { }; service.start(); } + + @FXML + protected void handleCreateList(ActionEvent event) { + + try { + Tab tab = new FMObjListTab(); + addTab(tab); + } catch (IOException e) { + e.printStackTrace(); + } + + } } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java index 55011ea..1856fa3 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java @@ -3,6 +3,7 @@ package sarsoo.fmframework.fx.controller; import java.io.IOException; import java.text.NumberFormat; import java.util.Collections; +import java.util.Comparator; import java.util.Locale; import javafx.collections.FXCollections; @@ -11,7 +12,7 @@ import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.scene.control.Label; +import javafx.scene.control.*; import javafx.scene.input.MouseEvent; import sarsoo.fmframework.fx.AlbumTab; import sarsoo.fmframework.fx.ArtistTab; @@ -24,6 +25,7 @@ import sarsoo.fmframework.util.Maths; import sarsoo.fmframework.util.Reference; import javafx.scene.layout.*; import javafx.scene.chart.*; +import javafx.scene.chart.PieChart.Data; public class FMObjListPaneController { @@ -39,6 +41,9 @@ public class FMObjListPaneController { @FXML private PieChart pieChart; + @FXML + private PieChart pieChartArtists; + private FMObjList list; public void populate(FMObjList list) { @@ -88,11 +93,30 @@ public class FMObjListPaneController { } - ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()), new PieChart.Data("other", Getter.getScrobbles(Reference.getUserName()) - list.getTotalUserScrobbles())); + + ObservableList pieChartArtistsData = FXCollections.observableArrayList(); + int counter2; + for(counter2 = 0; counter2 < list.size(); counter2++) { + + PieChart.Data data = new PieChart.Data(list.get(counter2).getName(), list.get(counter2).getUserPlayCount()); + + pieChartArtistsData.add(data); + + } + + Collections.sort(pieChartArtistsData, new Comparator() { + + @Override + public int compare(Data arg0, Data arg1) { + return (int) (arg1.getPieValue() - arg0.getPieValue()); + } + }); + pieChart.setData(pieChartData); + pieChartArtists.setData(pieChartArtistsData); } @@ -154,5 +178,6 @@ public class FMObjListPaneController { new PieChart.Data("other", Getter.getScrobbles(Reference.getUserName()) - list.getTotalUserScrobbles())); pieChart.setData(pieChartData); } + } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneEditController.java b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneEditController.java new file mode 100644 index 0000000..6893762 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneEditController.java @@ -0,0 +1,224 @@ +package sarsoo.fmframework.fx.controller; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.Collections; +import java.util.Comparator; +import java.util.Locale; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.input.MouseEvent; +import sarsoo.fmframework.fx.AlbumTab; +import sarsoo.fmframework.fx.ArtistTab; +import sarsoo.fmframework.fx.FmFramework; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.FMObj; +import sarsoo.fmframework.music.Track; +import sarsoo.fmframework.util.FMObjList; +import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Maths; +import sarsoo.fmframework.util.Reference; +import javafx.scene.layout.*; +import javafx.scene.chart.*; +import javafx.scene.chart.PieChart.Data; + +public class FMObjListPaneEditController { + + @FXML + private Label labelTotalScrobbles; + + @FXML + private Label labelPercent; + + @FXML + private GridPane gridPaneFMObjs; + + @FXML + private PieChart pieChart; + + @FXML + private PieChart pieChartArtists; + + private FMObjList list = new FMObjList(); + + // public void populate(FMObjList list) { + // this.list = list; + // + // double percent = Maths.getPercentListening(list, Reference.getUserName()); + // NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + // + // labelTotalScrobbles.setText("Σ " + list.getTotalUserScrobbles()); + // labelPercent.setText(String.format("%.2f%%", percent)); + // + // Collections.sort(list); + // Collections.reverse(list); + // + // int counter; + // for (counter = 0; counter < list.size(); counter++) { + // + // FMObj obj = list.get(counter); + // + // Label name = new Label(obj.getName().toLowerCase()); + // + // name.getStyleClass().add("nameLabel"); + // + // name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { + // + // @Override + // public void handle(Event event) { + // + // try { + // FmFramework.getController().addTab(new ArtistTab((Artist) obj)); + // } catch (IOException e) { + // + // e.printStackTrace(); + // } + // + // } + // + // }); + // + // Label userScrobbles = new Label(numberFormat.format(obj.getUserPlayCount())); + // Label totalScrobbles = new Label(numberFormat.format(obj.getPlayCount())); + // + // gridPaneFMObjs.add(name, 0, counter); + // gridPaneFMObjs.add(userScrobbles, 1, counter); + // gridPaneFMObjs.add(totalScrobbles, 2, counter); + // + // } + // + // + // ObservableList pieChartData = + // FXCollections.observableArrayList( + // new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()), + // new PieChart.Data("other", Getter.getScrobbles(Reference.getUserName()) - + // list.getTotalUserScrobbles())); + // + // ObservableList pieChartArtistsData = + // FXCollections.observableArrayList(); + // int counter2; + // for(counter2 = 0; counter2 < list.size(); counter2++) { + // + // PieChart.Data data = new PieChart.Data(list.get(counter2).getName(), + // list.get(counter2).getUserPlayCount()); + // + // pieChartArtistsData.add(data); + // + // } + // + // Collections.sort(pieChartArtistsData, new Comparator() { + // + // @Override + // public int compare(Data arg0, Data arg1) { + // return (int) (arg1.getPieValue() - arg0.getPieValue()); + // } + // }); + // + // pieChart.setData(pieChartData); + // pieChartArtists.setData(pieChartArtistsData); + // + // } + + @FXML + protected void handleRefresh(ActionEvent event) { + + refresh(); + } + + public void refresh() { + double percent = Maths.getPercentListening(list, Reference.getUserName()); + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelTotalScrobbles.setText("Σ " + list.getTotalUserScrobbles()); + labelPercent.setText(String.format("%.2f%%", percent)); + + Collections.sort(list); + Collections.reverse(list); + + gridPaneFMObjs.getChildren().clear(); + + int counter; + for (counter = 0; counter < list.size(); counter++) { + + FMObj obj = list.get(counter); + + Label name = new Label(obj.getName().toLowerCase()); + + name.getStyleClass().add("nameLabel"); + + name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { + + @Override + public void handle(Event event) { + + try { + FmFramework.getController().addTab(new ArtistTab((Artist) obj)); + } catch (IOException e) { + + e.printStackTrace(); + } + + } + + }); + + Label userScrobbles = new Label(numberFormat.format(obj.getUserPlayCount())); + Label totalScrobbles = new Label(numberFormat.format(obj.getPlayCount())); + + gridPaneFMObjs.add(name, 0, counter); + gridPaneFMObjs.add(userScrobbles, 1, counter); + gridPaneFMObjs.add(totalScrobbles, 2, counter); + + } + + ObservableList pieChartData = FXCollections + .observableArrayList(new PieChart.Data("list", list.getTotalUserScrobbles()), new PieChart.Data("other", + Getter.getScrobbles(Reference.getUserName()) - list.getTotalUserScrobbles())); + pieChart.setData(pieChartData); + + } + + @FXML + protected TextField textArtist; + @FXML + protected TextField textTrack; + @FXML + protected TextField textAlbum; + + @FXML + protected void handleAddTrack(ActionEvent event) { + + String name = textTrack.getText(); + System.out.println(name + "."); + String album = textAlbum.getText(); + System.out.println(album + "."); + String artist = textArtist.getText(); + System.out.println(artist + "."); + System.out.println("Click"); + + if ((name != null) && (artist != null)) { + System.out.println("not null"); + Track track = Track.getTrack(name, artist, Reference.getUserName()); + System.out.println("track created"); + if (album != null) { + Album albumObj = Album.getAlbum(album, artist, Reference.getUserName()); + System.out.println("album created"); + track.setAlbum(albumObj); + System.out.println("no album"); + } + + list.add(track); + } + + refresh(); + + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css b/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css index c23a1c8..6d146c7 100644 --- a/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css +++ b/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css @@ -1,16 +1,23 @@ -.title{ +.titleLabel{ - -fx-font-size: 400%; + -fx-font-size: 600%; + -fx-font-weight: bolder; + +} + +.subLabel{ + + -fx-font-size: 300%; + -fx-font-weight: bold; +} + +.normalLabel{ + + -fx-font-size: 200%; } -.sub{ - - - -} - -.wiki{ +.wikiTextArea{ } diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml index fa2d7e2..10d9f93 100644 --- a/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml +++ b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml @@ -28,32 +28,32 @@ -