1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 import java.awt.event.MouseEvent ; 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.aspects.gui.DisplayContext; 26 import org.objectweb.jac.aspects.gui.GuiAC; 27 import org.objectweb.jac.aspects.gui.ResourceManager; 28 import org.objectweb.jac.core.rtti.ClassItem; 29 import org.objectweb.jac.core.rtti.ClassRepository; 30 import org.objectweb.jac.core.rtti.MethodItem; 31 32 35 public class SwingEvents { 36 static Logger logger = Logger.getLogger("gui.events"); 37 38 46 public static void showObjectMenu(DisplayContext context, Object object, 47 MouseEvent event) 48 { 49 showObjectsMenu(context,new Object [] {object}, event); 50 } 51 52 60 public static void showObjectsMenu(DisplayContext context, Object [] objects, 61 MouseEvent event) 62 { 63 logger.debug("showObjectsMenu for "+Arrays.asList(objects)); 64 ObjectPopup dynPopup = new ObjectPopup(context); 65 for (int o=0; o<objects.length; o++) { 66 ClassItem cli = ClassRepository.get().getClass(objects[o]); 67 68 dynPopup.addViewItem(objects[o],"View "+cli.getShortName(), 69 ResourceManager.getIconResource("view_icon")); 70 71 MethodItem[] menu = GuiAC.getMenu(cli); 72 logger.debug(" menu for "+objects[o]+":"+Arrays.asList(menu)); 73 74 if (menu != null) { 75 if (menu.length>0) 76 dynPopup.addSeparator(); 77 for (int i=0; i<menu.length; i++) { 78 if (menu[i] == null) { 79 dynPopup.addSeparator(); 80 } else { 81 String icon = GuiAC.getIcon(menu[i]); 82 if (icon==null) { 83 icon = ResourceManager.getResource("blank_icon"); 84 } 85 dynPopup.addMethodItem(objects[o],menu[i],icon); 86 } 87 } 88 } else { 89 Collection meths = cli.getMethods(); 90 if (meths.size()>0) 91 dynPopup.addSeparator(); 92 Iterator it = meths.iterator(); 93 while (it.hasNext()) { 94 MethodItem mi = ((MethodItem[])it.next())[0]; 95 if (mi.isGetter() || mi.isRemover() || mi.isJacMethod()) 97 continue; 98 String icon = GuiAC.getIcon(mi); 99 if (icon==null) { 100 icon = ResourceManager.getResource("blank_icon"); 101 } 102 dynPopup.addMethodItem(objects[o],mi,icon); 103 } 104 } 105 if (o+1<objects.length) 106 dynPopup.addSeparator(); 107 } 108 dynPopup.show(event.getComponent(), event.getX(), event.getY()); 109 } 110 } 111 | Popular Tags |