1 package org.devaki.nextobjects.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Properties;
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.ListIterator;
25 import org.devaki.nextobjects.ui.menus.NOMenuBar;
26 /***
27 * Recent file list
28 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
29 * @author <a href="mailto:eflorent@devaki.org">Romeo Benzoni</a>
30 */
31 public final class NORecentFile
32 {
33 /*** app properties */
34 private static final Properties Prop = NOPreferences.getAppProperties();
35 /*** file list */
36 private static final ArrayList RecentFileList = new ArrayList();
37 /*** size */
38 private static final int SIZE = 5;
39 /***
40 * Default constructor avoid instanciation
41 *
42 */
43 private NORecentFile()
44 {
45 }
46 /***
47 * Add a file
48 * @param file the file to add
49 */
50 public static void add(final File file)
51 {
52 if (RecentFileList.contains(file))
53 {
54 RecentFileList.remove(RecentFileList.indexOf(file));
55 }
56 RecentFileList.add(0, file);
57 while (RecentFileList.size() > SIZE)
58 {
59 RecentFileList.remove(RecentFileList.size() - 1);
60 }
61 ListIterator i = RecentFileList.listIterator();
62 while (i.hasNext())
63 {
64 Prop.put("RecentFile" + i.nextIndex(), i.next().toString());
65 }
66 NOMenuBar.addRecent(RecentFileList);
67 }
68 /***
69 * Load the file list
70 *
71 */
72 public static void load()
73 {
74 int i;
75 for (i = SIZE; i >= 0; i--)
76 {
77 if (Prop.getProperty("RecentFile" + i) != null)
78 {
79 RecentFileList.add(
80 0,
81 new File(Prop.getProperty("RecentFile" + i)));
82 }
83 }
84 NOMenuBar.addRecent(RecentFileList);
85 }
86 }