Revision: 3642
http://fudaa.svn.sourceforge.net/fudaa/?rev=3642&view=rev
Author: bmarchan
Date: 2008-06-18 02:00:45 -0700 (Wed, 18 Jun 2008)
Log Message:
-----------
Ajout de methodes d'acc?\195?\168s aux menus par la commande d'action.
Modified Paths:
--------------
branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenu.java
branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenuBar.java
Modified: branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenu.java
===================================================================
--- branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenu.java 2008-06-18 08:51:48 UTC (rev 3641)
+++ branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenu.java 2008-06-18 09:00:45 UTC (rev 3642)
@@ -320,7 +320,26 @@
{
return addMenuItem(_s,_cmd,true);
}
+
+ /**
+ * Retourne l'index de l'item de commande donn\xE9e.
+ * @param _cmd Le nom de la commande.
+ * @return L'index, ou -1 si non trouv\xE9.
+ */
+ public int indexOf(String _cmd) {
+ return indexOf(this,_cmd);
+ }
+ private int indexOf(BuMenu _menu, String _cmd) {
+ if (_cmd==null) return -1;
+
+ for (int i=0; i<_menu.getItemCount(); i++) {
+ if (!(_menu.getItem(i) instanceof JMenuItem)) continue;
+ if (_cmd.equals(_menu.getItem(i).getActionCommand())) return i;
+ }
+ return -1;
+ }
+
public BuMenuItem addMenuItem(String _s, String _cmd,
ActionListener _al)
{
Modified: branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenuBar.java
===================================================================
--- branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenuBar.java 2008-06-18 08:51:48 UTC (rev 3641)
+++ branches/Br_FudaaModeleur_TF/fudaa_devel/ctulu/src/com/memoire/bu/BuMenuBar.java 2008-06-18 09:00:45 UTC (rev 3642)
@@ -22,6 +22,7 @@
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import com.memoire.fu.FuFactoryInteger;
@@ -232,22 +233,55 @@
return getMenuItem(this,_name);
}
- /*
- public void removeMenu(String _name)
+ /**
+ * Retourne le menu qui contient l'item de commande donn\xE9e, recursivement a
+ * partir de la barre de menus.
+ * @param _cmd La commande
+ * @return Le menu
+ */
+ public JMenu getMenuForAction(String _cmd)
{
- MenuElement[] c=getSubElements();
- for(int i=0; i<c.length; i++)
- if(c[i] instanceof JMenu)
- {
- JMenu m=(JMenu)c[i];
- if(m.getName().equals("mn"+_name))
- remove(m);
+ return getMenuForAction(this,_cmd);
+ }
+
+ /**
+ * Retourne le menu qui contient l'item de commande donn\xE9e, recursivement a
+ * partir du menu en parametres.
+ * @param _cmd La commande
+ * @return Le menu
+ */
+ public static JMenu getMenuForAction(MenuElement _menu, String _cmd) {
+ if (_cmd==null) return null;
+
+ JMenu r=null;
+
+ MenuElement[] c=_menu.getSubElements();
+
+ for (int i=0; i<c.length; i++) {
+ if (c[i] instanceof JMenuItem) {
+ JMenuItem m=(JMenuItem)c[i];
+
+ if (m.getActionCommand().equals(_cmd)) {
+ r=(JMenu)((JPopupMenu)m.getParent()).getInvoker();
+ break;
+ }
}
- doLayout();
- validate();
+
+ r=getMenuForAction(c[i], _cmd);
+ if (r!=null)
+ break;
+ }
+
+ return r;
}
- */
+ /*
+ * public void removeMenu(String _name) { MenuElement[] c=getSubElements();
+ * for(int i=0; i<c.length; i++) if(c[i] instanceof JMenu) { JMenu
+ * m=(JMenu)c[i]; if(m.getName().equals("mn"+_name)) remove(m); } doLayout();
+ * validate(); }
+ */
+
public void addRecentFile(String _path, String _icon)
{
BuMenu m=(BuMenu)getMenu("REOUVRIR");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|