2019-04-15 11:45:15 +02:00
package de.mas.wiiu.jnus.jnustool.gui ;
2016-02-02 19:38:53 +01:00
2016-02-01 23:57:01 +01:00
import java.awt.BorderLayout ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.util.ArrayList ;
import java.util.List ;
import javax.swing.JButton ;
import javax.swing.JFrame ;
2016-02-05 16:40:26 +01:00
import javax.swing.JPanel ;
2016-03-02 19:48:04 +01:00
import javax.swing.JProgressBar ;
2016-02-01 23:57:01 +01:00
import javax.swing.JScrollPane ;
2016-02-05 16:40:26 +01:00
import javax.swing.JSplitPane ;
import javax.swing.JTextArea ;
import javax.swing.ScrollPaneConstants ;
2016-02-01 23:57:01 +01:00
import javax.swing.tree.DefaultMutableTreeNode ;
import javax.swing.tree.TreePath ;
2019-04-15 11:45:15 +02:00
import de.mas.wiiu.jnus.jnustool.FEntry ;
import de.mas.wiiu.jnus.jnustool.Logger ;
import de.mas.wiiu.jnus.jnustool.NUSTitle ;
import de.mas.wiiu.jnus.jnustool.Progress ;
import de.mas.wiiu.jnus.jnustool.ProgressUpdateListener ;
2016-02-06 18:48:21 +01:00
2016-02-01 23:57:01 +01:00
public class NUSGUI extends JFrame {
private static final long serialVersionUID = 4648172894076113183L ;
2016-02-05 16:40:26 +01:00
public static JTextArea output = new JTextArea ( 1 , 10 ) ;
2016-02-06 18:25:08 +01:00
public NUSGUI ( NUSTitle nus ) {
2016-02-01 23:57:01 +01:00
super ( ) ;
2016-02-05 16:40:26 +01:00
this . setResizable ( false ) ;
2016-10-23 14:40:15 +02:00
if ( nus . getFst ( ) = = null ) {
Logger . log ( " Error: Can't create GUI window without the FST. Please provide a key/title.key. To download the encrpyted files use the -dlEncrypted argument " ) ;
System . exit ( - 1 ) ;
}
2016-02-05 16:40:26 +01:00
setSize ( 600 , 768 ) ;
2016-08-24 21:27:35 +02:00
setTitle ( String . format ( " %016X " , nus . getTitleID ( ) ) ) ;
2016-02-05 16:40:26 +01:00
getContentPane ( ) . setLayout ( null ) ;
JSplitPane splitPane = new JSplitPane ( ) ;
splitPane . setBounds ( 0 , 0 , 594 , 726 ) ;
splitPane . setOrientation ( JSplitPane . VERTICAL_SPLIT ) ;
getContentPane ( ) . add ( splitPane , BorderLayout . NORTH ) ;
JScrollPane qPane = new JScrollPane ( JScrollPane . VERTICAL_SCROLLBAR_AS_NEEDED ,
JScrollPane . HORIZONTAL_SCROLLBAR_NEVER ) ;
2016-02-01 23:57:01 +01:00
2016-02-05 16:40:26 +01:00
this . getContentPane ( ) . add ( splitPane ) ;
2016-10-23 14:40:15 +02:00
2016-02-01 23:57:01 +01:00
final JCheckBoxTree cbt = new JCheckBoxTree ( nus ) ;
2016-02-05 16:40:26 +01:00
qPane . setViewportView ( cbt ) ;
2016-02-01 23:57:01 +01:00
2016-02-05 16:40:26 +01:00
JPanel panel = new JPanel ( ) ;
panel . setLayout ( new BorderLayout ( 0 , 0 ) ) ;
panel . add ( qPane ) ;
splitPane . setLeftComponent ( panel ) ;
2016-02-01 23:57:01 +01:00
2016-02-06 18:48:21 +01:00
JPanel panel_1 = new JPanel ( ) ;
panel . add ( panel_1 , BorderLayout . SOUTH ) ;
2016-02-01 23:57:01 +01:00
JButton btnNewButton = new JButton ( " Download " ) ;
2016-02-06 18:48:21 +01:00
panel_1 . add ( btnNewButton ) ;
2016-10-23 06:28:16 +02:00
final JProgressBar progressBar = new JProgressBar ( ) ;
2016-02-06 18:48:21 +01:00
panel_1 . add ( progressBar ) ;
progressBar . setValue ( 0 ) ;
2016-10-23 06:28:16 +02:00
final Progress progress = new Progress ( ) ;
2016-02-06 18:48:21 +01:00
progress . setProgressUpdateListener ( new ProgressUpdateListener ( ) {
@Override
public void updatePerformed ( Progress p ) {
progressBar . setValue ( ( int ) p . statusInPercent ( ) ) ;
}
} ) ;
2016-10-23 06:28:16 +02:00
final NUSTitle nuscpy = nus ;
2016-02-01 23:57:01 +01:00
btnNewButton . addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent e ) {
2016-02-06 18:48:21 +01:00
if ( ! progress . isInProgress ( ) ) {
progress . clear ( ) ;
progress . operationStart ( ) ;
new Thread ( new Runnable ( ) { public void run ( ) {
List < FEntry > list = new ArrayList < > ( ) ;
TreePath [ ] paths = cbt . getCheckedPaths ( ) ;
for ( TreePath tp : paths ) {
Object obj = tp . getPath ( ) [ tp . getPath ( ) . length - 1 ] ;
if ( ( ( DefaultMutableTreeNode ) obj ) . getUserObject ( ) instanceof FEntry ) {
list . add ( ( FEntry ) ( ( DefaultMutableTreeNode ) obj ) . getUserObject ( ) ) ;
}
}
2016-10-23 06:28:16 +02:00
nuscpy . decryptFEntries ( list , progress ) ;
2016-02-06 18:48:21 +01:00
progress . operationFinish ( ) ;
Logger . messageBox ( " Finished " ) ;
} } ) . start ( ) ;
} else {
Logger . messageBox ( " Operation still in progress, please wait " ) ;
}
2016-02-01 23:57:01 +01:00
}
} ) ;
2016-02-05 16:40:26 +01:00
JScrollPane outputPane = new JScrollPane ( output ,
ScrollPaneConstants . VERTICAL_SCROLLBAR_ALWAYS ,
ScrollPaneConstants . HORIZONTAL_SCROLLBAR_AS_NEEDED ) ;
2016-02-01 23:57:01 +01:00
2016-02-05 16:40:26 +01:00
splitPane . setRightComponent ( outputPane ) ;
splitPane . setDividerLocation ( 0 . 7 ) ;
splitPane . setResizeWeight ( 0 . 7 ) ;
splitPane . setEnabled ( false ) ;
2016-02-01 23:57:01 +01:00
this . setDefaultCloseOperation ( EXIT_ON_CLOSE ) ;
}
}