KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > annotate > AnnotationBarManager


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.versioning.system.cvss.ui.actions.annotate;
21
22 import org.netbeans.editor.SideBarFactory;
23
24 import javax.swing.*;
25 import javax.swing.text.JTextComponent JavaDoc;
26
27 /**
28  * Binds annotation action and editor sidebars support.
29  *
30  * <p>It's registered in module layer into
31  * <tt>Editors/text/base/SideBar</tt> registry.
32  *
33  * @author Petr Kuzel
34  */

35 public final class AnnotationBarManager implements SideBarFactory {
36
37     private static final Object JavaDoc BAR_KEY = new Object JavaDoc();
38
39     /**
40      * Creates initially hidden annotations sidebar.
41      * It's called once by target lifetime.
42      */

43     public JComponent createSideBar(JTextComponent JavaDoc target) {
44         final AnnotationBar ab = new AnnotationBar(target);
45         target.putClientProperty(BAR_KEY, ab);
46         return ab;
47     }
48
49     /**
50      * Shows annotations sidebar.
51      */

52     public static AnnotationBar showAnnotationBar(JTextComponent JavaDoc target) {
53         AnnotationBar ab = (AnnotationBar) target.getClientProperty(BAR_KEY);
54         assert ab != null: "#58828 reappeared!"; // NOI18N
55
ab.annotate();
56         return ab;
57     }
58
59     /**
60      * Shows annotations sidebar.
61      */

62     public static void hideAnnotationBar(JTextComponent JavaDoc target) {
63         if (target == null) return;
64         AnnotationBar ab = (AnnotationBar) target.getClientProperty(BAR_KEY);
65         assert ab != null: "#58828 reappeared!"; // NOI18N
66
ab.hideBar();
67     }
68
69     /**
70      * Tests wheteher given editor shows annotations.
71      */

72     public static boolean annotationBarVisible(JTextComponent JavaDoc target) {
73         if (target == null) return false;
74         AnnotationBar ab = (AnnotationBar) target.getClientProperty(BAR_KEY);
75         if (ab == null) {
76             return false;
77         }
78         return ab.getPreferredSize().width > 0;
79     }
80 }
81
Popular Tags