From: <aki...@us...> - 2008-08-03 21:08:30
|
Revision: 4742 http://gridarta.svn.sourceforge.net/gridarta/?rev=4742&view=rev Author: akirschbaum Date: 2008-08-03 21:08:36 +0000 (Sun, 03 Aug 2008) Log Message: ----------- Move GUI related utility classes to separate package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java trunk/crossfire/src/cfeditor/gui/script/ScriptView.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/gui/MainView.java trunk/src/app/net/sf/gridarta/gui/RecentManager.java trunk/src/app/net/sf/gridarta/gui/SystemIcons.java trunk/src/app/net/sf/gridarta/gui/map/MapView.java trunk/src/app/net/sf/gridarta/gui/pickmapchooser/FolderListActions.java trunk/src/app/net/sf/gridarta/treasurelist/TreasureCellRenderer.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/utils/ trunk/src/app/net/sf/gridarta/gui/utils/GUIUtils.java trunk/src/app/net/sf/gridarta/gui/utils/MenuUtils.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/GUIUtils.java trunk/src/app/net/sf/gridarta/gui/MenuHelper.java Modified: trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/crossfire/src/cfeditor/gui/script/CloseableTabbedPane.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -52,7 +52,7 @@ import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JTabbedPane; -import net.sf.gridarta.gui.GUIUtils; +import net.sf.gridarta.gui.utils.GUIUtils; public class CloseableTabbedPane extends JTabbedPane { Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptEditor.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -54,7 +54,7 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import net.sf.gridarta.gui.GUIUtils; +import net.sf.gridarta.gui.utils.GUIUtils; import org.apache.log4j.Logger; public class ScriptEditor extends JPanel { Modified: trunk/crossfire/src/cfeditor/gui/script/ScriptView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/crossfire/src/cfeditor/gui/script/ScriptView.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -40,7 +40,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; -import net.sf.gridarta.gui.MenuHelper; +import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ReflectionAction; import org.apache.log4j.Logger; @@ -130,7 +130,7 @@ return; } - MenuHelper.removeAllToSeparator(menuScripts); + MenuUtils.removeAllToSeparator(menuScripts); int index = 0; for (final String script : control.listScript()) { Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/daimonin/src/daieditor/CMainControl.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -76,7 +76,6 @@ import net.sf.gridarta.gameobject.scripts.AbstractScriptArchEditor; import net.sf.gridarta.gameobject.scripts.ScriptedEventEditor; import net.sf.gridarta.gui.About; -import net.sf.gridarta.gui.GUIUtils; import net.sf.gridarta.gui.HideFileFilterProxy; import net.sf.gridarta.gui.LeftPanel; import net.sf.gridarta.gui.MainActions; @@ -106,6 +105,7 @@ import net.sf.gridarta.gui.selectedsquare.SelectedSquareControl; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.gui.undo.UndoControl; +import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.io.IOUtils; import net.sf.gridarta.io.PathManager; import net.sf.gridarta.map.AutoValidator; Deleted: trunk/src/app/net/sf/gridarta/gui/GUIUtils.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/GUIUtils.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/GUIUtils.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -1,128 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gui; - -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import javax.swing.ImageIcon; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; - -/** - * <code>CGUtils</code> is a collection of GUI utility methods. Mainly focusing - * on resource management. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class GUIUtils { - - /** The Logger for printing log messages. */ - private static final Logger log = Logger.getLogger(GUIUtils.class); - - private static final Map<String, ImageIcon> imageCache = new HashMap<String, ImageIcon>(); - - /** Do not subclass. */ - private GUIUtils() { - /* nothing to do - never invoked. */ - } - - /** - * Returns the image icon for the given icon name. Loads every icon only - * once and uses hashtable to return the same instance if same icon name is - * given. Note: There must not be conflicting icon names from different - * directorys. - * @param dirUri uri of the directory the icon is in - * @param strIconName the icon name (propably one of the constants defined - * in IGUIConstants). - * @return The image icon for the given icon name. - */ - @Nullable - private static ImageIcon getResourceIcon(final String dirUri, final String strIconName) { - if (dirUri.contains("\\")) { - throw new IllegalArgumentException("dirUri must be a URI but was: " + dirUri); - } - // first, look if this icon is already available in the Hashtable - if (imageCache.containsKey(strIconName)) { - return imageCache.get(strIconName); - } - - // Look for the file, replacing '/' with File.separatorChar when necessary. - final File imageFile = new File(File.separatorChar != '/' ? dirUri.replace('/', File.separatorChar) : dirUri, strIconName); - @Nullable final ImageIcon icon; - if (imageFile.exists()) { - // image file exists in expected directory - icon = new ImageIcon(imageFile.getAbsolutePath()); - } else { - // image file is missing, so let's try to load it from jar - final URL fullImageResource = GUIUtils.class.getClassLoader().getResource(dirUri + '/' + strIconName); - - if (fullImageResource != null) { - icon = new ImageIcon(fullImageResource); - } else { - final int slashIndex = dirUri.indexOf('/'); - if (slashIndex != -1) { - // let's try it again without first directory (okay, this may look - // a bit weird, but usually this is the correct icon path in the jar) - final URL strippedImageResource = GUIUtils.class.getClassLoader().getResource(dirUri.substring(slashIndex + 1) + '/' + strIconName); - if (strippedImageResource != null) { - icon = new ImageIcon(strippedImageResource); - } else { - icon = null; - } - } else { - icon = null; - } - } - } - - // put this icon into the Hashtable - if (icon != null) { - imageCache.put(strIconName, icon); - } else { - log.warn("Failed to load icon '" + strIconName + "'!"); - } - - return icon; - } - - /** - * Returns the specified icon as a normal icon resource. - * @param strIconName Name of the icon to return. - * @return The icon or <code>null</code> if the icon couldn't be loaded. - */ - @Nullable - public static ImageIcon getIcon(final String strIconName) { - return getResourceIcon(GUIConstants.ICON_DIR, strIconName); - } - - /** - * Returns the specified icon as a system icon resource. - * @param strIconName Name of the icon to return. - * @return The icon or <code>null</code> if the icon couldn't be loaded. - */ - @Nullable - public static ImageIcon getSysIcon(final String strIconName) { - return getResourceIcon(GUIConstants.SYSTEM_DIR, strIconName); - } - -} // class GUIUtils Modified: trunk/src/app/net/sf/gridarta/gui/MainView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/MainView.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/MainView.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -54,6 +54,8 @@ import net.sf.gridarta.gui.map.ViewActions; import net.sf.gridarta.gui.objectchooser.DefaultObjectChooser; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; +import net.sf.gridarta.gui.utils.GUIUtils; +import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.help.Help; import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapControl; @@ -542,7 +544,7 @@ /** Rebuild the window menu. */ private void rebuildWindowMenu() { final JMenu menuWindow = (JMenu) actionFactory.find(getJMenuBar(), "window"); - MenuHelper.removeAll(menuWindow); + MenuUtils.removeAll(menuWindow); menuWindow.add(aCloseAll); if (!mapViewManager.isEmpty()) { menuWindow.addSeparator(); Deleted: trunk/src/app/net/sf/gridarta/gui/MenuHelper.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/MenuHelper.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/MenuHelper.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -1,82 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gui; - -import java.awt.Component; -import javax.swing.AbstractButton; -import javax.swing.JMenu; -import javax.swing.JSeparator; -import javax.swing.MenuElement; - -/** - * Utility class implementing menu related functions. - * @author Andreas Kirschbaum - */ -@SuppressWarnings({"ClassNamingConvention"}) -public class MenuHelper { - - /** Private constructor to prevent instantiation. */ - private MenuHelper() { - } - - /** - * Remove all actions attached to menu entries in a given menu element and - * its children. - * @param menuElement the menu element to process - */ - public static void disposeMenuElement(final MenuElement menuElement) { - if (menuElement instanceof AbstractButton) { - ((AbstractButton) menuElement).setAction(null); - } - - for (final MenuElement child : menuElement.getSubElements()) { - disposeMenuElement(child); - } - } - - /** - * Remove all menu entries. - * @param menu the menu to remove the entries from - */ - public static void removeAll(final JMenu menu) { - for (final MenuElement child : menu.getSubElements()) { - disposeMenuElement(child); - } - menu.removeAll(); - } - - /** - * Remove all menu entries up to (but not including) the first separator. - * @param menu the menu to remove the entries from - */ - public static void removeAllToSeparator(final JMenu menu) { - for (; ;) { - final Component menuItem = menu.getMenuComponent(0); - if (menuItem == null || menuItem instanceof JSeparator) { - break; - } - menu.remove(0); - if (menuItem instanceof MenuElement) { - disposeMenuElement((MenuElement) menuItem); - } - } - } - -} // class MenuHelper Modified: trunk/src/app/net/sf/gridarta/gui/RecentManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/RecentManager.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/RecentManager.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -33,6 +33,7 @@ import net.sf.gridarta.GlobalSettings; import net.sf.gridarta.MapManager; import net.sf.gridarta.gui.map.MapPreviewAccessory; +import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -125,7 +126,7 @@ return; } - MenuHelper.removeAll(recentMenu); + MenuUtils.removeAll(recentMenu); for (final Recent recent : recents) { recentMenu.add(recent); } Modified: trunk/src/app/net/sf/gridarta/gui/SystemIcons.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/SystemIcons.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/SystemIcons.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -26,6 +26,7 @@ import java.awt.image.ImageProducer; import javax.swing.ImageIcon; import net.sf.gridarta.gameobject.face.AbstractFaceObjects; +import net.sf.gridarta.gui.utils.GUIUtils; /** * Utility class for system icons. Modified: trunk/src/app/net/sf/gridarta/gui/map/MapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapView.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/map/MapView.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -31,7 +31,7 @@ import net.sf.gridarta.MapImageCache; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.gui.MenuHelper; +import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.io.PathManager; import net.sf.gridarta.map.DefaultMapControl; import net.sf.gridarta.map.MapArchObject; @@ -175,7 +175,7 @@ mapControl.removeMapControlListener(mapControlListener); mapControl.getMapModel().removeMapModelListener(mapModelListener); //mapFileActions.closeNotify(); - MenuHelper.disposeMenuElement(getJMenuBar()); + MenuUtils.disposeMenuElement(getJMenuBar()); } /** Modified: trunk/src/app/net/sf/gridarta/gui/pickmapchooser/FolderListActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/pickmapchooser/FolderListActions.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/gui/pickmapchooser/FolderListActions.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -24,9 +24,9 @@ import javax.swing.JMenu; import net.sf.gridarta.gameobject.Archetype; import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.gui.MenuHelper; import net.sf.gridarta.gui.map.MapViewBasic; import net.sf.gridarta.gui.newmap.NewMapDialogFactory; +import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.map.MapArchObject; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; @@ -115,7 +115,7 @@ return; } - MenuHelper.removeAll(folderMenu); + MenuUtils.removeAll(folderMenu); for (final Folder<G, A, R, V> folder : model) { final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(); final FolderListAction<G, A, R, V> action = new FolderListAction<G, A, R, V>(folder, menuItem); Copied: trunk/src/app/net/sf/gridarta/gui/utils/GUIUtils.java (from rev 4737, trunk/src/app/net/sf/gridarta/gui/GUIUtils.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/GUIUtils.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/utils/GUIUtils.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -0,0 +1,129 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.utils; + +import java.io.File; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import javax.swing.ImageIcon; +import net.sf.gridarta.gui.GUIConstants; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; + +/** + * <code>CGUtils</code> is a collection of GUI utility methods. Mainly focusing + * on resource management. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class GUIUtils { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(GUIUtils.class); + + private static final Map<String, ImageIcon> imageCache = new HashMap<String, ImageIcon>(); + + /** Do not subclass. */ + private GUIUtils() { + /* nothing to do - never invoked. */ + } + + /** + * Returns the image icon for the given icon name. Loads every icon only + * once and uses hashtable to return the same instance if same icon name is + * given. Note: There must not be conflicting icon names from different + * directorys. + * @param dirUri uri of the directory the icon is in + * @param strIconName the icon name (propably one of the constants defined + * in IGUIConstants). + * @return The image icon for the given icon name. + */ + @Nullable + private static ImageIcon getResourceIcon(final String dirUri, final String strIconName) { + if (dirUri.contains("\\")) { + throw new IllegalArgumentException("dirUri must be a URI but was: " + dirUri); + } + // first, look if this icon is already available in the Hashtable + if (imageCache.containsKey(strIconName)) { + return imageCache.get(strIconName); + } + + // Look for the file, replacing '/' with File.separatorChar when necessary. + final File imageFile = new File(File.separatorChar != '/' ? dirUri.replace('/', File.separatorChar) : dirUri, strIconName); + @Nullable final ImageIcon icon; + if (imageFile.exists()) { + // image file exists in expected directory + icon = new ImageIcon(imageFile.getAbsolutePath()); + } else { + // image file is missing, so let's try to load it from jar + final URL fullImageResource = GUIUtils.class.getClassLoader().getResource(dirUri + '/' + strIconName); + + if (fullImageResource != null) { + icon = new ImageIcon(fullImageResource); + } else { + final int slashIndex = dirUri.indexOf('/'); + if (slashIndex != -1) { + // let's try it again without first directory (okay, this may look + // a bit weird, but usually this is the correct icon path in the jar) + final URL strippedImageResource = GUIUtils.class.getClassLoader().getResource(dirUri.substring(slashIndex + 1) + '/' + strIconName); + if (strippedImageResource != null) { + icon = new ImageIcon(strippedImageResource); + } else { + icon = null; + } + } else { + icon = null; + } + } + } + + // put this icon into the Hashtable + if (icon != null) { + imageCache.put(strIconName, icon); + } else { + log.warn("Failed to load icon '" + strIconName + "'!"); + } + + return icon; + } + + /** + * Returns the specified icon as a normal icon resource. + * @param strIconName Name of the icon to return. + * @return The icon or <code>null</code> if the icon couldn't be loaded. + */ + @Nullable + public static ImageIcon getIcon(final String strIconName) { + return getResourceIcon(GUIConstants.ICON_DIR, strIconName); + } + + /** + * Returns the specified icon as a system icon resource. + * @param strIconName Name of the icon to return. + * @return The icon or <code>null</code> if the icon couldn't be loaded. + */ + @Nullable + public static ImageIcon getSysIcon(final String strIconName) { + return getResourceIcon(GUIConstants.SYSTEM_DIR, strIconName); + } + +} // class GUIUtils Property changes on: trunk/src/app/net/sf/gridarta/gui/utils/GUIUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/gui/utils/MenuUtils.java (from rev 4737, trunk/src/app/net/sf/gridarta/gui/MenuHelper.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/MenuUtils.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/utils/MenuUtils.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -0,0 +1,82 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.utils; + +import java.awt.Component; +import javax.swing.AbstractButton; +import javax.swing.JMenu; +import javax.swing.JSeparator; +import javax.swing.MenuElement; + +/** + * Utility class implementing menu related functions. + * @author Andreas Kirschbaum + */ +@SuppressWarnings({"ClassNamingConvention"}) +public class MenuUtils { + + /** Private constructor to prevent instantiation. */ + private MenuUtils() { + } + + /** + * Remove all actions attached to menu entries in a given menu element and + * its children. + * @param menuElement the menu element to process + */ + public static void disposeMenuElement(final MenuElement menuElement) { + if (menuElement instanceof AbstractButton) { + ((AbstractButton) menuElement).setAction(null); + } + + for (final MenuElement child : menuElement.getSubElements()) { + disposeMenuElement(child); + } + } + + /** + * Remove all menu entries. + * @param menu the menu to remove the entries from + */ + public static void removeAll(final JMenu menu) { + for (final MenuElement child : menu.getSubElements()) { + disposeMenuElement(child); + } + menu.removeAll(); + } + + /** + * Remove all menu entries up to (but not including) the first separator. + * @param menu the menu to remove the entries from + */ + public static void removeAllToSeparator(final JMenu menu) { + for (; ;) { + final Component menuItem = menu.getMenuComponent(0); + if (menuItem == null || menuItem instanceof JSeparator) { + break; + } + menu.remove(0); + if (menuItem instanceof MenuElement) { + disposeMenuElement((MenuElement) menuItem); + } + } + } + +} // class MenuUtils Property changes on: trunk/src/app/net/sf/gridarta/gui/utils/MenuUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:mergeinfo + Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/treasurelist/TreasureCellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/treasurelist/TreasureCellRenderer.java 2008-08-03 21:05:44 UTC (rev 4741) +++ trunk/src/app/net/sf/gridarta/treasurelist/TreasureCellRenderer.java 2008-08-03 21:08:36 UTC (rev 4742) @@ -31,7 +31,7 @@ import net.sf.gridarta.gameobject.ArchetypeSet; import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.gui.GUIConstants; -import net.sf.gridarta.gui.GUIUtils; +import net.sf.gridarta.gui.utils.GUIUtils; import net.sf.gridarta.map.MapArchObject; import org.jetbrains.annotations.NotNull; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |