layout change, added percentages

This commit is contained in:
aj 2018-04-02 20:15:55 -07:00
parent 837d79cf99
commit 096bf38365
4 changed files with 47 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package sarsoo.fmframework.gui;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -11,6 +12,7 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.net.Network;
@ -55,13 +57,25 @@ public class AlbumView extends JFrame {
buttons.add(rym);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
Font title = new Font("Arial", Font.BOLD, 24);
Font sub = new Font("Arial", Font.PLAIN, 20);
name.setText(album.getName());
name.setHorizontalAlignment(SwingConstants.CENTER);
name.setFont(title);
artist.setText(album.getArtist().getName());
artist.setHorizontalAlignment(SwingConstants.CENTER);
artist.setFont(sub);
listeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
listeners.setHorizontalAlignment(SwingConstants.CENTER);
playCount.setText(numberFormat.format(album.getPlayCount()) + " Scrobbles");
playCount.setHorizontalAlignment(SwingConstants.CENTER);
userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + " Your Scrobbles");
userPlayCount.setHorizontalAlignment(SwingConstants.CENTER);
userPlayCount.setFont(sub);
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
@ -133,9 +147,9 @@ public class AlbumView extends JFrame {
add(name);
add(artist);
add(userPlayCount);
add(listeners);
add(playCount);
add(userPlayCount);
add(trackListPanel);
add(buttons);

View File

@ -21,6 +21,7 @@ import sarsoo.fmframework.music.FMObj;
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;
public class FMObjListView extends JFrame {
@ -33,7 +34,7 @@ public class FMObjListView extends JFrame {
// createMenu();
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
Font font = new Font("Arial", Font.BOLD, 24);
Font font = new Font("Arial", Font.PLAIN, 20);
JPanel headerLabels = new JPanel();
headerLabels.setLayout(new GridLayout(1, 5));
@ -85,26 +86,19 @@ public class FMObjListView extends JFrame {
JPanel info = new JPanel();
info.setLayout(new GridLayout(1, 2));
JLabel totalScrobbles = new JLabel(numberFormat.format(objects.getTotalUserScrobbles()) + " Total Plays");
JLabel totalScrobbles = new JLabel(numberFormat.format(objects.getTotalUserScrobbles()) + " total plays");
totalScrobbles.setHorizontalAlignment(SwingConstants.CENTER);
totalScrobbles.setFont(font);
info.add(totalScrobbles);
int userScrobbles = Getter.getScrobbles(Reference.getUserName());
if (userScrobbles > 0) {
JLabel percent = new JLabel();
percent.setHorizontalAlignment(SwingConstants.CENTER);
double percent = Maths.getPercentListening(objects, Reference.getUserName());
if (percent > 1) {
JLabel percentLabel = new JLabel();
percentLabel.setHorizontalAlignment(SwingConstants.CENTER);
percentLabel.setText(String.format("%.2f%%", percent));
percentLabel.setFont(font);
info.add(percentLabel);
double plays = (double) objects.getTotalUserScrobbles();
double userScrobblesDouble = (double) userScrobbles;
double percentage = (plays / userScrobblesDouble) * 100;
if (percentage > 1) {
percent.setText(String.format("%.2f%%", percentage));
percent.setFont(font);
info.add(percent);
}
}
add(info);

View File

@ -11,6 +11,7 @@ import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.net.Network;
@ -45,10 +46,13 @@ public class FMObjView extends JFrame{
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
name.setText(obj.getName());
name.setHorizontalTextPosition(JLabel.CENTER);
name.setHorizontalAlignment(SwingConstants.CENTER);
listeners.setText(numberFormat.format(obj.getListeners()) + " Listeners");
listeners.setHorizontalAlignment(SwingConstants.CENTER);
playCount.setText(numberFormat.format(obj.getPlayCount()) + " Scrobbles");
playCount.setHorizontalAlignment(SwingConstants.CENTER);
userPlayCount.setText(numberFormat.format(obj.getUserPlayCount()) + " Your Scrobbles");
userPlayCount.setHorizontalAlignment(SwingConstants.CENTER);
viewWiki.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

View File

@ -19,6 +19,22 @@ public class Maths {
return percentage;
}
return 0;
}
public static double getPercentListening(FMObjList objList, String username) {
int userScrobbles = Getter.getScrobbles(Reference.getUserName());
double plays = (double) objList.getTotalUserScrobbles();
if (userScrobbles > 0 && plays > 0) {
double userScrobblesDouble = (double) userScrobbles;
double percentage = (plays / userScrobblesDouble) * 100;
return percentage;
}
return 0;
}
}