001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.openide.explorer.view;
042:
043: import org.openide.awt.ListPane;
044: import org.openide.explorer.*;
045: import org.openide.nodes.*;
046:
047: import java.awt.*;
048: import java.awt.event.*;
049:
050: import java.beans.*;
051:
052: import java.io.*;
053:
054: import javax.swing.*;
055:
056: /* TODO:
057: - improve cell renderer (two lines of text or hints)
058: - better behaviour during scrolling (ListPane)
059: - external selection bug (BUG ID: 01110034)
060: -
061: - XXX if doing anything with this class other than deleting it, rewrite it to use a JTable - that would be
062: - much more sensible and scalable. -Tim
063: -
064: */
065:
066: /** A view displaying {@link Node}s as icons.
067: * <p>
068: * This class is a <q>view</q>
069: * to use it properly you need to add it into a component which implements
070: * {@link Provider}. Good examples of that can be found
071: * in {@link ExplorerUtils}. Then just use
072: * {@link Provider#getExplorerManager} call to get the {@link ExplorerManager}
073: * and control its state.
074: * </p>
075: * <p>
076: * There can be multiple <q>views</q> under one container implementing {@link Provider}. Select from
077: * range of predefined ones or write your own:
078: * </p>
079: * <ul>
080: * <li>{@link org.openide.explorer.view.BeanTreeView} - shows a tree of nodes</li>
081: * <li>{@link org.openide.explorer.view.ContextTreeView} - shows a tree of nodes without leaf nodes</li>
082: * <li>{@link org.openide.explorer.view.ListView} - shows a list of nodes</li>
083: * <li>{@link org.openide.explorer.view.IconView} - shows a rows of nodes with bigger icons</li>
084: * <li>{@link org.openide.explorer.view.ChoiceView} - creates a combo box based on the explored nodes</li>
085: * <li>{@link org.openide.explorer.view.TreeTableView} - shows tree of nodes together with a set of their {@link Property}</li>
086: * <li>{@link org.openide.explorer.view.MenuView} - can create a {@link JMenu} structure based on structure of {@link Node}s</li>
087: * </ul>
088: * <p>
089: * All of these views use {@link ExplorerManager#find} to walk up the AWT hierarchy and locate the
090: * {@link ExplorerManager} to use as a controler. They attach as listeners to
091: * it and also call its setter methods to update the shared state based on the
092: * user action. Not all views make sence together, but for example
093: * {@link org.openide.explorer.view.ContextTreeView} and {@link org.openide.explorer.view.ListView} were designed to complement
094: * themselves and behaves like windows explorer. The {@link org.openide.explorer.propertysheet.PropertySheetView}
095: * for example should be able to work with any other view.
096: * </p>
097: *
098: * @author Jaroslav Tulach
099: */
100: public class IconView extends ListView implements Externalizable {
101: /** generated Serialized Version UID */
102: static final long serialVersionUID = -9129850245819731264L;
103:
104: public IconView() {
105: }
106:
107: /** Creates the list that will display the data.
108: */
109: protected JList createList() {
110: JList list = new ListPane() {
111: /**
112: * Overrides JComponent's getToolTipText method in order to allow
113: * renderer's tips to be used if it has text set.
114: * @param event the MouseEvent that initiated the ToolTip display
115: */
116: public String getToolTipText(MouseEvent event) {
117: if (event != null) {
118: Point p = event.getPoint();
119: int index = locationToIndex(p);
120:
121: if (index >= 0) {
122: VisualizerNode v = (VisualizerNode) getModel()
123: .getElementAt(index);
124: String tooltip = v.getShortDescription();
125: String displayName = v.getDisplayName();
126:
127: if ((tooltip != null)
128: && !tooltip.equals(displayName)) {
129: return tooltip;
130: }
131: }
132: }
133:
134: return null;
135: }
136: };
137:
138: list.setCellRenderer(new NodeRenderer());
139:
140: return list;
141: }
142: }
|