KickJava   Java API By Example, From Geeks To Geeks.

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


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.nodes.Node;
22
23 import javax.swing.tree.*;
24
25
26 /** This class provide access to thread safe layer that
27 * reflects the hierarchy of Nodes, but is updated only in
28 * event dispatch thread (in contrast to nodes that can be updated from any thread).
29 * That is why this class is useful for writers of explorer views,
30 * because it guarantees that all changes will be done safely.
31 * <P>
32 * NodeTreeModel, NodeListModel, etc. use these objects as its
33 * model values.
34 *
35 * @author Jaroslav Tulach
36 */

37 public class Visualizer extends Object JavaDoc {
38     /** No constructor. */
39     private Visualizer() {
40     }
41
42     /** Methods that create a tree node for given node.
43     * The tree node reflects the state of the associated node as close
44     * as possible, but is updated asynchronously in event dispatch thread.
45     * <P>
46     * This method can be called only from AWT-Event dispatch thread.
47     *
48     * @param node node to create safe representant for
49     * @return tree node that represents the node
50     */

51     public static TreeNode findVisualizer(Node node) {
52         return VisualizerNode.getVisualizer(null, node);
53     }
54
55     /** Converts visualizer object back to its node representant.
56     *
57     * @param visualizer visualizer create by findVisualizer method
58     * @return node associated with the visualizer
59     * @exception ClassCastException if the parameter is invalid
60     */

61     public static Node findNode(Object JavaDoc visualizer) {
62         if (visualizer instanceof Node) {
63             return (Node) visualizer;
64         } else {
65             return ((VisualizerNode) visualizer).node;
66         }
67     }
68 }
69
Popular Tags