added track tab
This commit is contained in:
parent
a00199fbd3
commit
0ea8f91e14
@ -1,5 +1,38 @@
|
||||
package sarsoo.fmframework.fx;
|
||||
|
||||
public class TrackTab {
|
||||
import java.io.IOException;
|
||||
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import sarsoo.fmframework.fx.controller.AlbumPaneController;
|
||||
import sarsoo.fmframework.fx.controller.TrackPaneController;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class TrackTab extends Tab {
|
||||
|
||||
public TrackTab(Track track) throws IOException {
|
||||
|
||||
setText(track.getName());
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/TrackPane.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);
|
||||
|
||||
TrackPaneController control = (TrackPaneController) loader.getController();
|
||||
|
||||
control.populate(track);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import javafx.scene.text.Text;
|
||||
import sarsoo.fmframework.fx.AlbumTab;
|
||||
import sarsoo.fmframework.fx.ArtistTab;
|
||||
import sarsoo.fmframework.fx.FMObjListTab;
|
||||
import sarsoo.fmframework.fx.TrackTab;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
@ -67,7 +68,7 @@ public class ControllerMain {
|
||||
int counter;
|
||||
for (counter = 0; counter < tags.size(); counter++) {
|
||||
|
||||
String name = tags.get(counter).getName();
|
||||
String name = tags.get(counter).getName().toLowerCase();
|
||||
|
||||
// System.out.println(name);
|
||||
|
||||
@ -80,7 +81,7 @@ public class ControllerMain {
|
||||
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
|
||||
|
||||
tabPane.getTabs().add(tab);
|
||||
System.out.println("tab added");
|
||||
// System.out.println("tab added");
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@ -151,6 +152,12 @@ public class ControllerMain {
|
||||
tabPane.getTabs().add(new ArtistTab(Getter.getArtist()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleLookupTrack(ActionEvent event) throws IOException {
|
||||
|
||||
tabPane.getTabs().add(new TrackTab(Getter.getTrack()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Menu menuTag;
|
||||
|
||||
@ -168,7 +175,7 @@ public class ControllerMain {
|
||||
int counter;
|
||||
for (counter = 0; counter < tags.size(); counter++) {
|
||||
|
||||
String name = tags.get(counter).getName();
|
||||
String name = tags.get(counter).getName().toLowerCase();
|
||||
|
||||
// System.out.println(name);
|
||||
|
||||
@ -198,7 +205,7 @@ public class ControllerMain {
|
||||
|
||||
if (event.getCode() == KeyCode.F5) {
|
||||
refresh();
|
||||
System.out.println("refreshed");
|
||||
// System.out.println("refreshed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,5 +249,8 @@ public class ControllerMain {
|
||||
|
||||
public void addTab(Tab tab) {
|
||||
tabPane.getTabs().add(tab);
|
||||
SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
|
||||
|
||||
selectionModel.select(tab);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
package sarsoo.fmframework.fx.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.event.Event;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import sarsoo.fmframework.fx.AlbumTab;
|
||||
import sarsoo.fmframework.fx.ArtistTab;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
@ -27,18 +35,35 @@ public class FMObjListPaneController {
|
||||
double percent = Maths.getPercentListening(list, Reference.getUserName());
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelTotalScrobbles.setText("Σ" + list.getTotalUserScrobbles());
|
||||
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++) {
|
||||
for (counter = 0; counter < list.size(); counter++) {
|
||||
|
||||
FMObj obj = list.get(counter);
|
||||
|
||||
Label name = new Label(obj.getName().toLowerCase());
|
||||
|
||||
name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
|
||||
|
||||
@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()));
|
||||
|
||||
@ -46,7 +71,6 @@ public class FMObjListPaneController {
|
||||
gridPaneFMObjs.add(userScrobbles, 1, counter);
|
||||
gridPaneFMObjs.add(totalScrobbles, 2, counter);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,146 @@
|
||||
package sarsoo.fmframework.fx.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import sarsoo.fmframework.fx.AlbumTab;
|
||||
import sarsoo.fmframework.fx.ArtistTab;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.music.Wiki;
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
public class TrackPaneController {
|
||||
|
||||
@FXML
|
||||
private Label labelTrackName;
|
||||
|
||||
@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
|
||||
private Button buttonViewAlbum;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
Track track;
|
||||
|
||||
public void populate(Track track) {
|
||||
|
||||
this.track = track;
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelTrackName.setText(track.getName());
|
||||
|
||||
if (track.getAlbum() == null)
|
||||
labelAlbumName.setVisible(false);
|
||||
else
|
||||
labelAlbumName.setText(track.getAlbum().getName());
|
||||
|
||||
labelArtistName.setText(track.getArtist().getName());
|
||||
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
||||
|
||||
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||
|
||||
double ratio = track.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 = track.getWiki();
|
||||
|
||||
if (wiki != null) {
|
||||
|
||||
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||
}
|
||||
|
||||
if (track.getAlbum() == null) {
|
||||
buttonViewAlbum.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleRefresh(ActionEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void viewOnline(ActionEvent event) {
|
||||
Network.openURL(track.getUrl());
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void viewArtist(ActionEvent event) throws IOException {
|
||||
FmFramework.getController().addTab(new ArtistTab(track.getArtist()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void viewAlbum(ActionEvent event) throws IOException {
|
||||
FmFramework.getController().addTab(new AlbumTab(track.getAlbum()));
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
track.refresh();
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
||||
|
||||
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||
|
||||
double ratio = track.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 = track.getWiki();
|
||||
|
||||
if (wiki != null) {
|
||||
|
||||
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
91
fmframework/src/sarsoo/fmframework/fx/ui/TrackPane.fxml
Normal file
91
fmframework/src/sarsoo/fmframework/fx/ui/TrackPane.fxml
Normal file
@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.paint.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.TrackPaneController">
|
||||
<children>
|
||||
<BorderPane fx:id="albumBorderPane" prefHeight="327.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
||||
<children>
|
||||
<GridPane prefHeight="325.0" prefWidth="296.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="115.0" minHeight="10.0" prefHeight="94.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="49.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="39.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="37.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label fx:id="labelTrackName" alignment="CENTER" text="Track Name" wrapText="true" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
|
||||
<font>
|
||||
<Font name="System Bold" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelArtistName" alignment="CENTER" text="Artist Name" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelUserScrobbles" alignment="CENTER" text="User Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelRatio" alignment="CENTER" text="Ratio" GridPane.halignment="CENTER" GridPane.rowIndex="4">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelTotalListeners" alignment="CENTER" text="Total Listeners" GridPane.halignment="CENTER" GridPane.rowIndex="5">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelTotalScrobbles" alignment="CENTER" text="Total Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="6">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="labelAlbumName" alignment="CENTER" text="Album Name" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
||||
<children>
|
||||
<TextArea fx:id="textAreaWiki" editable="false" layoutX="37.0" layoutY="34.0" prefHeight="285.0" prefWidth="296.0" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</center>
|
||||
<bottom>
|
||||
<ToolBar fx:id="toolBar" prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="buttonRefresh" mnemonicParsing="false" onAction="#handleRefresh" text="refresh" />
|
||||
<Button fx:id="buttonViewAlbum" mnemonicParsing="false" onAction="#viewAlbum" text="view album" />
|
||||
<Button fx:id="buttonViewArtist" mnemonicParsing="false" onAction="#viewArtist" text="view artist" />
|
||||
<Button fx:id="buttonViewOnline" mnemonicParsing="false" onAction="#viewOnline" text="view online" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
</children>
|
||||
</AnchorPane>
|
@ -12,7 +12,7 @@
|
||||
<menus>
|
||||
<Menu fx:id="menuLookup" mnemonicParsing="false" text="lookup">
|
||||
<items>
|
||||
<MenuItem fx:id="menuItemTrack" mnemonicParsing="false" text="track" />
|
||||
<MenuItem fx:id="menuItemTrack" mnemonicParsing="false" onAction="#handleLookupTrack" text="track" />
|
||||
<MenuItem fx:id="menuItemAlbum" mnemonicParsing="false" onAction="#handleLookupAlbum" text="album" />
|
||||
<MenuItem fx:id="menuItemArtist" mnemonicParsing="false" onAction="#handleLookupArtist" text="artist" />
|
||||
</items>
|
||||
|
@ -19,10 +19,10 @@ import sarsoo.fmframework.parser.Parser;
|
||||
|
||||
public class Getter {
|
||||
public static Album getAlbum() {
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
String albumName = JOptionPane.showInputDialog(null, "Enter Album Name");
|
||||
if (albumName != null) {
|
||||
String albumName = JOptionPane.showInputDialog(null, "Enter Album Name");
|
||||
if (albumName != null) {
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
return Album.getAlbum(albumName, artistName, Reference.getUserName());
|
||||
}
|
||||
}
|
||||
@ -37,6 +37,17 @@ public class Getter {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Track getTrack() {
|
||||
String trackName = JOptionPane.showInputDialog(null, "Enter Track Name");
|
||||
if (trackName != null) {
|
||||
String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name");
|
||||
if (artistName != null) {
|
||||
return Track.getTrack(artistName, trackName, Reference.getUserName());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Track getLastTrack() {
|
||||
|
||||
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
|
||||
@ -90,7 +101,7 @@ public class Getter {
|
||||
FMObjList list = Parser.parseUserTagList(doc);
|
||||
list.setGroupName(tag);
|
||||
|
||||
System.out.println(pages);
|
||||
// System.out.println(pages);
|
||||
if (pages > 1) {
|
||||
int counter;
|
||||
for (counter = 2; counter <= pages; counter++) {
|
||||
@ -118,4 +129,6 @@ public class Getter {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user