removed tracklist, focused album object

This commit is contained in:
aj 2018-03-29 03:19:55 -07:00
parent 65884aa7e0
commit dcf07fa2f7
4 changed files with 195 additions and 102 deletions

View File

@ -5,6 +5,7 @@ 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;
@ -13,11 +14,14 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Network;
public class AlbumView extends JFrame {
JPanel buttons = new JPanel();
JPanel buttons2 = new JPanel();
JPanel trackListPanel = new JPanel();
JLabel name = new JLabel();
JLabel artist = new JLabel();
@ -33,17 +37,19 @@ public class AlbumView extends JFrame {
public AlbumView(Album album) {
super(album.getName());
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(7,0));
setLayout(new GridLayout(8, 1));
setSize(300, 300);
setResizable(false);
buttons.setLayout(new FlowLayout());
buttons2.setLayout(new FlowLayout());
// System.out.println(album.getName());
// if (album.getTrackList() != null)
// buttons2.setLayout(new GridLayout(album.getTrackList().size(), 1));
buttons.add(open);
buttons.add(viewArtist);
if(album.getMbid() != null)
if (album.getMbid() != null)
buttons2.add(musicBrainz);
buttons2.add(rym);
@ -56,7 +62,6 @@ public class AlbumView extends JFrame {
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());
@ -69,21 +74,64 @@ public class AlbumView extends JFrame {
});
musicBrainz.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Network.openURL(album.getMusicBrainzURL());;
Network.openURL(album.getMusicBrainzURL());
;
}
});
rym.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Network.openURL(album.getRymURL());;
Network.openURL(album.getRymURL());
;
}
});
// if (album.getTrackList() != null) {
// int counter;
// ArrayList<Track> trackList = album.getTrackList();
// for (counter = 0; counter < trackList.size(); counter++) {
// Track track = trackList.get(counter);
// JLabel name = new JLabel(track.getName());
//
// int playCountString = track.getUserPlayCount();
//
// JLabel userPlays;
// if (playCountString == 0)
// userPlays = new JLabel("0");
// else
// userPlays = new JLabel(Integer.toString(track.getUserPlayCount()));
//
// JLabel plays = new JLabel(numberFormat.format(track.getPlayCount()));
// JButton openExternal = new JButton("Open Online");
// openExternal.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// Network.openURL(track.getUrl());
// }
// });
// JButton openInternal = new JButton("Open " + track.getClass().getSimpleName());
// openInternal.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent arg0) {
// track.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);
//
// trackListPanel.add(panel);
// }
// }
add(name);
add(artist);
add(listeners);
add(playCount);
add(userPlayCount);
add(trackListPanel);
add(buttons);
add(buttons2);
}

View File

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

View File

@ -12,7 +12,7 @@ import sarsoo.fmframework.util.Reference;
public class Album extends FMObj{
protected Artist artist;
protected ArrayList<Tag> tagList;
protected ArrayList<Track> trackList;
// protected ArrayList<Track> trackList;
public Album(String name, String artist) {
super(name, null, null, 0, 0, 0, null);
@ -35,14 +35,18 @@ public class Album extends FMObj{
return album;
}
public Track getTrack(int track) {
return trackList.get(track);
}
public ArrayList<Track> getTrackList(){
return trackList;
}
// public Track getTrack(int track) {
// return trackList.get(track);
// }
//
// public ArrayList<Track> getTrackList(){
// return trackList;
// }
//
// public void addTrack(Track track) {
// trackList.add(track);
// }
//
public ArrayList<Tag> getTags(){
return tagList;
}

View File

@ -12,6 +12,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@ -26,79 +27,119 @@ public class Parser {
public static Album parseAlbum(Document doc) {
// try {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
String artist = doc.getElementsByTagName("artist").item(0).getTextContent();
String mbid = null;
// try {
// mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
// } catch (NullPointerException e) {
// System.err.println("Null Mbid for " + name);
// }
// System.out.println(doc.getDocumentElement());
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
String artist = doc.getElementsByTagName("artist").item(0).getTextContent();
String mbid = null;
// try {
// mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
// } catch (NullPointerException e) {
// System.err.println("Null Mbid for " + name);
// }
NodeList mbidNodeList = doc.getElementsByTagName("mbid");
if (mbidNodeList.item(0) != null) {
mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
NodeList mbidNodeList = doc.getElementsByTagName("mbid");
if (mbidNodeList.item(0) != null) {
mbid = doc.getElementsByTagName("mbid").item(0).getTextContent();
}
String url = doc.getElementsByTagName("url").item(0).getTextContent();
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
int userPlayCount = 0;
// try {
// userPlayCount =
// Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
// } catch (Exception e) {
// System.err.println("Couldn't parse userPlayCount, possibly unscrobbled for "
// + name);
// }
NodeList userPlayCountNodeList = doc.getElementsByTagName("userplaycount");
if (userPlayCountNodeList.item(0) != null) {
userPlayCount = Integer.parseInt(userPlayCountNodeList.item(0).getTextContent());
}
Artist artistObj = Artist.getArtist(artist, Reference.getUserName());
Wiki wiki = new Wiki();
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
// NodeList trackListNode = doc.getElementsByTagName("tracks");
//
// NodeList child1 = doc.getElementsByTagName("tracks");
// Node sibling = trackListNode.item(0).getFirstChild();
// int counter;
// // for(counter = 0; counter < 2; counter++) {
// while (sibling != trackListNode.item(0).getLastChild()) {
// while (!(sibling instanceof Element) && sibling != null) {
// sibling = sibling.getNextSibling();
// }
// // NamedNodeMap attributes = sibling.getAttributes();
//
// // int trackNumber =
// // Integer.parseInt(attributes.getNamedItem("rank").getNodeValue());
// NodeList trackNodeList = sibling.getChildNodes();
// String trackName = trackNodeList.item(0).getTextContent();
// String artistName = trackNodeList.item(8).getFirstChild().getTextContent();
//
// Track track = Track.getTrack(trackName, artistName, Reference.getUserName());
// track.setAlbum(album);
// System.out.println(track.getName());
//
// album.addTrack(track);
//
// sibling = sibling.getNextSibling();
//
// }
// while (!(sibling instanceof Element) && sibling != null) {
// sibling = sibling.getNextSibling();
// }
// NodeList list = sibling.getChildNodes();
// list.item(0);
// System.out.println(list.item(0));
// System.out.println(trackListNode.item(0).getTextContent());
// NodeList trackNodeList = trackListNode.getChildNodes();
// if (trackListNode != null) {
// int counter = 0;
// while (trackNodeList.item(counter) != null) {
// Node track = trackNodeList.item(counter);
// // System.out.println(track.getTextContent());
// String trackName = track.getFirstChild().getTextContent();
// String trackUrl =
// track.getFirstChild().getNextSibling().getNextSibling().getTextContent();
// // String trackDuration =
// track.getFirstChild().getNextSibling().getNextSibling().getNextSibling().getNextSibling()
// .getTextContent();
// int trackNumber =
// Integer.parseInt(track.getAttributes().getNamedItem("rank").getNodeValue());
// // String trackName =
// // trackListNode.getFirstChild().getFirstChild().getTextContent();
// // String trackUrl = trackListNode.getNextSibling().getTextContent();
// System.out.println(trackUrl);
// counter++;
// }
// }
// Node wikiNode = doc.getElementsByTagName("wiki").item(0);
// String published = wikiNode.getFirstChild().getTextContent();
// String summary = wikiNode.getFirstChild().getNextSibling().getTextContent();
// String content =
// wikiNode.getFirstChild().getNextSibling().getNextSibling().getTextContent();
// System.out.println(published);
// System.out.println(summary);
// System.out.println(content);
return album;
// } catch (NullPointerException e) {
// System.err.println("Could Not Parse Album");
// return null;
// }
}
String url = doc.getElementsByTagName("url").item(0).getTextContent();
int listeners = Integer.parseInt(doc.getElementsByTagName("listeners").item(0).getTextContent());
int playCount = Integer.parseInt(doc.getElementsByTagName("playcount").item(0).getTextContent());
int userPlayCount = 0;
// try {
// userPlayCount =
// Integer.parseInt(doc.getElementsByTagName("userplaycount").item(0).getTextContent());
// } catch (Exception e) {
// System.err.println("Couldn't parse userPlayCount, possibly unscrobbled for "
// + name);
// }
NodeList userPlayCountNodeList = doc.getElementsByTagName("userplaycount");
if (userPlayCountNodeList.item(0) != null) {
userPlayCount = Integer.parseInt(userPlayCountNodeList.item(0).getTextContent());
}
// Node trackListNode = doc.getElementsByTagName("tracks").item(0);
// NodeList trackNodeList = trackListNode.getChildNodes();
// if (trackListNode != null) {
// int counter = 0;
// while (trackNodeList.item(counter) != null) {
// Node track = trackNodeList.item(counter);
// //System.out.println(track.getTextContent());
// String trackName = track.getFirstChild().getTextContent();
// String trackUrl =
// track.getFirstChild().getNextSibling().getNextSibling().getTextContent();
// //String trackDuration =
// track.getFirstChild().getNextSibling().getNextSibling().getNextSibling().getNextSibling().getTextContent();
// int trackNumber =
// Integer.parseInt(track.getAttributes().getNamedItem("rank").getNodeValue());
// // String trackName =
// // trackListNode.getFirstChild().getFirstChild().getTextContent();
// // String trackUrl = trackListNode.getNextSibling().getTextContent();
// System.out.println(trackUrl);
// counter++;
// }
// }
// Node wikiNode = doc.getElementsByTagName("wiki").item(0);
// String published = wikiNode.getFirstChild().getTextContent();
// String summary = wikiNode.getFirstChild().getNextSibling().getTextContent();
// String content =
// wikiNode.getFirstChild().getNextSibling().getNextSibling().getTextContent();
// System.out.println(published);
// System.out.println(summary);
// System.out.println(content);
Artist artistObj = Artist.getArtist(artist, Reference.getUserName());
Wiki wiki = new Wiki();
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
return album;
// } catch (NullPointerException e) {
// System.err.println("Could Not Parse Album");
// return null;
// }
return null;
}
@ -215,20 +256,20 @@ public class Parser {
public static Track parseLastTrack(Document doc) {
// try {
// System.out.println(doc.getDocumentElement().getAttribute("status"));
// System.out.println(doc.getDocumentElement().getAttribute("status"));
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
// System.out.println(name);
// System.out.println(name);
String artistName = doc.getElementsByTagName("artist").item(0).getTextContent();
String albumName = doc.getElementsByTagName("album").item(0).getTextContent();
System.out.println(albumName);
Track track = Track.getTrack(name, artistName, Reference.getUserName());
// Album album = Album.getAlbum(albumName, artistName, Reference.getUserName());
Album album = Album.getAlbum(albumName, artistName, Reference.getUserName());
// if (album.getName() != null)
// track.setAlbum(album);
track.setAlbum(album);
return track;
// } catch (NullPointerException e) {