progressbar added for "normal gui"

Added the progressbar for the normal gui
This commit is contained in:
Maschell 2016-02-06 18:48:21 +01:00
parent 626104209d
commit 9bbb016d97
5 changed files with 63 additions and 21 deletions

Binary file not shown.

View File

@ -86,7 +86,20 @@ public class Progress {
} }
public void finish() { public void finish() {
setCurrent(getTotalOfSingle()); setCurrent(getTotalOfSingle());
}
private boolean inprogress = false;
public void operationStart() {
inprogress = true;
}
public void operationFinish() {
inprogress = false;
}
public boolean isInProgress(){
return inprogress;
} }
} }

View File

@ -22,7 +22,7 @@ public class Starter {
private static String updateCSVPath; private static String updateCSVPath;
public static void main(String[] args) { public static void main(String[] args) {
Logger.log("JNUSTool 0.0.3 - pre alpha - by Maschell"); Logger.log("JNUSTool 0.0.4 - pre alpha - by Maschell");
Logger.log(""); Logger.log("");
try { try {
readConfig(); readConfig();

View File

@ -17,7 +17,12 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import de.mas.jnustool.FEntry; import de.mas.jnustool.FEntry;
import de.mas.jnustool.Logger;
import de.mas.jnustool.NUSTitle; import de.mas.jnustool.NUSTitle;
import de.mas.jnustool.Progress;
import de.mas.jnustool.ProgressUpdateListener;
import javax.swing.JProgressBar;
public class NUSGUI extends JFrame { public class NUSGUI extends JFrame {
@ -47,25 +52,47 @@ public class NUSGUI extends JFrame {
panel.add(qPane); panel.add(qPane);
splitPane.setLeftComponent(panel); splitPane.setLeftComponent(panel);
JPanel panel_1 = new JPanel();
panel.add(panel_1, BorderLayout.SOUTH);
JButton btnNewButton = new JButton("Download"); JButton btnNewButton = new JButton("Download");
panel.add(btnNewButton, BorderLayout.SOUTH); panel_1.add(btnNewButton);
JProgressBar progressBar = new JProgressBar();
panel_1.add(progressBar);
progressBar.setValue(0);
Progress progress = new Progress();
progress.setProgressUpdateListener(new ProgressUpdateListener() {
@Override
public void updatePerformed(Progress p) {
progressBar.setValue((int)p.statusInPercent());
}
});
btnNewButton.addActionListener(new ActionListener() { btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() { public void run() { if(!progress.isInProgress()){
progress.clear();
List<FEntry> list = new ArrayList<>(); progress.operationStart();
TreePath[] paths = cbt.getCheckedPaths(); new Thread(new Runnable() { public void run() {
for (TreePath tp : paths) {
Object obj = tp.getPath()[tp.getPath().length-1]; List<FEntry> list = new ArrayList<>();
if(((DefaultMutableTreeNode)obj).getUserObject() instanceof FEntry){ TreePath[] paths = cbt.getCheckedPaths();
list.add((FEntry) ((DefaultMutableTreeNode)obj).getUserObject()); for (TreePath tp : paths) {
} Object obj = tp.getPath()[tp.getPath().length-1];
} if(((DefaultMutableTreeNode)obj).getUserObject() instanceof FEntry){
list.add((FEntry) ((DefaultMutableTreeNode)obj).getUserObject());
nus.decryptFEntries(list, null); }
}}).start(); }
nus.decryptFEntries(list, progress);
progress.operationFinish();
Logger.messageBox("Finished");
}}).start();
}else{
Logger.messageBox("Operation still in progress, please wait");
}
} }
}); });
JScrollPane outputPane = new JScrollPane(output, JScrollPane outputPane = new JScrollPane(output,

View File

@ -27,6 +27,7 @@ import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import de.mas.jnustool.Logger;
import de.mas.jnustool.Progress; import de.mas.jnustool.Progress;
import de.mas.jnustool.ProgressUpdateListener; import de.mas.jnustool.ProgressUpdateListener;
import de.mas.jnustool.Starter; import de.mas.jnustool.Starter;
@ -154,20 +155,21 @@ public class UpdateChooser extends JPanel {
btnDownloadMeta.addActionListener(new ActionListener() { btnDownloadMeta.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(progressBar_1.getValue() == 0 || progressBar_1.getValue() == 100){ if(!progress.isInProgress()){
progressBar_1.setValue(1);
progress.clear(); progress.clear();
progress.operationStart();
new Thread(new Runnable(){ new Thread(new Runnable(){
@Override @Override
public void run() { public void run() {
Starter.downloadMeta(output_,progress); Starter.downloadMeta(output_,progress);
JOptionPane.showMessageDialog(window, "Finished"); progress.operationFinish();
Logger.messageBox("Finished");
} }
}).start(); }).start();
}else{ }else{
JOptionPane.showMessageDialog(window, "Operation still in progress, please wait"); Logger.messageBox("Operation still in progress, please wait");
} }
} }
}); });