Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Vector;
- public class App {
- private JList Directiories;
- private JFormattedTextField directorySelector;
- private JButton goButton;
- private JPanel panel;
- private JButton readButton;
- private JButton loginButton;
- private JButton Logout;
- private JButton backButton;
- public Session session = null;
- public String lastPath;
- List<String> shared = new LinkedList<>();
- List<FileDSM> filese = new LinkedList<>();
- List<String> temp = new LinkedList<>();
- public App() {
- loginButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- Login log = new Login();
- session = log.sess;
- Vector<String> v = new Vector<>();
- List<FileDSM> f = new LinkedList<>();
- v.clear();
- try {
- for (FileStationList.SharedFolder i : new FileStationList(session).listShared()) {
- shared.add(i.path);
- v.add(i.name);
- f.add(new FileDSM(i.path, i.name, true));
- lastPath = i.path.substring(0, i.path.lastIndexOf("/"));
- System.out.println(lastPath);
- }
- filese = f;
- } catch (IOException e) {
- e.printStackTrace();
- }
- Directiories.setListData(v);
- }
- });
- Logout.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- try {
- logout();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- goButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- try {
- int index = Directiories.getSelectedIndex();
- List<FileDSM> files = new FileStationList(session).list(filese.get(index).path);
- Vector<String> s = new Vector<>();
- for (FileDSM i : files) {
- s.add(i.path);
- }
- lastPath = files.get(0).path.substring(0, files.get(0).path.lastIndexOf("/"));
- filese = files;
- Directiories.setListData(s);
- System.out.println(lastPath);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- backButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- try {
- List<FileDSM> files = null;
- if(shared.contains(lastPath)){
- List<FileStationList.SharedFolder> filess = new FileStationList(session).listShared();
- files = new LinkedList<>();
- for (FileStationList.SharedFolder i : filess){
- files.add(new FileDSM(i.path, i.name, true));
- }
- } else {
- files = new FileStationList(session).list(lastPath);
- }
- Vector<String> s = new Vector<>();
- for (FileDSM i : files) {
- s.add(i.path);
- }
- lastPath = files.get(0).path.substring(0, files.get(0).path.lastIndexOf("/"));
- System.out.println(lastPath);
- filese = files;
- Directiories.setListData(s);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- readButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- int index = Directiories.getSelectedIndex();
- Runnable run = new Runnable() {
- @Override
- public void run() {
- try {
- byte[] file = new FileStationDownload(session).download(filese.get(index).path);
- File file1 = File.createTempFile("muz", ".tmp");
- FileOutputStream f = new FileOutputStream(file1);
- f.write(file);
- temp.add(file1.getAbsolutePath());
- Desktop.getDesktop().open(file1);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
- Thread t = new Thread(run);
- t.start();
- try {
- t.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- }
- public void logout() throws IOException {
- Auth.logout(session);
- }
- public void cleanTemp(){
- for(String i : temp){
- new File(i).delete();
- }
- }
- public static void main(String[] args) throws Exception {
- JFrame frame = new JFrame();
- App app = new App();
- frame.setContentPane(app.panel);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.pack();
- frame.setVisible(true);
- Thread.sleep(2000);
- WindowListener exitListene = new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent windowEvent) {
- super.windowClosing(windowEvent);
- try {
- app.logout();
- app.cleanTemp();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
- frame.addWindowListener(exitListene);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement