jfig.utils
Class RecentFileManager

java.lang.Object
  extended byjfig.utils.RecentFileManager

public class RecentFileManager
extends java.lang.Object

RecentFileManager - manage a set of "recent files" including the AWT menu stuff, AWT event and callback handling, and storage to a file or URL. The API for this class is based on the RecentFileList class from the org.freehep.swing package by Tony Johnson (tonyj@slac.stanford.edu).


Field Summary
(package private)  java.lang.String[] filenames
           
 int MAXCHARS
           
(package private)  java.awt.MenuItem[] menuItems
           
(package private)  java.awt.event.ActionListener target
           
 
Constructor Summary
RecentFileManager()
           
RecentFileManager(int n)
           
 
Method Summary
 void add(java.io.File file)
          retrieve the pathname of "file" and forward to the add( name ) method
 void add(java.lang.String name)
          add a file or URL "name" to our entries, and re-sort them: we just put the entry at position 0, and then walk through the filenames array.
 java.awt.MenuItem[] createMenuItems(java.awt.event.ActionListener listener)
          create n_entries menu items in the given Menu.
 java.lang.String get(java.awt.event.ActionEvent evt)
           
 java.lang.String get(int i)
           
 java.lang.String get(java.lang.String name)
           
 java.lang.String getMenuItemLabel(int i)
           
 int getSize()
           
 void load(java.util.Properties props)
          load the recent filenames from a Properties object, using "RecentFile0", "RecentFile1", etc.
 void loadFromFile(java.lang.String filename)
           
static void main(java.lang.String[] argv)
          minimal selftest
 void print()
           
 void save(java.util.Properties props)
          save the current filename entries as a Properties object, using "RecentFile0", "RecentFile1", etc.
 void saveToFile(java.lang.String filename)
           
 void setActionListener(java.awt.event.ActionListener al)
           
 void updateMenuItems()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXCHARS

public final int MAXCHARS
See Also:
Constant Field Values

filenames

java.lang.String[] filenames

menuItems

java.awt.MenuItem[] menuItems

target

java.awt.event.ActionListener target
Constructor Detail

RecentFileManager

public RecentFileManager()

RecentFileManager

public RecentFileManager(int n)
Method Detail

getSize

public int getSize()

setActionListener

public void setActionListener(java.awt.event.ActionListener al)

add

public void add(java.io.File file)
retrieve the pathname of "file" and forward to the add( name ) method


add

public void add(java.lang.String name)
add a file or URL "name" to our entries, and re-sort them: we just put the entry at position 0, and then walk through the filenames array.


print

public void print()

get

public java.lang.String get(java.lang.String name)

get

public java.lang.String get(int i)

createMenuItems

public java.awt.MenuItem[] createMenuItems(java.awt.event.ActionListener listener)
create n_entries menu items in the given Menu. The label of the menu item is built from the current file name: If the file name has less than 20 characters, we use the file name, otherwise the filename is truncated. If the corresponding entry is still null, we use "---" as the label.


updateMenuItems

public void updateMenuItems()

getMenuItemLabel

public java.lang.String getMenuItemLabel(int i)

get

public java.lang.String get(java.awt.event.ActionEvent evt)

save

public void save(java.util.Properties props)
save the current filename entries as a Properties object, using "RecentFile0", "RecentFile1", etc. as keys.


load

public void load(java.util.Properties props)
load the recent filenames from a Properties object, using "RecentFile0", "RecentFile1", etc. as keys.


saveToFile

public void saveToFile(java.lang.String filename)

loadFromFile

public void loadFromFile(java.lang.String filename)

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
minimal selftest

Throws:
java.lang.Exception