1 56 package org.objectstyle.cayenne.modeler.util; 57 58 import java.awt.Component ; 59 import java.util.Vector ; 60 61 import javax.swing.Action ; 62 import javax.swing.JMenu ; 63 import javax.swing.JMenuItem ; 64 65 import org.objectstyle.cayenne.modeler.Application; 66 import org.objectstyle.cayenne.modeler.ModelerPreferences; 67 import org.objectstyle.cayenne.modeler.action.OpenProjectAction; 68 69 75 public class RecentFileMenu extends JMenu { 76 77 80 public RecentFileMenu(String s) { 81 super(s); 82 } 83 84 87 public RecentFileMenuItem add(RecentFileMenuItem menuItem) { 88 return (RecentFileMenuItem) super.add(menuItem); 89 } 90 91 95 public void rebuildFromPreferences() { 96 ModelerPreferences pref = ModelerPreferences.getPreferences(); 97 Vector arr = pref.getVector(ModelerPreferences.LAST_PROJ_FILES); 98 while (arr.size() > 4) { 99 arr.remove(arr.size() - 1); 100 } 101 102 Component [] comps = getMenuComponents(); 104 int curSize = comps.length; 105 int prefSize = arr.size(); 106 107 for (int i = 0; i < prefSize; i++) { 108 String name = (String ) arr.get(i); 109 110 if (i < curSize) { 111 RecentFileMenuItem item = (RecentFileMenuItem) comps[i]; 113 item.setText(name); 114 } 115 else { 116 RecentFileMenuItem item = new RecentFileMenuItem(name); 118 item.setAction(findAction()); 119 add(item); 120 } 121 } 122 123 for (int i = curSize - 1; i >= prefSize; i--) { 125 remove(i); 126 } 127 } 128 129 protected Action findAction() { 130 return Application.getInstance().getAction(OpenProjectAction.getActionName()); 131 } 132 } | Popular Tags |