-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipGUI.java
More file actions
174 lines (155 loc) · 4.81 KB
/
ZipGUI.java
File metadata and controls
174 lines (155 loc) · 4.81 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class ZipGUI {
public String fileName;
public String zipName;
public String fileLocation;
public String zipLocation;
public String zipFileName;
JLabel fileLocationLabel;
JLabel filePathLabel;
JLabel zipLocationLabel;
JLabel zipPathLabel;
public ZipGUI() {
fileLocation = null;
zipLocation = null;
fileName = null;
zipName = null;
JFrame frame = new JFrame ("File Zipper");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(750, 400));
frame.add(new PositionPane());
frame.pack();
frame.setVisible(true);
}
protected class PositionPane extends JPanel {
public PositionPane() {
GridBagConstraints gbc = new GridBagConstraints();
JPanel filePanel = new JPanel(new GridBagLayout());
fileLocationLabel = new JLabel("File Location");
filePathLabel = new JLabel("C:\\Program Files\\filePath");
zipLocationLabel = new JLabel("Zip Location");
zipPathLabel = new JLabel("C:\\Program Files\\zipPath");
final JButton fileLocationButton = new JButton("Browse File");
fileLocationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(fileLocationButton);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = fc.getCurrentDirectory();
filePathLabel.setText(fc.getSelectedFile().getPath());
setFileName(fc.getSelectedFile().getName());
setFileLocation(selectedFile.getPath());
}
}
});
final JButton zipLocationButton = new JButton("Browse Zip");
zipLocationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(zipLocationButton);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println(fc.getSelectedFile().getAbsolutePath());
zipPathLabel.setText(fc.getSelectedFile().getAbsolutePath());
setZipName(fc.getSelectedFile().getAbsolutePath());
setZipLocation(fc.getSelectedFile().getAbsolutePath());
}
}
});
JButton zipButton = new JButton("Zip");
zipButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String zipFileName = JOptionPane.showInputDialog("Enter the name of the zip file.");
System.out.println(zipFileName);
setZipFileName(zipFileName);
ZipUtil.ZipFile();
}
});
//File Components
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 20, 150);
filePanel.add(fileLocationLabel, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(0, 0, 0, 120);
filePanel.add(fileLocationButton, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 2;
gbc.ipadx = 1;
gbc.insets = new Insets(0, 0, 0, 60);
filePanel.add(filePathLabel, gbc);
gbc.ipadx = 0;
//Zip Components
gbc.gridx = 0;
gbc.gridy = 3;
gbc.insets = new Insets(100, 0, 20, 150);
filePanel.add(zipLocationLabel, gbc);
gbc.gridx = 0;
gbc.gridy = 4;
gbc.insets = new Insets(0, 0, 0, 120);
filePanel.add(zipLocationButton, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 2;
gbc.ipadx = 2;
gbc.insets = new Insets(0, 0, 0, 60);
filePanel.add(zipPathLabel, gbc);
gbc.ipadx = 0;
gbc.anchor = GridBagConstraints.PAGE_END;
gbc.insets = new Insets(80, 0, 0, 100);
gbc.gridx = 0;
gbc.gridy = 5;
filePanel.add(zipButton, gbc);
add(filePanel);
}
}
public void checkFileNames() {
JOptionPane.showMessageDialog(null, "File path/name(s) are invalid. Try again.");
}
public void showDoneDialog() {
JOptionPane.showMessageDialog(null, "Done!");
}
public void setFileLocation(String file) {
fileLocation = file;
}
public String getFileLocation() {
return fileLocation;
}
public void setFileName(String file) {
fileName = file;
}
public String getFileName() {
return fileName;
}
public void setZipLocation(String file) {
zipLocation = file;
}
public String getZipLocation() {
return zipLocation;
}
public void setZipName(String file) {
zipName = file;
}
public String getZipName() {
return zipName;
}
public void setZipFileName(String file) {
zipFileName = file;
}
public String getZipFileName() {
return zipFileName;
}
}