From 6ceb77393c2771c619b84a406c67bcf2dfaf3d08 Mon Sep 17 00:00:00 2001 From: aj Date: Sat, 24 Mar 2018 20:10:47 -0700 Subject: [PATCH] removed fmobjview abstraction from albumview, added gui get for album --- .../src/sarsoo/fmframework/drive/Driver.java | 6 +++--- .../src/sarsoo/fmframework/gui/AlbumView.java | 11 ++++++++--- .../src/sarsoo/fmframework/gui/FMObjView.java | 12 +++++++++--- .../src/sarsoo/fmframework/music/Album.java | 7 +++++++ .../src/sarsoo/fmframework/music/FMObj.java | 7 +++++++ .../src/sarsoo/fmframework/util/GetObject.java | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 fmframework/src/sarsoo/fmframework/util/GetObject.java diff --git a/fmframework/src/sarsoo/fmframework/drive/Driver.java b/fmframework/src/sarsoo/fmframework/drive/Driver.java index 9700436..925608d 100644 --- a/fmframework/src/sarsoo/fmframework/drive/Driver.java +++ b/fmframework/src/sarsoo/fmframework/drive/Driver.java @@ -2,14 +2,14 @@ package sarsoo.fmframework.drive; import sarsoo.fmframework.gui.AlbumView; import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.util.GetObject; public class Driver { public static void main(String[] args) { - System.out.println("Hello World"); - AlbumView view = new AlbumView(Album.getAlbum("Recovery", "Eminem", "sarsoo")); - view.setVisible(true); + GetObject.getAlbum().view(); + } } diff --git a/fmframework/src/sarsoo/fmframework/gui/AlbumView.java b/fmframework/src/sarsoo/fmframework/gui/AlbumView.java index b3d4d60..fac809f 100644 --- a/fmframework/src/sarsoo/fmframework/gui/AlbumView.java +++ b/fmframework/src/sarsoo/fmframework/gui/AlbumView.java @@ -6,6 +6,8 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URI; +import java.text.NumberFormat; +import java.util.Locale; import javax.swing.JButton; import javax.swing.JFrame; @@ -14,6 +16,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.FMObj; public class AlbumView extends JFrame{ JPanel info = new JPanel(); @@ -38,11 +41,13 @@ public class AlbumView extends JFrame{ // info.add(userPlayCount); buttons.add(open); + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + name.setText(album.getName()); name.setHorizontalTextPosition(JLabel.CENTER); - listeners.setText(album.getListeners() + " Listeners"); - playCount.setText(album.getPlayCount() + " Scrobbles"); - userPlayCount.setText(album.getUserPlayCount() + " Your Scrobbles"); + 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() { diff --git a/fmframework/src/sarsoo/fmframework/gui/FMObjView.java b/fmframework/src/sarsoo/fmframework/gui/FMObjView.java index 3ab1fa8..8b6c4f4 100644 --- a/fmframework/src/sarsoo/fmframework/gui/FMObjView.java +++ b/fmframework/src/sarsoo/fmframework/gui/FMObjView.java @@ -6,6 +6,8 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URI; +import java.text.NumberFormat; +import java.util.Locale; import javax.swing.JButton; import javax.swing.JFrame; @@ -37,11 +39,13 @@ public class FMObjView extends JFrame{ // info.add(userPlayCount); buttons.add(open); + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + name.setText(obj.getName()); name.setHorizontalTextPosition(JLabel.CENTER); - listeners.setText(obj.getListeners() + " Listeners"); - playCount.setText(obj.getPlayCount() + " Scrobbles"); - userPlayCount.setText(obj.getUserPlayCount() + " Your Scrobbles"); + listeners.setText(numberFormat.format(obj.getListeners()) + " Listeners"); + playCount.setText(numberFormat.format(obj.getPlayCount()) + " Scrobbles"); + userPlayCount.setText(numberFormat.format(obj.getUserPlayCount()) + " Your Scrobbles"); open.addActionListener(new ActionListener() { @@ -62,4 +66,6 @@ public class FMObjView extends JFrame{ // add(info); add(buttons); } + + } diff --git a/fmframework/src/sarsoo/fmframework/music/Album.java b/fmframework/src/sarsoo/fmframework/music/Album.java index bc7c2fa..fc36b72 100644 --- a/fmframework/src/sarsoo/fmframework/music/Album.java +++ b/fmframework/src/sarsoo/fmframework/music/Album.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.w3c.dom.Document; +import sarsoo.fmframework.gui.AlbumView; import sarsoo.fmframework.net.Network; import sarsoo.fmframework.parser.Parser; @@ -61,4 +62,10 @@ public class Album extends FMObj{ return false; } + + @Override + public void view() { + AlbumView view = new AlbumView(this); + view.setVisible(true); + } } diff --git a/fmframework/src/sarsoo/fmframework/music/FMObj.java b/fmframework/src/sarsoo/fmframework/music/FMObj.java index 04f22fd..2fe153b 100644 --- a/fmframework/src/sarsoo/fmframework/music/FMObj.java +++ b/fmframework/src/sarsoo/fmframework/music/FMObj.java @@ -1,5 +1,7 @@ package sarsoo.fmframework.music; +import sarsoo.fmframework.gui.FMObjView; + public class FMObj { protected String name; @@ -22,6 +24,11 @@ public class FMObj { this.wiki = wiki; } + public void view() { + FMObjView view = new FMObjView(this); + view.setVisible(true); + } + public String toString() { return name; } diff --git a/fmframework/src/sarsoo/fmframework/util/GetObject.java b/fmframework/src/sarsoo/fmframework/util/GetObject.java new file mode 100644 index 0000000..1d3c675 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/util/GetObject.java @@ -0,0 +1,14 @@ +package sarsoo.fmframework.util; + +import javax.swing.JOptionPane; + +import sarsoo.fmframework.music.Album; + +public class GetObject { + public static Album getAlbum() { + String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); + String albumName = JOptionPane.showInputDialog(null, "Enter Album Name"); + return Album.getAlbum(albumName, artistName, "sarsoo"); + } + +}