[Jsxe-cvs] SF.net SVN: jsxe: [1197] trunk/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-29 16:06:25
|
Revision: 1197 Author: ian_lewis Date: 2006-08-29 09:06:10 -0700 (Tue, 29 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1197&view=rev Log Message: ----------- Merge from 05pre3 branch rev. 1195 Modified Paths: -------------- trunk/jsxe/Changelog trunk/jsxe/build.xml trunk/jsxe/src/net/sourceforge/jsxe/ActionManager.java trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java trunk/jsxe/src/net/sourceforge/jsxe/gui/menu/WrappingMenu.java Modified: trunk/jsxe/Changelog =================================================================== --- trunk/jsxe/Changelog 2006-08-29 16:05:55 UTC (rev 1196) +++ trunk/jsxe/Changelog 2006-08-29 16:06:10 UTC (rev 1197) @@ -1,3 +1,9 @@ +08/29/2006 Ian Lewis <Ian...@me...> + + * Fixed a memory leak with JMenuItems. ActionManager kept a cache of + Wrapper Action objects. JMenu items register listeners with those Actions + so the JMenuItems would never be Garbage collected. + 08/28/2006 Ian Lewis <Ian...@me...> * Changed the messages files to be named the standard ResourceBundle way. Modified: trunk/jsxe/build.xml =================================================================== --- trunk/jsxe/build.xml 2006-08-29 16:05:55 UTC (rev 1196) +++ trunk/jsxe/build.xml 2006-08-29 16:06:10 UTC (rev 1197) @@ -278,6 +278,15 @@ </fileset> </copy> + <!-- copy the lib directory so that the jsXe.exe can be run + from the build dir --> + <mkdir dir="${build.lib}"/> + <copy todir="${build.lib}"> + <fileset dir="${lib.dir}"> + <include name="**/*"/> + </fileset> + </copy> + <!-- set the build properties --> <propertyfile comment="${app.name}'s build properties" file="${build.dest}/net/sourceforge/jsxe/build.properties"> <entry key="application.name" value="${app.name}"/> @@ -340,13 +349,6 @@ <!-- }}} --> <!-- {{{ ============ Prepares for a build ============================= --> <target depends="init" name="prepare-build"> - <!-- lib --> - <mkdir dir="${build.dir}/lib"/> - <copy todir="${build.dir}/lib"> - <fileset dir="${lib.dir}"> - <include name="**/*"/> - </fileset> - </copy> <!-- bin --> <mkdir dir="${build.dir}/bin"/> <copy todir="${build.dir}/bin"> @@ -621,15 +623,6 @@ <!-- {{{ create the win tar.bz2 file --> - <!-- copy the lib directory so that the jsXe.exe can be run - from the build dir --> - <mkdir dir="${build.dir}/lib"/> - <copy todir="${build.dir}/lib"> - <fileset dir="${build.lib}"> - <include name="**/*"/> - </fileset> - </copy> - <!-- create the windows exe --> <taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask" Modified: trunk/jsxe/src/net/sourceforge/jsxe/ActionManager.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/ActionManager.java 2006-08-29 16:05:55 UTC (rev 1196) +++ trunk/jsxe/src/net/sourceforge/jsxe/ActionManager.java 2006-08-29 16:06:10 UTC (rev 1197) @@ -118,8 +118,11 @@ * @param name the name of the action. */ public static Action getAction(String name) { - Action action = (Action)m_actionMap.get(name); - if (action == null) { + // We can't keep a cache of Wrappers because JMenuItems register + //listeners with them and would never be GCed. + Action action = null; + // Action action = (Action)m_actionMap.get(name); + // if (action == null) { LocalizedAction editAction = getLocalizedAction(name); if (editAction != null) { action = new Wrapper(name); @@ -135,11 +138,11 @@ action.putValue(Action.ACCELERATOR_KEY, KeyEventTranslator.getKeyStroke(keyBinding)); } - m_actionMap.put(name, action); + // m_actionMap.put(name, action); } else { Log.log(Log.WARNING,ActionManager.class,"Unknown action: "+ name); } - } + // } return action; }//}}} @@ -326,7 +329,7 @@ /** * This is an name to Wrapper mapping. */ - private static HashMap m_actionMap = new HashMap(); + // private static HashMap m_actionMap = new HashMap(); private static ArrayList m_actionSets = new ArrayList(); private static boolean initialized = false; Modified: trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java 2006-08-29 16:05:55 UTC (rev 1196) +++ trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java 2006-08-29 16:06:10 UTC (rev 1197) @@ -462,17 +462,16 @@ m_recentFilesMenu.removeAll(); ArrayList historyEntries = jsXe.getBufferHistory().getEntries(); int index = 0; - JMenu addMenu = m_recentFilesMenu; Iterator historyItr = historyEntries.iterator(); while (historyItr.hasNext()) { BufferHistory.BufferHistoryEntry entry = (BufferHistory.BufferHistoryEntry)historyItr.next(); - addMenu.add(new JMenuItem(new OpenRecentFileAction(this, entry))); + m_recentFilesMenu.add(new JMenuItem(new OpenRecentFileAction(this, entry))); index++; } - if (addMenu.getItemCount() == 0) { + if (m_recentFilesMenu.getMenuComponentCount() == 0) { JMenuItem nullItem = new JMenuItem(Messages.getMessage("File.Recent.None")); nullItem.setEnabled(false); - addMenu.add(nullItem); + m_recentFilesMenu.add(nullItem); } }//}}} @@ -671,7 +670,7 @@ //Add recent files menu m_recentFilesMenu = new WrappingMenu(Messages.getMessage("File.Recent"), jsXe.getIntegerProperty("menu.spill.over", 20)); - m_fileMenu.add(m_recentFilesMenu); + m_fileMenu.add(m_recentFilesMenu.getJMenu()); m_fileMenu.addSeparator(); menuItem = new JMenuItem(ActionManager.getAction("save-file")); Modified: trunk/jsxe/src/net/sourceforge/jsxe/gui/menu/WrappingMenu.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/gui/menu/WrappingMenu.java 2006-08-29 16:05:55 UTC (rev 1196) +++ trunk/jsxe/src/net/sourceforge/jsxe/gui/menu/WrappingMenu.java 2006-08-29 16:06:10 UTC (rev 1197) @@ -28,7 +28,6 @@ //{{{ jsXe classes import net.sourceforge.jsxe.gui.Messages; -import net.sourceforge.jsxe.EBListener; //}}} //{{{ Java classes @@ -47,15 +46,14 @@ * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ */ -public class WrappingMenu extends JMenu { +public class WrappingMenu { //{{{ WrappingMenu constructor /** * Constructs a WrappingMenu without an "invoker" and the default wrap count of 20. */ public WrappingMenu() { - super(); - m_addToMenus.push(this); + m_addToMenus.push(new JMenu()); }//}}} //{{{ WrappingMenu constructor @@ -66,9 +64,8 @@ * it wraps. */ public WrappingMenu(int wrapCount) { - super(); m_wrapCount = wrapCount; - m_addToMenus.push(this); + m_addToMenus.push(new JMenu()); }//}}} //{{{ WrappingMenu constructor @@ -80,9 +77,8 @@ * it wraps. */ public WrappingMenu(String label, int wrapCount) { - super(label); m_wrapCount = wrapCount; - m_addToMenus.push(this); + m_addToMenus.push(new JMenu(label)); }//}}} //{{{ add() @@ -91,11 +87,7 @@ maybeAddMenu(); JMenuItem r; JMenu menu = getCurrentMenu(); - if (menu == this) { - r = super.add(a); - } else { - r = menu.add(a); - } + r = menu.add(a); m_menuHash.put(r, getCurrentMenu()); return r; }//}}} @@ -106,11 +98,7 @@ maybeAddMenu(); Component r; JMenu menu = getCurrentMenu(); - if (menu == this) { - r = super.add(c); - } else { - r = menu.add(c); - } + r = menu.add(c); m_menuHash.put(r, getCurrentMenu()); return r; }//}}} @@ -126,11 +114,7 @@ int addIndex = (int)(index / m_wrapCount); int addSubIndex = (index % m_wrapCount); JMenu menu = (JMenu)m_addToMenus.get(addIndex); - if (menu == this) { - r = super.add(c, addSubIndex); - } else { - r = menu.add(c, addSubIndex); - } + r = menu.add(c, addSubIndex); updateSubMenus(); } return r; @@ -145,11 +129,7 @@ } JMenuItem r; JMenu menu = getCurrentMenu(); - if (menu == this) { - r = super.add(menuItem); - } else { - r = menu.add(menuItem); - } + r = menu.add(menuItem); return r; }//}}} @@ -159,11 +139,7 @@ maybeAddMenu(); JMenuItem r; JMenu menu = getCurrentMenu(); - if (menu == this) { - r = super.add(s); - } else { - r = menu.add(s); - } + r = menu.add(s); m_menuHash.put(r, getCurrentMenu()); return r; }//}}} @@ -179,11 +155,7 @@ int addIndex = (int)(pos / m_wrapCount); int addSubIndex = (pos % m_wrapCount); JMenu menu = (JMenu)m_addToMenus.get(addIndex); - if (menu == this) { - r = super.insert(a, addSubIndex); - } else { - r = menu.insert(a, addSubIndex); - } + r = menu.insert(a, addSubIndex); updateSubMenus(); } return r; @@ -200,17 +172,13 @@ int addIndex = (int)(pos / m_wrapCount); int addSubIndex = (pos % m_wrapCount); JMenu menu = (JMenu)m_addToMenus.get(addIndex); - if (menu == this) { - r = super.insert(mi, addSubIndex); - } else { - r = menu.insert(mi, addSubIndex); - } + r = menu.insert(mi, addSubIndex); updateSubMenus(); } return r; }//}}} - //{{{ insert + //{{{ insert() public void insert(String s, int pos) { if (pos == -1) { @@ -220,11 +188,7 @@ int addIndex = (int)(pos / m_wrapCount); int addSubIndex = (pos % m_wrapCount); JMenu menu = (JMenu)m_addToMenus.get(addIndex); - if (menu == this) { - super.insert(s, addSubIndex); - } else { - menu.insert(s, addSubIndex); - } + menu.insert(s, addSubIndex); updateSubMenus(); } }//}}} @@ -233,12 +197,7 @@ public void remove(Component c) { JMenu menu = (JMenu)m_menuHash.get(c); - if (menu == this) { - super.remove(c); - } else { - menu.remove(c); - } - + menu.remove(c); m_menuHash.remove(c); updateSubMenus(); }//}}} @@ -253,11 +212,7 @@ public void remove(JMenuItem item) { JMenu menu = (JMenu)m_menuHash.get(item); - if (menu == this) { - super.remove(item); - } else { - menu.remove(item); - } + menu.remove(item); m_menuHash.remove(item); updateSubMenus(); }//}}} @@ -265,10 +220,11 @@ //{{{ removeAll() public void removeAll() { + JMenu menu = getJMenu(); + menu.removeAll(); m_menuHash = new HashMap(); m_addToMenus = new Stack(); - m_addToMenus.push(this); - super.removeAll(); + m_addToMenus.push(menu); }//}}} //{{{ getMenuComponent() @@ -280,14 +236,10 @@ int addIndex = (int)(n / m_wrapCount); int addSubIndex = (n % m_wrapCount); JMenu menu = (JMenu)m_addToMenus.get(addIndex); - if (menu == this) { - return super.getMenuComponent(addSubIndex); - } else { - return menu.getMenuComponent(addSubIndex); - } + return menu.getMenuComponent(addSubIndex); }//}}} - //{{{ getMenuComponentCount + //{{{ getMenuComponentCount() /** * Gets the total number of components in this menu * and submenus. @@ -297,6 +249,14 @@ return m_menuHash.keySet().size(); }//}}} + //{{{ getJMenu() + /** + * Gets the JMenu that is used by Swing for this WrappingMenu. + */ + public JMenu getJMenu() { + return (JMenu)m_addToMenus.get(0); + }//}}} + //{{{ MoreMenu class /** * A submenu used by the <code>WrappingMenu</code>. Classes that extend @@ -328,18 +288,6 @@ //{{{ Private members - //{{{ getTrueMenuItemCount() - /** - * Gets the true item count for a sub-menu - */ - private int getTrueMenuItemCount(JMenu menu) { - if (menu == this) { - return super.getMenuComponentCount(); - } else { - return menu.getMenuComponentCount(); - } - }//}}} - //{{{ getCurrentMenu() /** * Gets the current menu that we are adding to. @@ -358,7 +306,7 @@ JMenu menu = (JMenu)m_addToMenus.get(i); //greater than wrap count + 1 because of the "More" menu item. - while (getTrueMenuItemCount(menu) > m_wrapCount + 1) { + while (menu.getMenuComponentCount() > m_wrapCount + 1) { //If we need another menu then make one. JMenu nextMenu; @@ -371,25 +319,21 @@ nextMenu = moreMenu; } - int index = getTrueMenuItemCount(menu)-2; + int index = menu.getMenuComponentCount()-2; Component menuComponent = menu.getComponent(index); menu.remove(index); nextMenu.add(menuComponent, 0); } //while there are less than we want in the menu and it's not the last menu - while (getTrueMenuItemCount(menu) < m_wrapCount + 1 && i+1 < m_addToMenus.size()) { + while (menu.getMenuComponentCount() < m_wrapCount + 1 && i+1 < m_addToMenus.size()) { JMenu nextMenu = (JMenu)m_addToMenus.get(i+1); Component menuComponent = nextMenu.getMenuComponent(0); nextMenu.remove(0); - if (menu == this) { - super.add(menuComponent, getTrueMenuItemCount(this)-1); - } else { - menu.add(menuComponent, getTrueMenuItemCount(menu)-1); - } + menu.add(menuComponent, menu.getMenuComponentCount()-1); - if (getTrueMenuItemCount(nextMenu) == 0) { + if (nextMenu.getMenuComponentCount() == 0) { menu.remove(nextMenu); m_addToMenus.pop(); //if it's empty it must be the last menu. } @@ -402,7 +346,7 @@ * Updates the menu that we are truly adding to. */ private void maybeAddMenu() { - int componentCount = getTrueMenuItemCount(getCurrentMenu()); + int componentCount = getCurrentMenu().getMenuComponentCount(); if (componentCount >= m_wrapCount) { MoreMenu menu = createMoreMenu(); ((JMenu)m_addToMenus.peek()).add(menu); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |