From b0ea458555265541e57e8722a31e20a5137068b0 Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 3 Apr 2018 15:24:24 -0700 Subject: [PATCH] changed list view layout, fixed? bad requests changed request property --- .../sarsoo/fmframework/gui/FMObjListView.java | 62 ++++++++++++++----- .../sarsoo/fmframework/gui/RefListsView.java | 20 ++++-- .../src/sarsoo/fmframework/gui/TrackView.java | 17 ++++- .../src/sarsoo/fmframework/net/Network.java | 2 +- .../sarsoo/fmframework/util/Reference.java | 10 +++ 5 files changed, 85 insertions(+), 26 deletions(-) diff --git a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java index c603630..875ecd8 100644 --- a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java +++ b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java @@ -4,6 +4,8 @@ import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.text.NumberFormat; import java.util.Locale; @@ -35,21 +37,44 @@ public class FMObjListView extends JFrame { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); Font font = new Font("Arial", Font.PLAIN, 20); - + Font header = new Font("Arial", Font.BOLD, 16); + 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.setFont(header); + headerLabels.setLayout(new GridLayout(1, 4)); + + + JLabel headerName = new JLabel("name"); + headerName.setHorizontalAlignment(SwingConstants.CENTER); + headerName.setFont(header); + + JLabel headerUser = new JLabel("user"); + headerUser.setHorizontalAlignment(SwingConstants.CENTER); + headerUser.setFont(header); + + JLabel headerTotal = new JLabel("total"); + headerTotal.setHorizontalAlignment(SwingConstants.CENTER); + headerTotal.setFont(header); + + headerLabels.add(headerName); + headerLabels.add(headerUser); + headerLabels.add(headerTotal); 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()); + JLabel artistName = new JLabel(fmObj.getName()); + artistName.setHorizontalAlignment(SwingConstants.CENTER); + artistName.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + fmObj.view(); + } + }); int playCountString = fmObj.getUserPlayCount(); @@ -58,26 +83,29 @@ public class FMObjListView extends JFrame { userPlays = new JLabel("0"); else userPlays = new JLabel(Integer.toString(fmObj.getUserPlayCount())); - + userPlays.setHorizontalAlignment(SwingConstants.CENTER); + JLabel plays = new JLabel(numberFormat.format(fmObj.getPlayCount())); + plays.setHorizontalAlignment(SwingConstants.CENTER); + 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(); - } - }); +// 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.setLayout(new GridLayout(1, 4)); + panel.add(artistName); panel.add(userPlays); panel.add(plays); - panel.add(openInternal); +// panel.add(openInternal); panel.add(openExternal); add(panel); diff --git a/fmframework/src/sarsoo/fmframework/gui/RefListsView.java b/fmframework/src/sarsoo/fmframework/gui/RefListsView.java index a97f09a..dfe51ae 100644 --- a/fmframework/src/sarsoo/fmframework/gui/RefListsView.java +++ b/fmframework/src/sarsoo/fmframework/gui/RefListsView.java @@ -34,7 +34,7 @@ public class RefListsView extends JFrame { // add(view); // } - JButton viewTDE = new JButton("View TDE"); + JButton viewTDE = new JButton("TDE"); viewTDE.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getTDE().view(); @@ -42,7 +42,7 @@ public class RefListsView extends JFrame { }); add(viewTDE); - JButton viewBPHQ = new JButton("View BPHQ"); + JButton viewBPHQ = new JButton("BPHQ"); viewBPHQ.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getBPHQ().view(); @@ -50,33 +50,41 @@ public class RefListsView extends JFrame { }); add(viewBPHQ); - JButton viewDre = new JButton("View Dre"); + JButton viewDre = new JButton("Dre"); viewDre.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getDre().view(); } }); add(viewDre); - JButton viewWu = new JButton("View Wu"); + JButton viewWu = new JButton("Wu"); viewWu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getWu().view(); } }); add(viewWu); - JButton viewHopeless = new JButton("View Hopeless"); + JButton viewHopeless = new JButton("Hopeless"); viewHopeless.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getHopeless().view(); } }); add(viewHopeless); - JButton viewSaturation = new JButton("View Saturation"); + JButton viewSaturation = new JButton("Saturation"); viewSaturation.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Reference.getSaturation().view(); } }); add(viewSaturation); + + JButton viewEmoTrio = new JButton("Emo Trio"); + viewEmoTrio.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + Reference.getEmoTrio().view(); + } + }); + add(viewEmoTrio); } } diff --git a/fmframework/src/sarsoo/fmframework/gui/TrackView.java b/fmframework/src/sarsoo/fmframework/gui/TrackView.java index a4ba91f..f24a736 100644 --- a/fmframework/src/sarsoo/fmframework/gui/TrackView.java +++ b/fmframework/src/sarsoo/fmframework/gui/TrackView.java @@ -51,7 +51,7 @@ public class TrackView extends JFrame { setLayout(new GridLayout(6, 1)); } // setSize(300, 300); - setResizable(false); + setResizable(false); // info.setLayout(new GridLayout(6,1)); // nameInfo.setLayout(new GridLayout(3,1)); @@ -100,7 +100,7 @@ public class TrackView extends JFrame { playCount.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles"); playCount.setHorizontalAlignment(SwingConstants.CENTER); userPlayCount.setText(numberFormat.format(track.getUserPlayCount()) - + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName()))); + + String.format(" Scrobbles (%.3f%%)", Maths.getPercentListening(track, Reference.getUserName()))); userPlayCount.setHorizontalAlignment(SwingConstants.CENTER); userPlayCount.setFont(sub); @@ -115,6 +115,19 @@ public class TrackView extends JFrame { } }); + if (track.getUserPlayCount() > 0) { + userPlayCount.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + String namePlus = track.getName().replaceAll(" ", "+"); + String artistPlus = track.getArtist().getName().replaceAll(" ", "+"); + String url = String.format("https://www.last.fm/user/%s/library/music/%s/_/%s", + Reference.getUserName(), artistPlus, namePlus); + Network.openURL(url); + } + }); + } + artist.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { diff --git a/fmframework/src/sarsoo/fmframework/net/Network.java b/fmframework/src/sarsoo/fmframework/net/Network.java index 5bf17c4..9864bcb 100644 --- a/fmframework/src/sarsoo/fmframework/net/Network.java +++ b/fmframework/src/sarsoo/fmframework/net/Network.java @@ -24,7 +24,7 @@ public class Network { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); - conn.setRequestProperty("Accept", "text/xml"); + conn.setRequestProperty("Accept", "application/xml"); conn.setRequestProperty("User-Agent", "fmframework/1.0"); if (conn.getResponseCode() != 200) { diff --git a/fmframework/src/sarsoo/fmframework/util/Reference.java b/fmframework/src/sarsoo/fmframework/util/Reference.java index 00dbeb2..f34e151 100644 --- a/fmframework/src/sarsoo/fmframework/util/Reference.java +++ b/fmframework/src/sarsoo/fmframework/util/Reference.java @@ -123,4 +123,14 @@ public class Reference { return wu; } + public static FMObjList getEmoTrio() { + FMObjList emoTrio = new FMObjList("Classic Emo Trio"); + + emoTrio.add(Artist.getArtist("My Chemical Romance", Reference.getUserName())); + emoTrio.add(Artist.getArtist("Fall Out Boy", Reference.getUserName())); + emoTrio.add(Artist.getArtist("Panic! at the Disco", Reference.getUserName())); + + return emoTrio; + } + }