-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveGui.java
More file actions
104 lines (101 loc) · 2.8 KB
/
DriveGui.java
File metadata and controls
104 lines (101 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Alec Snyder
* cs162
* Main Gui frontend for google drive
* Creates a menu that calls all the other programs for the google drive program
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.lang.Runtime;
import java.io.IOException;
import java.lang.Process;
public class DriveGui implements ActionListener
{
public JFrame frame;
private JButton sync, list, upload, quit, rem;
public DriveGui()
{
frame=new JFrame("Welcome to Google Drive!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(2,1));
sync=new JButton("Sync");
list=new JButton("Download Files from Drive");
upload=new JButton("Upload File");
quit=new JButton("Quit");
rem=new JButton("Remove Files from Drive");
JPanel bPanel=new JPanel();
bPanel.setLayout(new GridLayout(1,5));
sync.addActionListener(this);
upload.addActionListener(this);
list.addActionListener(this);
rem.addActionListener(this);
quit.addActionListener(this);
bPanel.add(sync);
bPanel.add(list);
bPanel.add(upload);
bPanel.add(rem);
bPanel.add(quit);
JLabel instr=new JLabel("What would you like to do?");
frame.add(instr);
frame.add(bPanel);
frame.pack();
frame.setVisible(true);
File f=new File(System.getProperty("user.home")+"/gdrive/.drive_key");
if(!f.exists())
{
new GuiRefresh();
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==(Object)(quit))
{
System.exit(0);
}
else if(e.getSource()==(Object)(upload))
{
JFileChooser fc=new JFileChooser();
fc.setCurrentDirectory(new File(System.getProperty("user.home")));
int val=fc.showOpenDialog(frame);
if(val==JFileChooser.APPROVE_OPTION)
{
move(fc.getSelectedFile());
}
}
else if(e.getSource()==(Object)(sync))
{
String[] args={};
Sync.main(args);
}
else if(e.getSource()==(Object)(list))
{
new DownloadFrame();
}
else if(e.getSource()==(Object)(rem))
{
new RemoveFrame();
}
}
public void move(File f)
{
try
{
DriveInsert.up(f.getAbsolutePath());
}
catch(IOException e)
{
System.out.println("error occurred");
}
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new DriveGui();
}
});
}
}