KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > ResultWindow


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.junit.output;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.EventQueue JavaDoc;
25 import java.lang.ref.WeakReference JavaDoc;
26 import javax.accessibility.AccessibleContext JavaDoc;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import org.openide.util.Utilities;
30 import org.openide.windows.TopComponent;
31 import org.openide.windows.WindowManager;
32
33 /**
34  *
35  * @author Marian Petras
36  */

37 public final class ResultWindow extends TopComponent {
38     
39     /** unique ID of <code>TopComponent</code> (singleton) */
40     private static final String JavaDoc ID = "junit-test-results"; //NOI18N
41
/**
42      * instance/singleton of this class
43      *
44      * @see #getInstance
45      */

46     private static WeakReference JavaDoc<ResultWindow> instance = null;
47     
48     /**
49      * Returns a singleton of this class.
50      *
51      * @return singleton of this class
52      */

53     static synchronized ResultWindow getInstance() {
54         ResultWindow window;
55         window = (ResultWindow) WindowManager.getDefault().findTopComponent(ID);
56         if (window == null) {
57             window = getDefault();
58         }
59         return window;
60     }
61     
62     /**
63      * Singleton accessor reserved for the window system only.
64      * The window system calls this method to create an instance of this
65      * <code>TopComponent</code> from a <code>.settings</code> file.
66      * <p>
67      * <em>This method should not be called anywhere except from the window
68      * system's code.</em>
69      *
70      * @return singleton - instance of this class
71      */

72     public static synchronized ResultWindow getDefault() {
73         ResultWindow window = (instance != null) ? instance.get() : null;
74         if (window == null) {
75             window = new ResultWindow();
76             instance = new WeakReference JavaDoc<ResultWindow>(window);
77         }
78         return window;
79     }
80     
81     /** */
82     private Component JavaDoc view;
83     
84     
85     /** Creates a new instance of ResultWindow */
86     public ResultWindow() {
87         super();
88         setLayout(new BorderLayout JavaDoc());
89         //add(tabbedPanel = new JTabbedPane(), BorderLayout.CENTER);
90

91         setName(ID);
92         setDisplayName(NbBundle.getMessage(ResultWindow.class,
93                                            "TITLE_TEST_RESULTS")); //NOI18N
94
setIcon(Utilities.loadImage(
95                 "org/netbeans/modules/junit/output/res/testResults.png",//NOI18N
96
true));
97         
98         AccessibleContext JavaDoc accessibleContext = getAccessibleContext();
99         accessibleContext.setAccessibleName(
100                 NbBundle.getMessage(getClass(), "ACSN_TestResults")); //NOI18N
101
accessibleContext.setAccessibleDescription(
102                 NbBundle.getMessage(getClass(), "ACSD_TestResults")); //NOI18N
103
}
104     
105     /**
106      */

107     void addDisplayComponent(Component JavaDoc displayComp) {
108         assert EventQueue.isDispatchThread();
109         
110         removeAll();
111         addView(displayComp);
112     }
113     
114     /**
115      */

116     private void addView(final Component JavaDoc view) {
117         assert EventQueue.isDispatchThread();
118         
119         this.view = view;
120         add(view);
121     }
122     
123     /**
124      */

125     private boolean isActivated() {
126         return TopComponent.getRegistry().getActivated() == this;
127     }
128     
129     /**
130      */

131     void promote() {
132         assert EventQueue.isDispatchThread();
133         
134         open();
135         requestVisible();
136         requestActive();
137     }
138     
139     /**
140      */

141     protected String JavaDoc preferredID() {
142         return ID;
143     }
144     
145     /**
146      */

147     public HelpCtx getHelpCtx() {
148         return new HelpCtx(getClass());
149     }
150     
151     /**
152      */

153     public int getPersistenceType() {
154         return TopComponent.PERSISTENCE_ALWAYS;
155     }
156     
157     /**
158      * Resolves to the {@linkplain #getDefault default instance} of this class.
159      *
160      * This method is necessary for correct functinality of window system's
161      * mechanism of persistence of top components.
162      */

163     private Object JavaDoc readResolve() throws java.io.ObjectStreamException JavaDoc {
164         return ResultWindow.getDefault();
165     }
166     
167 }
168
Popular Tags