1 19 20 package org.netbeans.modules.palette; 21 22 import java.awt.Image ; 23 import java.awt.datatransfer.Transferable ; 24 import java.awt.event.ActionEvent ; 25 import java.io.IOException ; 26 import javax.swing.Action ; 27 import org.openide.ErrorManager; 28 import org.openide.util.Lookup; 29 import org.openide.nodes.*; 30 31 32 37 public class DefaultItem implements Item { 38 39 private Node itemNode; 40 41 46 public DefaultItem( Node itemNode ) { 47 this.itemNode = itemNode; 48 } 49 50 public String getName() { 51 return itemNode.getName(); 52 } 53 54 public Image getIcon(int type) { 55 return itemNode.getIcon( type ); 56 } 57 58 public Action [] getActions() { 59 return itemNode.getActions( false ); 60 } 61 62 public String getShortDescription() { 63 return itemNode.getShortDescription(); 64 } 65 66 public String getDisplayName() { 67 return itemNode.getDisplayName(); 68 } 69 70 public void invokePreferredAction( ActionEvent e ) { 71 Action action = itemNode.getPreferredAction(); 72 if( null != action && action.isEnabled() ) { 73 action.actionPerformed( e ); 74 } 75 } 76 77 public Lookup getLookup() { 78 return itemNode.getLookup(); 79 } 80 81 public boolean equals(Object obj) { 82 if( null == obj || !(obj instanceof DefaultItem) ) 83 return false; 84 85 return itemNode.equals( ((DefaultItem) obj).itemNode ); 86 } 87 88 public Transferable drag() { 89 try { 90 return itemNode.drag(); 91 } catch( IOException ioE ) { 92 ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, ioE ); 93 } 94 return null; 95 } 96 97 public Transferable cut() { 98 try { 99 return itemNode.clipboardCut(); 100 } catch( IOException ioE ) { 101 ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, ioE ); 102 } 103 return null; 104 } 105 106 public String toString() { 107 return itemNode.getDisplayName(); 108 } 109 } 110 | Popular Tags |