KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > palette > DefaultItem


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.palette;
21
22 import java.awt.Image JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.io.IOException JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import org.openide.ErrorManager;
28 import org.openide.util.Lookup;
29 import org.openide.nodes.*;
30
31
32 /**
33  * Default implementation of PaletteItem interface based on Nodes.
34  *
35  * @author S. Aubrecht
36  */

37 public class DefaultItem implements Item {
38
39     private Node itemNode;
40
41     /**
42      * Creates a new instance of DefaultPaletteItem
43      *
44      * @param itemNode Node representing the palette item.
45      */

46     public DefaultItem( Node itemNode ) {
47         this.itemNode = itemNode;
48     }
49
50     public String JavaDoc getName() {
51         return itemNode.getName();
52     }
53     
54     public Image JavaDoc getIcon(int type) {
55         return itemNode.getIcon( type );
56     }
57
58     public Action JavaDoc[] getActions() {
59         return itemNode.getActions( false );
60     }
61
62     public String JavaDoc getShortDescription() {
63         return itemNode.getShortDescription();
64     }
65
66     public String JavaDoc getDisplayName() {
67         return itemNode.getDisplayName();
68     }
69
70     public void invokePreferredAction( ActionEvent JavaDoc e ) {
71         Action JavaDoc 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 JavaDoc obj) {
82         if( null == obj || !(obj instanceof DefaultItem) )
83             return false;
84         
85         return itemNode.equals( ((DefaultItem) obj).itemNode );
86     }
87
88     public Transferable JavaDoc drag() {
89         try {
90             return itemNode.drag();
91         } catch( IOException JavaDoc ioE ) {
92             ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, ioE );
93         }
94         return null;
95     }
96
97     public Transferable JavaDoc cut() {
98         try {
99             return itemNode.clipboardCut();
100         } catch( IOException JavaDoc ioE ) {
101             ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, ioE );
102         }
103         return null;
104     }
105     
106     public String JavaDoc toString() {
107         return itemNode.getDisplayName();
108     }
109 }
110
Popular Tags