1 26 27 package org.objectweb.util.browser.core.popup; 28 29 30 import java.awt.event.ActionEvent ; 31 32 import javax.swing.AbstractAction ; 33 import javax.swing.Icon ; 34 import javax.swing.JOptionPane ; 35 import javax.swing.KeyStroke ; 36 37 38 import org.objectweb.util.browser.api.MenuItem; 39 import org.objectweb.util.browser.api.MenuItemTreeView; 40 import org.objectweb.util.browser.core.api.MenuItemTreeViewConfiguration; 41 import org.objectweb.util.browser.core.common.DynamicTree; 42 43 49 public class DefaultAction extends AbstractAction { 50 51 protected DynamicTree tree_ = null; 52 protected MenuItem delegate_ = null; 53 protected MenuItemTreeView treeView_ = null; 54 protected boolean isUserIcon_ = false; 55 56 protected void init(DynamicTree tree, MenuItem actionListener, MenuItemTreeView treeView){ 57 tree_ = tree; 58 delegate_ = actionListener; 59 treeView_ = treeView; 60 } 61 62 public DefaultAction(DynamicTree tree, MenuItem actionListener, MenuItemTreeView treeView, String name, Icon icon, KeyStroke keyStroke, Character mnemonic, boolean isUserIcon, int itemState) { 63 super(name, icon); 64 init(tree,actionListener,treeView); 65 putValue(SHORT_DESCRIPTION, name); 67 if(mnemonic!=null){ 69 putValue(MNEMONIC_KEY, new Integer (Character.toUpperCase(mnemonic.charValue()))); 70 } 71 if(keyStroke!=null){ 73 putValue(ACCELERATOR_KEY, keyStroke); 74 } 75 isUserIcon_ = isUserIcon; 76 if (itemState == MenuItem.DISABLED_STATUS) 77 setEnabled(false); 78 } 79 80 public boolean isUserIcon(){ 81 return isUserIcon_; 82 } 83 84 public void actionPerformed(ActionEvent e) { 85 try { 86 ((MenuItemTreeViewConfiguration)treeView_).setActionEvent(e); 87 delegate_.actionPerformed(treeView_); 88 } catch (Exception e1) { 89 JOptionPane.showMessageDialog(null, e1.getClass().getName() + ":\n" + e1.getMessage(), "Exception (" + e.getActionCommand() + ")", JOptionPane.ERROR_MESSAGE); 91 } 92 tree_.refreshAll(); 93 } 94 95 } 96 | Popular Tags |