-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddfile.java
193 lines (176 loc) · 7.35 KB
/
addfile.java
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package not.git;
jhi
import java.awt.Window;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import static not.git.NotGit.fileName;
import static not.git.menu.window;
/**
*
* @author Administrator
*/
public class addfile extends javax.swing.JFrame {
static boolean fileFound;
public static String fileName = "";
static String path = "";
static int printtrack = 0;
ArrayList list;
String command;
/**
* Creates new form addfile
*/
public addfile() {
initComponents();
// openlist();
}
public void openlist() {
File ng = new File("C:\\Users\\Administrator\\Documents\\NetBeansProjects\\not-git\\console.dat");
list = new ArrayList();
// StringBuilder sb = new StringBuilder();
if (ng.exists()) {
try {
ObjectInputStream obs=new ObjectInputStream(new FileInputStream("console.dat"));
try{
while(true){
Scanner s=new Scanner(obs.readUTF());
String check=s.next();
list.add(check);
}
}
catch(EOFException e){}
obs.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(addfile.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(addfile.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
inputfilename = new javax.swing.JTextField();
done = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jTextField1.setText("Please enter the name of the file");
done.setText("DONE");
done.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
doneActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(59, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(90, 90, 90))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(inputfilename, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52))))
.addGroup(layout.createSequentialGroup()
.addGap(169, 169, 169)
.addComponent(done)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addComponent(inputfilename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(done)
.addContainerGap(58, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void doneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneActionPerformed
/*
Path paths = Paths.get("C:\\Users\\Administrator\\Documents\\NetBeansProjects\\not-git\\console.dat");
try {
Files.createFile(paths);
} catch (IOException ex) {
Logger.getLogger(NotGit.class.getName()).log(Level.SEVERE, null, ex);
}
} */
openlist();
if (inputfilename.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Please enter a file name");
} else {
File file = new File("C:\\Users\\Administrator\\Documents");
command = inputfilename.getText().trim();
String checkaddfile = " "; int save=1;
for(int i=0;i<list.size();i++)
if(list.get(i).equals(command)){
JOptionPane.showMessageDialog(null, command+" is already in the list");
save=0;
break;
}
if(save==1)
savedata(file, command);
}
}//GEN-LAST:event_doneActionPerformed
/**
* @param args the command line arguments
*/
public void savedata(File file, String command) {
if (NotGit.searchFile(file, command)) {
JOptionPane.showMessageDialog(null, command + " is successfully added");
list.add(command);
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("console.dat"));
for (int i = 0; i < list.size(); i++) {
out.writeUTF(list.get(i) + " ");
}
// printtrack=1;
out.close();
} catch (IOException me) {
System.out.println(me.getMessage());
}
/* File addfile = new File(path);
doublelinked db = new doublelinked();
db.addlast(addfile);
db.showcontent(addfile); */
window.append(command + " is being tracked \n\n");
this.dispose();
} else {
JOptionPane.showMessageDialog(null, command + " does not exist");
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton done;
private javax.swing.JTextField inputfilename;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}