KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > palette > DummyPalette


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.spi.palette;
21
22 import java.awt.Image JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.Node;
28 import org.openide.util.Utilities;
29
30
31 /**
32  *
33  * @author Stanislav Aubrecht
34  */

35 class DummyPalette {
36
37     private static final int CATEGORY_COUNT = 9;
38     private static final int ITEM_COUNT = 9;
39
40     /** Creates a new instance of DummyPalette */
41     private DummyPalette() {
42     }
43
44     public static Node createPaletteRoot() {
45         Children categories = new Children.Array();
46         categories.add( createCategories() );
47         return new RootNode( categories );
48     }
49     
50     private static Node[] createCategories() {
51         Node[] categories = new Node[ CATEGORY_COUNT ];
52         
53         for( int i=0; i<categories.length; i++ ) {
54             Children items = new Children.Array();
55             items.add( createItems() );
56             categories[i] = new CategoryNode( items, i );
57         }
58         return categories;
59     }
60     
61     private static Node[] createItems() {
62         Node[] items = new Node[ ITEM_COUNT ];
63         
64         for( int i=0; i<items.length; i++ ) {
65             items[i] = new ItemNode( i );
66         }
67         return items;
68     }
69
70     private static class RootNode extends AbstractNode {
71         public RootNode( Children children ) {
72             super( children );
73             setName( "DummyPalette" );
74         }
75     }
76     
77     private static class CategoryNode extends AbstractNode {
78         public CategoryNode( Children children, int index ) {
79             super( children );
80             setName( "Category_" + index );
81             setDisplayName( "CategoryName_" + index );
82             setShortDescription( "Short category description " + index );
83         }
84
85         public Image JavaDoc getIcon(int type) {
86
87             Image JavaDoc icon = null;
88             try {
89                 URL JavaDoc url = new URL JavaDoc("nbres:/javax/swing/beaninfo/images/JTabbedPaneColor16.gif");
90                 icon = java.awt.Toolkit.getDefaultToolkit().getImage(url);
91             } catch( MalformedURLException JavaDoc murlE ) {
92             }
93             return icon;
94         }
95     }
96     
97     private static class ItemNode extends AbstractNode {
98         
99         public ItemNode( int index ) {
100             super( Children.LEAF );
101             setName( "Item_" + index );
102             setDisplayName( "ItemName_" + index );
103             setShortDescription( "Short item description " + index );
104         }
105
106         public Image JavaDoc getIcon(int type) {
107
108             Image JavaDoc icon = null;
109             try {
110                 URL JavaDoc url = new URL JavaDoc("nbres:/javax/swing/beaninfo/images/JTabbedPaneColor16.gif");
111                 icon = java.awt.Toolkit.getDefaultToolkit().getImage(url);
112             } catch( MalformedURLException JavaDoc murlE ) {
113             }
114             return icon;
115         }
116     }
117 }
118
Popular Tags