Skip to content

Commit

Permalink
V6
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Mar 29, 2015
1 parent c9058bb commit 89cec0b
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 213 deletions.
15 changes: 9 additions & 6 deletions src/latmod/cursegraph/Curse.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ public static class Project implements Comparable<Project>

@Expose public Integer typeID;
@Expose public String title;
@Expose public String game;
@Expose public String category;
@Expose public String url;
@Expose public String thumbnail;
@Expose public String[] authors;
@Expose public Map<String, Integer> downloads;
@Expose public Integer favorites;
@Expose public Integer likes;
@Expose public String updated_at;
@Expose public String created_at;
@Expose public String project_url;
@Expose public String release_type;
@Expose public String license;
@Expose public Version download;
@Expose public Map<String, Version[]> versions;

public boolean checkValid()
{
if(title == null) return false;
if(url == null) return false;
if(download == null) return false;
if(versions == null) return false;
return true;
}

private int totalDownloads = -1;

public String toString()
Expand Down
241 changes: 199 additions & 42 deletions src/latmod/cursegraph/CurseGraphFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;

Expand All @@ -10,129 +11,262 @@ public class CurseGraphFrame extends JFrame
private static final long serialVersionUID = 1L;
public static final CurseGraphFrame inst = new CurseGraphFrame();

public final JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
public final JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);

public CurseGraphFrame()
{
setTitle("CurseGraph v" + Main.version);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
add(pane);
this.setSize(700, 500);
pane.setSize(700, 500);
setResizable(true);
refresh();
pack();
setLocationRelativeTo(null);

setVisible(!Main.config.startMinimized.booleanValue());
setIconImage(Main.imageReady);
}

public void refresh()
{
pane.removeAll();
pane.setTabLayoutPolicy(Main.config.scrollTabs.booleanValue() ? JTabbedPane.SCROLL_TAB_LAYOUT : JTabbedPane.WRAP_TAB_LAYOUT);

ArrayList<String> componentsAdded = new ArrayList<String>();
componentsAdded.add("Settings");

JPanel settingsPanel = new JPanel(false);

//settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.Y_AXIS));
BorderLayout layout = new BorderLayout();
layout.setHgap(40);
layout.setVgap(50);
GridLayout layout = new GridLayout();
layout.setColumns(1);
layout.setRows(0);
layout.setVgap(5);
settingsPanel.setLayout(layout);

{
JButton b = new JButton("Add");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String types[] = Curse.Type.getAllNames();
String type0 = (String)JOptionPane.showInputDialog(null, "Select the mod:", "Add new Project", JOptionPane.PLAIN_MESSAGE, null, types, Curse.Type.MOD.name);
if(type0 == null || type0.isEmpty()) return;
Curse.Type t = Curse.Type.getFromName(type0);

String input = JOptionPane.showInputDialog("Enter " + t.name + "'s ProjectID here:", "");
if(input != null && !input.trim().isEmpty())
{
Projects.add(t, input.trim(), false);
Main.refresh();
}
}
catch(Exception ex)
{ ex.printStackTrace(); }
}
});

settingsPanel.add(b);
}

{
JButton b = new JButton("Refresh");
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ try { refresh(); Graph.logData(); } catch(Exception ex)
{ try { Main.refresh(); Graph.logData(); } catch(Exception ex)
{ ex.printStackTrace(); } }
});

settingsPanel.add(b, BorderLayout.LINE_END);
settingsPanel.add(b);
}

{
JButton b = new JButton("Set refresh interval");
b.setAlignmentX(Component.CENTER_ALIGNMENT);
JButton b = new JButton("Set graph type");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String input = JOptionPane.showInputDialog("Set refresh minutes:", "" + Main.config.refreshMinutes);
if(input != null && !input.isEmpty())
try
{
try
int times[] = { -1, 1, 24, 24 * 7, 24 * 30 };
String types[] = { "None", "Hour", "Day", "Week", "Month" };

String type0 = (String)JOptionPane.showInputDialog(null, "Select graph type:", "Graph type", JOptionPane.PLAIN_MESSAGE, null, types, types[0]);
if(type0 == null || type0.isEmpty()) return;

for(int i = 0; i < types.length; i++)
{
int i = Integer.parseInt(input);
Main.config.refreshMinutes = Math.max(1, i);
Main.config.save();

Graph.checker.start();
if(type0.equals(types[i]))
{
Main.config.graphLimit = times[i];
Main.refresh();
}
}
catch(Exception ex)
{ Main.error("Invalid number!"); }
}
catch(Exception ex)
{ ex.printStackTrace(); }
}
});

settingsPanel.add(b, BorderLayout.LINE_START);
//settingsPanel.add(b);
}

{
JButton b = new JButton("Add");
b.setAlignmentX(Component.CENTER_ALIGNMENT);
final boolean scrollTabs = Main.config.scrollTabs.booleanValue();
final JButton b = new JButton("Scrolling Tabs " + (scrollTabs ? "[ON]" : "[OFF]"));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
Main.config.scrollTabs = !Main.config.scrollTabs.booleanValue();
Main.config.save();
refresh();
}
});

settingsPanel.add(b);
}

{
JButton b = new JButton("Set refresh interval");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String input = JOptionPane.showInputDialog("Set refresh minutes:", "" + Main.config.refreshMinutes);
if(input != null && !input.isEmpty())
{
String types[] = Curse.Type.getAllNames();
String type0 = (String)JOptionPane.showInputDialog(null, "Select the mod:", "Add new Project", JOptionPane.PLAIN_MESSAGE, null, types, Curse.Type.MOD.name);
if(type0 == null || type0.isEmpty()) return;
Curse.Type t = Curse.Type.getFromName(type0);

String input = JOptionPane.showInputDialog("Enter " + t.name + "'s ProjectID here:", "");
if(input != null && !input.isEmpty())
try
{
Projects.add(t, input, false);
refresh();
int i = Integer.parseInt(input);
Main.config.refreshMinutes = Math.max(1, i);
Main.config.save();

Graph.checker.start();
}
catch(Exception ex)
{ Main.error("Invalid number!", false); }
}
catch(Exception ex)
{ ex.printStackTrace(); }
}
});

settingsPanel.add(b, BorderLayout.CENTER);
settingsPanel.add(b);
}

{
JButton b = new JButton("Open data folder");
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ try { Desktop.getDesktop().open(Main.folder); }
catch(Exception ex) { ex.printStackTrace(); } }
});

settingsPanel.add(b, BorderLayout.PAGE_START);
settingsPanel.add(b);
}

/*
{
PopupMenu m1 = new PopupMenu("Clear older than...");
{
MenuItem m2 = new MenuItem("Month");
m2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ Graph.clearData(getH(24 * 30)); }
});
m1.add(m2);
}
{
MenuItem m2 = new MenuItem("Week");
m2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ Graph.clearData(getH(24 * 7)); }
});
m1.add(m2);
}
{
MenuItem m2 = new MenuItem("Day");
m2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ Graph.clearData(getH(24)); }
});
m1.add(m2);
}
{
MenuItem m2 = new MenuItem("Hour");
m2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ Graph.clearData(getH(1)); }
});
m1.add(m2);
}
{
MenuItem m2 = new MenuItem("X Minues");
m2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String input = JOptionPane.showInputDialog("X Minutes:", "10");
if(input != null && !input.isEmpty())
{
try
{
int i = Integer.parseInt(input);
i = Math.max(1, i);
Graph.clearData(i * 60000L);
}
catch(Exception ex)
{ error("Invalid number!", false); }
}
}
});
m1.add(m2);
}
menu.add(m1);
}
*/
{
JButton b = new JButton("Exit");
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ System.exit(0); }
});

settingsPanel.add(b, BorderLayout.PAGE_END);
settingsPanel.add(b);
}

addPanel("Settings", settingsPanel);

for(final Curse.Project p : Projects.list)
Curse.Project[] projectsList = Projects.list.toArray(new Curse.Project[0]);
Arrays.sort(projectsList);

for(final Curse.Project p : projectsList)
{
final JPanel panel = new JPanel(false);

Expand Down Expand Up @@ -247,7 +381,7 @@ public void actionPerformed(ActionEvent e)
{
Projects.list.remove(p);
Projects.save();
refresh();
Main.refresh();
}
}
});
Expand All @@ -259,9 +393,32 @@ public void actionPerformed(ActionEvent e)

panel.add(new JCurseGraph(panel, p));
addPanel(p.title, panel);
componentsAdded.add(p.title);
}

JPopupMenu menuAll = new JPopupMenu();

for(int i = 0; i < componentsAdded.size(); i++)
{
final JMenuItem item = new JMenuItem(componentsAdded.get(i));
final int index = i;
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
pane.setSelectedIndex(index);
}
});

menuAll.add(item);
}

pane.setComponentPopupMenu(menuAll);
}

//private static long getH(int i)
//{ return 1000L * 60L * 60L * i; }

public void addPanel(String title, JComponent c)
{ pane.addTab(title, null, c, title); }
}
Loading

0 comments on commit 89cec0b

Please sign in to comment.