moved ref lists to separate view to reduce api calls on startup

This commit is contained in:
aj 2018-03-29 00:36:36 -07:00
parent 166aeb9a45
commit e289ec60f5
5 changed files with 88 additions and 17 deletions

View File

@ -9,11 +9,16 @@ import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.GetObject;
public class FMObjListView extends JFrame{
@ -22,6 +27,7 @@ public class FMObjListView extends JFrame{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(objects.size() + 2,0));
setResizable(false);
// createMenu();
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
@ -75,4 +81,38 @@ public class FMObjListView extends JFrame{
add(totalScrobbles);
pack();
}
private void createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu editMenu = new JMenu("Edit");
JMenu addMenu = new JMenu("Add");
// create menu items
JMenuItem addAlbum = new JMenuItem("Album");
addAlbum.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Album album = GetObject.getAlbum();
if(album != null) {
}
}
});
JMenuItem addTrack = new JMenuItem("Track");
JMenuItem addArtist = new JMenuItem("Artist");
addMenu.add(addAlbum);
addMenu.add(addTrack);
addMenu.add(addArtist);
editMenu.add(addMenu);
menuBar.add(editMenu);
setJMenuBar(menuBar);
}
}

View File

@ -27,12 +27,13 @@ public class MainMenu extends JFrame {
JButton getAlbum = new JButton("Get Album");
JButton getArtist = new JButton("Get Artist");
JButton viewLastTrack = new JButton("View Last Track");
JButton viewList = new JButton("View List");
public MainMenu() {
super("fmframework");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(5, 5));
setSize(500, 500);
setLayout(new GridLayout(2, 2));
setSize(300, 300);
setResizable(false);
getAlbum.addActionListener(new ActionListener() {
@ -65,22 +66,17 @@ public class MainMenu extends JFrame {
}
}
});
viewList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
RefListsView view = new RefListsView();
view.setVisible(true);
}
});
add(viewLastTrack);
add(viewList);
add(getAlbum);
add(getArtist);
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

@ -0,0 +1,37 @@
package sarsoo.fmframework.gui;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
public class RefListsView extends JFrame {
public RefListsView() {
super("fmframework");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new GridLayout(5, 5));
setSize(500, 500);
setResizable(false);
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

@ -12,7 +12,6 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Network;

View File

@ -3,7 +3,6 @@ package sarsoo.fmframework.util;
import java.util.ArrayList;
import sarsoo.fmframework.gui.FMObjListView;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.FMObj;
public class FMObjList extends ArrayList<FMObj> {