-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileMenu.java
100 lines (86 loc) · 3.59 KB
/
FileMenu.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package FileMngmt;
import java.io.BufferedReader;
import java.io.FileReader;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
/**
*
* @author stefanopilla
*/
public class FileMenu {
public FileMenu(String path){
addRecentFile(String path);
}
public void addRecentFile(String path) {
if (verifyRecentFile()) {
recentMenuItem.setEnabled(true);
try {
FileReader fr = new FileReader(path);
BufferedReader reader = new BufferedReader(fr);
String line;
int i = 0;
while ((line = reader.readLine()) != null) {
final String[] result = line.split(",");
for (i = 0; i < result.length; i = i + 2) {
freimapgsoc.LayerForm.recentMenuItem = new JMenuItem(result[i]);
freimapgsoc.LayerForm.recentMenuItem.setToolTipText(result[i + 1]);
freimapgsoc.LayerForm.recentMenuItem.add(freimapgsoc.LayerForm.recentMenuItem, i);
path = result[i + 1];
freimapgsoc.LayerForm.recentMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
freimapgsoc.newRecentFileActionPerformed(evt, path);
}
});
}
reader.close();
fr.close();
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
/*
public void addRecentFile(final String path, String name) {
try {
if (verifyRecentFile()) {
recentFilesMenu.setEnabled(true);
JMenuItem newRecentFile = new JMenuItem(name);
recentFilesMenu.add(newRecentFile, recentFilesMenu.getItemCount() - 2);
newRecentFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newRecentFileActionPerformed(evt, path);
}
});
newRecentFile.setToolTipText(path);
PrintStream output = new PrintStream(new FileOutputStream(recentFile.getPath()));
output.append(name + "," + path);
} else if (!verifyRecentFile()) {
recentFile.createNewFile();
recentFilesMenu.setEnabled(true);
JMenuItem newRecentFile = new JMenuItem(name);
newRecentFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newRecentFileActionPerformed(evt, path);
}
});
recentFilesMenu.add(newRecentFile, recentFilesMenu.getItemCount() - 2);
newRecentFile.setToolTipText(path);
PrintStream output = new PrintStream(new FileOutputStream(recentFile.getPath()));
output.append(name + "," + path);
}
} catch (FileNotFoundException ex) {
ex.getMessage();
} catch (IOException io) {
io.getMessage();
}
}*/
private boolean verifyRecentFile() {
throw new UnsupportedOperationException("Not yet implemented");
}
private JMenu recentMenu;
}