View Javadoc

1   package org.devaki.nextobjects.util;
2   /*
3   
4   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2 of the License, or (at your
9   option) any later version.
10  
11  This program is distributed in the hope that it will
12  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the GNU General Public License for more details.
15  
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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  }