|
| 1 | +package LiveSplitAddRun; |
| 2 | + |
| 3 | +import javax.swing.*; |
| 4 | +import javax.swing.filechooser.*; |
| 5 | +import java.awt.*; |
| 6 | +import java.awt.event.ActionEvent; |
| 7 | +import java.awt.event.ActionListener; |
| 8 | +import java.io.File; |
| 9 | + |
| 10 | +public class Content extends JPanel implements ActionListener { |
| 11 | + |
| 12 | + public static File lssFile; |
| 13 | + public static File txtFile; |
| 14 | + private static final JTextArea lssText = new JTextArea(); |
| 15 | + private static final JTextArea txtText = new JTextArea(); |
| 16 | + private static final JTextArea outputText = new JTextArea("Waiting..."); |
| 17 | + |
| 18 | + |
| 19 | + public Content() { |
| 20 | + this.setFocusable(true); |
| 21 | + this.setSize(300, 300); |
| 22 | + this.setLayout(new GridLayout(3, 1)); |
| 23 | + |
| 24 | + JButton lssButton = new JButton("Pick .lss file"); |
| 25 | + lssButton.setActionCommand("lss"); |
| 26 | + lssButton.addActionListener(this); |
| 27 | + this.add(lssButton); |
| 28 | + lssText.setLineWrap(true); |
| 29 | + this.add(lssText); |
| 30 | + |
| 31 | + JButton txtButton = new JButton("Pick times file"); |
| 32 | + txtButton.setActionCommand("txt"); |
| 33 | + txtButton.addActionListener(this); |
| 34 | + this.add(txtButton); |
| 35 | + txtText.setLineWrap(true); |
| 36 | + this.add(txtText); |
| 37 | + |
| 38 | + JButton execute = new JButton("Generate File"); |
| 39 | + execute.setActionCommand("exe"); |
| 40 | + execute.addActionListener(this); |
| 41 | + this.add(execute); |
| 42 | + outputText.setLineWrap(true); |
| 43 | + this.add(outputText); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void actionPerformed(ActionEvent e) { |
| 48 | + if (e.getActionCommand().equals("exe")) { |
| 49 | + try { |
| 50 | + outputText.setText(Main.convert(lssFile.getPath(), Main.getTimes(txtFile))); |
| 51 | + } |
| 52 | + catch (Exception ex) { |
| 53 | + outputText.setText("There was an error converting the files.\n" + ex.getMessage()); |
| 54 | + } |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + boolean isSplits = e.getActionCommand().equals("lss"); |
| 59 | + JFileChooser chooser = new JFileChooser(); |
| 60 | + chooser.setFileFilter(isSplits ? new LssOnly() : new TxtOnly()); |
| 61 | + |
| 62 | + int result = chooser.showOpenDialog(this); |
| 63 | + if (result == JFileChooser.APPROVE_OPTION) { |
| 64 | + if (isSplits) lssFile = chooser.getSelectedFile(); |
| 65 | + else txtFile = chooser.getSelectedFile(); |
| 66 | + } |
| 67 | + updateTexts(); |
| 68 | + } |
| 69 | + |
| 70 | + private static void updateTexts() { |
| 71 | + if (lssFile != null) lssText.setText(lssFile.getName()); |
| 72 | + if (txtFile != null) txtText.setText(txtFile.getName()); |
| 73 | + } |
| 74 | + |
| 75 | + private static class LssOnly extends FileFilter { |
| 76 | + |
| 77 | + @Override |
| 78 | + public boolean accept(File f) { |
| 79 | + return f.isDirectory() || f.getName().toLowerCase().endsWith(".lss"); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public String getDescription() { |
| 84 | + return ".lss files"; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private static class TxtOnly extends FileFilter { |
| 89 | + |
| 90 | + @Override |
| 91 | + public boolean accept(File f) { |
| 92 | + return f.isDirectory() || f.getName().toLowerCase().endsWith(".txt"); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public String getDescription() { |
| 97 | + return ".txt files"; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | +} |
0 commit comments