KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > IconView


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 package org.openide.explorer.view;
20
21 import org.openide.awt.ListPane;
22 import org.openide.explorer.*;
23 import org.openide.nodes.*;
24
25 import java.awt.*;
26 import java.awt.event.*;
27
28 import java.beans.*;
29
30 import java.io.*;
31
32 import javax.swing.*;
33
34
35 /* TODO:
36  - improve cell renderer (two lines of text or hints)
37  - better behaviour during scrolling (ListPane)
38  - external selection bug (BUG ID: 01110034)
39  -
40  - XXX if doing anything with this class other than deleting it, rewrite it to use a JTable - that would be
41  - much more sensible and scalable. -Tim
42  -
43 */

44
45 /** A view displaying {@link Node}s as icons.
46  * <p>
47  * This class is a <q>view</q>
48  * to use it properly you need to add it into a component which implements
49  * {@link Provider}. Good examples of that can be found
50  * in {@link ExplorerUtils}. Then just use
51  * {@link Provider#getExplorerManager} call to get the {@link ExplorerManager}
52  * and control its state.
53  * </p>
54  * <p>
55  * There can be multiple <q>views</q> under one container implementing {@link Provider}. Select from
56  * range of predefined ones or write your own:
57  * </p>
58  * <ul>
59  * <li>{@link org.openide.explorer.view.BeanTreeView} - shows a tree of nodes</li>
60  * <li>{@link org.openide.explorer.view.ContextTreeView} - shows a tree of nodes without leaf nodes</li>
61  * <li>{@link org.openide.explorer.view.ListView} - shows a list of nodes</li>
62  * <li>{@link org.openide.explorer.view.IconView} - shows a rows of nodes with bigger icons</li>
63  * <li>{@link org.openide.explorer.view.ChoiceView} - creates a combo box based on the explored nodes</li>
64  * <li>{@link org.openide.explorer.view.TreeTableView} - shows tree of nodes together with a set of their {@link Property}</li>
65  * <li>{@link org.openide.explorer.view.MenuView} - can create a {@link JMenu} structure based on structure of {@link Node}s</li>
66  * </ul>
67  * <p>
68  * All of these views use {@link ExplorerManager#find} to walk up the AWT hierarchy and locate the
69  * {@link ExplorerManager} to use as a controler. They attach as listeners to
70  * it and also call its setter methods to update the shared state based on the
71  * user action. Not all views make sence together, but for example
72  * {@link org.openide.explorer.view.ContextTreeView} and {@link org.openide.explorer.view.ListView} were designed to complement
73  * themselves and behaves like windows explorer. The {@link org.openide.explorer.propertysheet.PropertySheetView}
74  * for example should be able to work with any other view.
75  * </p>
76  *
77  * @author Jaroslav Tulach
78  */

79 public class IconView extends ListView implements Externalizable {
80     /** generated Serialized Version UID */
81     static final long serialVersionUID = -9129850245819731264L;
82
83     public IconView() {
84     }
85
86     /** Creates the list that will display the data.
87     */

88     protected JList createList() {
89         JList list = new ListPane() {
90                 /**
91                  * Overrides JComponent's getToolTipText method in order to allow
92                  * renderer's tips to be used if it has text set.
93                  * @param event the MouseEvent that initiated the ToolTip display
94                  */

95                 public String JavaDoc getToolTipText(MouseEvent event) {
96                     if (event != null) {
97                         Point p = event.getPoint();
98                         int index = locationToIndex(p);
99
100                         if (index >= 0) {
101                             VisualizerNode v = (VisualizerNode) getModel().getElementAt(index);
102                             String JavaDoc tooltip = v.getShortDescription();
103                             String JavaDoc displayName = v.getDisplayName();
104
105                             if ((tooltip != null) && !tooltip.equals(displayName)) {
106                                 return tooltip;
107                             }
108                         }
109                     }
110
111                     return null;
112                 }
113             };
114
115         list.setCellRenderer(new NodeRenderer());
116
117         return list;
118     }
119 }
120
Popular Tags