abstracted artistlist to fmobj, added self adding of lists to main menu

This commit is contained in:
aj 2018-03-29 00:11:47 -07:00
parent 8014a1e3a6
commit 166aeb9a45
8 changed files with 190 additions and 183 deletions

View File

@ -1,132 +0,0 @@
package sarsoo.fmframework.gui;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.ArtistList;
public class ArtistListView extends JFrame{
// JPanel info = new JPanel();
// JPanel buttons = new JPanel();
// JPanel buttons2 = new JPanel();
// JLabel name = new JLabel();
// JLabel artist = new JLabel();
// JLabel listeners = new JLabel();
// JLabel playCount = new JLabel();
// JLabel userPlayCount = new JLabel();
// JButton open = new JButton("View Online");
// JButton viewArtist = new JButton("View Artist");
// JButton musicBeanz = new JButton("Open MusicBeanz");
// JButton rym = new JButton("Open RYM");
//
public ArtistListView(ArtistList artists, String title) {
super(title);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(artists.size() + 2,0));
// setSize(300, 300);
setResizable(false);
// info.setLayout(new GridLayout());
// buttons.setLayout(new FlowLayout());
// buttons2.setLayout(new FlowLayout());
//
// buttons.add(open);
// buttons.add(viewArtist);
// buttons2.add(musicBeanz);
// buttons2.add(rym);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
JPanel headerLabels = new JPanel();
headerLabels.setLayout(new GridLayout(1, 5));
headerLabels.add(new JLabel("Name"));
headerLabels.add(new JLabel("User Scrobbles"));
headerLabels.add(new JLabel("Total Scrobbles"));
headerLabels.add(new JLabel(""));
headerLabels.add(new JLabel(""));
add(headerLabels);
int counter;
for(counter = 0; counter < artists.size(); counter++) {
Artist artist = artists.get(counter);
JLabel name = new JLabel(artist.getName());
JLabel userPlays = new JLabel(Integer.toString(artist.getUserPlayCount()));
JLabel plays = new JLabel(numberFormat.format(artist.getPlayCount()));
JButton openExternal = new JButton("Open Online");
openExternal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Network.openURL(artist.getUrl());
}
});
JButton openInternal = new JButton("Open Artist");
openInternal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
artist.view();
}
});
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 5));
panel.add(name);
panel.add(userPlays);
panel.add(plays);
panel.add(openInternal);
panel.add(openExternal);
add(panel);
}
JLabel totalScrobbles = new JLabel(numberFormat.format(artists.getTotalUserScrobbles()) + " Total Plays");
add(totalScrobbles);
pack();
// name.setText(album.getName());
// name.setHorizontalTextPosition(JLabel.CENTER);
// artist.setText(album.getArtist().getName());
// listeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
// playCount.setText(numberFormat.format(album.getPlayCount()) + " Scrobbles");
// userPlayCount.setText(numberFormat.format(album.getUserPlayCount()) + " Your Scrobbles");
//
//
// open.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// Network.openURL(album.getUrl());
// }
// });
// viewArtist.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// album.getArtist().view();
// }
// });
// musicBeanz.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// Network.openURL(album.getMusicBeanzURL());;
// }
// });
// rym.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// Network.openURL(album.getRymURL());;
// }
// });
//
// add(name);
// add(artist);
// add(listeners);
// add(playCount);
// add(userPlayCount);
//// add(info);
// add(buttons);
// add(buttons2);
}
}

View File

@ -0,0 +1,78 @@
package sarsoo.fmframework.gui;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.FMObjList;
public class FMObjListView extends JFrame{
public FMObjListView(FMObjList objects, String title) {
super(title);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(objects.size() + 2,0));
setResizable(false);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
JPanel headerLabels = new JPanel();
headerLabels.setLayout(new GridLayout(1, 5));
headerLabels.add(new JLabel("Name"));
headerLabels.add(new JLabel("User Scrobbles"));
headerLabels.add(new JLabel("Total Scrobbles"));
headerLabels.add(new JLabel(""));
headerLabels.add(new JLabel(""));
add(headerLabels);
int counter;
for(counter = 0; counter < objects.size(); counter++) {
FMObj fmObj = objects.get(counter);
JLabel name = new JLabel(fmObj.getName());
int playCountString = fmObj.getUserPlayCount();
JLabel userPlays;
if(playCountString == 0)
userPlays = new JLabel("0");
else
userPlays = new JLabel(Integer.toString(fmObj.getUserPlayCount()));
JLabel plays = new JLabel(numberFormat.format(fmObj.getPlayCount()));
JButton openExternal = new JButton("Open Online");
openExternal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Network.openURL(fmObj.getUrl());
}
});
JButton openInternal = new JButton("Open " + fmObj.getClass().getSimpleName());
openInternal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
fmObj.view();
}
});
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 5));
panel.add(name);
panel.add(userPlays);
panel.add(plays);
panel.add(openInternal);
panel.add(openExternal);
add(panel);
}
JLabel totalScrobbles = new JLabel(numberFormat.format(objects.getTotalUserScrobbles()) + " Total Plays");
add(totalScrobbles);
pack();
}
}

View File

@ -1,11 +1,11 @@
package sarsoo.fmframework.gui;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.JButton;
@ -18,30 +18,29 @@ import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.GetObject;
import sarsoo.fmframework.util.Reference;
public class MainMenu extends JFrame{
public class MainMenu extends JFrame {
JButton getAlbum = new JButton("Get Album");
JButton getArtist = new JButton("Get Artist");
JButton viewTDE = new JButton("View TDE");
JButton viewBPHQ = new JButton("View BPHQ");
JButton viewLastTrack = new JButton("View Last Track");
public MainMenu() {
super("fmframework");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3,2));
setSize(300, 300);
setLayout(new GridLayout(5, 5));
setSize(500, 500);
setResizable(false);
getAlbum.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Album album = GetObject.getAlbum();
if(album != null) {
if (album != null) {
album.view();
}else {
} else {
JOptionPane.showMessageDialog(null, "No Album Found", "Album Error", JOptionPane.ERROR_MESSAGE);
}
}
@ -49,38 +48,39 @@ public class MainMenu extends JFrame{
getArtist.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Artist artist = GetObject.getArtist();
if(artist != null) {
if (artist != null) {
artist.view();
}else {
} else {
JOptionPane.showMessageDialog(null, "No Artist Found", "Artist Error", JOptionPane.ERROR_MESSAGE);
}
}
});
viewTDE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Reference.getTDE().view();
}
});
viewBPHQ.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Reference.getBPHQ().view();
}
});
viewLastTrack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Track track = GetObject.getLastTrack();
if(track != null) {
if (track != null) {
track.view();
}else {
} else {
JOptionPane.showMessageDialog(null, "No Track Found", "Track Error", JOptionPane.ERROR_MESSAGE);
}
}
});
add(viewLastTrack);
add(getAlbum);
add(getArtist);
add(viewTDE);
add(viewBPHQ);
Reference.initGroupsList();
ArrayList<FMObjList> groups = Reference.getGroups();
int counter;
for (counter = 0; counter < groups.size(); counter++) {
FMObjList group = groups.get(counter);
JButton view = new JButton("View " + group.getGroupName());
view.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
group.view();
}
});
add(view);
}
}
}

View File

@ -38,7 +38,7 @@ public class TrackView extends JFrame {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(8, 1));
// setSize(300, 300);
// setResizable(false);
setResizable(false);
buttons.setLayout(new FlowLayout());
buttons2.setLayout(new FlowLayout());

View File

@ -41,7 +41,7 @@ public class Parser {
try {
userPlayCount = Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
} catch (Exception e) {
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled");
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled for " + name);
}
// Node trackListNode = doc.getElementsByTagName("tracks").item(0);
@ -107,7 +107,7 @@ public class Parser {
try {
userPlayCount = Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
} catch (Exception e) {
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled");
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled for " + name);
}
// System.out.println(listeners);
@ -138,7 +138,7 @@ public class Parser {
try {
userPlayCount = Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
} catch (Exception e) {
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled");
System.err.println("Couldn't parse userPlayCount, possibly unscrobbled for " + name);
}
// String albumName =

View File

@ -2,18 +2,19 @@ package sarsoo.fmframework.util;
import java.util.ArrayList;
import sarsoo.fmframework.gui.ArtistListView;
import sarsoo.fmframework.gui.FMObjListView;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.FMObj;
public class ArtistList extends ArrayList<Artist> {
public class FMObjList extends ArrayList<FMObj> {
private String groupName = null;
public ArtistList() {
public FMObjList() {
super();
}
public ArtistList(String name) {
public FMObjList(String name) {
super();
this.groupName = name;
}
@ -28,16 +29,16 @@ public class ArtistList extends ArrayList<Artist> {
}
public void view(String title) {
ArtistListView view = new ArtistListView(this, title);
FMObjListView view = new FMObjListView(this, title);
view.setVisible(true);
}
public void view() {
if(groupName != null) {
ArtistListView view = new ArtistListView(this, getGroupName());
FMObjListView view = new FMObjListView(this, getGroupName());
view.setVisible(true);
}else {
ArtistListView view = new ArtistListView(this, "Artist List View");
FMObjListView view = new FMObjListView(this, "List View");
view.setVisible(true);
}
}

View File

@ -1,5 +1,8 @@
package sarsoo.fmframework.util;
import java.util.ArrayList;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
public class Reference {
@ -13,40 +16,97 @@ public class Reference {
public static void setUserName(String userNameIn) {
userName = userNameIn;
}
public static boolean getIsHeadless() {
return isHeadless;
}
public static void setIsHeadless(boolean headlessIn) {
isHeadless = headlessIn;
}
private static ArrayList<FMObjList> groups = new ArrayList<FMObjList>();
public static void initGroupsList() {
groups.add(getTDE());
groups.add(getBPHQ());
groups.add(getDre());
groups.add(getHopeless());
groups.add(getSaturation());
}
public static FMObjList getSaturation() {
FMObjList saturation = new FMObjList("Saturation");
saturation.add(Album.getAlbum("Saturation", "Brockhampton", Reference.getUserName()));
saturation.add(Album.getAlbum("Saturation II", "Brockhampton", Reference.getUserName()));
saturation.add(Album.getAlbum("Saturation III", "Brockhampton", Reference.getUserName()));
return saturation;
}
public static ArrayList<FMObjList> getGroups() {
return groups;
}
public static ArtistList getTDE() {
ArtistList tde = new ArtistList("TDE");
public static FMObjList getHopeless() {
FMObjList hopeless = new FMObjList("Hopless");
hopeless.add(Artist.getArtist("Circa Survive", Reference.getUserName()));
hopeless.add(Artist.getArtist("Enter Shikari", Reference.getUserName()));
hopeless.add(Artist.getArtist("Have Mercy", Reference.getUserName()));
hopeless.add(Artist.getArtist("Moose Blood", Reference.getUserName()));
// hopeless.add(Artist.getArtist("New Found Glory", Reference.getUserName()));
hopeless.add(Artist.getArtist("Neck Deep", Reference.getUserName()));
hopeless.add(Artist.getArtist("Sum 41", Reference.getUserName()));
// hopeless.add(Artist.getArtist("Taking Back Saturday", Reference.getUserName()));
hopeless.add(Artist.getArtist("Tonight Alive", Reference.getUserName()));
hopeless.add(Artist.getArtist("Trash Boat", Reference.getUserName()));
hopeless.add(Artist.getArtist("The Wonder Years", Reference.getUserName()));
hopeless.add(Artist.getArtist("With Confidence", Reference.getUserName()));
hopeless.add(Artist.getArtist("Trophy Eyes", Reference.getUserName()));
hopeless.add(Artist.getArtist("Dryjacket", Reference.getUserName()));
hopeless.add(Artist.getArtist("Yellowcard", Reference.getUserName()));
return hopeless;
}
public static FMObjList getTDE() {
FMObjList tde = new FMObjList("TDE");
tde.add(Artist.getArtist("Kendrick Lamar", Reference.getUserName()));
tde.add(Artist.getArtist("Jay Rock", Reference.getUserName()));
tde.add(Artist.getArtist("ScHoolboy Q", Reference.getUserName()));
tde.add(Artist.getArtist("Ab-Soul", Reference.getUserName()));
tde.add(Artist.getArtistByMbid("6fc5c0c6-bf05-4b29-bda0-5fa6cc863785", Reference.getUserName())); //Black Hippy
tde.add(Artist.getArtistByMbid("6fc5c0c6-bf05-4b29-bda0-5fa6cc863785", Reference.getUserName())); // Black Hippy
tde.add(Artist.getArtist("Isaiah Rashad", Reference.getUserName()));
tde.add(Artist.getArtist("SZA", Reference.getUserName()));
tde.add(Artist.getArtist("Sir", Reference.getUserName()));
return tde;
}
public static ArtistList getBPHQ() {
ArtistList bphq = new ArtistList("British Post Hardcore Quintet");
public static FMObjList getBPHQ() {
FMObjList bphq = new FMObjList("BPHQ");
bphq.add(Artist.getArtistByMbid("98edd2f1-d136-4c47-ab9b-c31839dd1d98", Reference.getUserName()));
bphq.add(Artist.getArtist("Lower Than Atlantis", Reference.getUserName()));
bphq.add(Artist.getArtist("Mallory Knox", Reference.getUserName()));
bphq.add(Artist.getArtist("Don Broco", Reference.getUserName()));
bphq.add(Artist.getArtist("Moose Blood", Reference.getUserName()));
return bphq;
}
public static FMObjList getDre() {
FMObjList dre = new FMObjList("Dre");
dre.add(Artist.getArtist("N.W.A", Reference.getUserName()));
dre.add(Artist.getArtist("Dr. Dre", Reference.getUserName()));
dre.add(Artist.getArtist("Snoop Dogg", Reference.getUserName()));
dre.add(Artist.getArtist("Eminem", Reference.getUserName()));
return dre;
}
}

View File

@ -4,7 +4,7 @@ import sarsoo.fmframework.music.Artist;
public class ScrobbleSumming {
public static int getTopDawgScrobbles() {
ArtistList tde = new ArtistList();
FMObjList tde = new FMObjList();
// Artist kendrick = Artist.getArtist("Kendrick Lamar", "sarsoo");
// Artist jay = Artist.getArtist("Jay Rock", "sarsoo");