KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > NbPlatformCustomizerSourcesTest


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.apisupport.project.ui.platform;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.EventQueue JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import org.netbeans.modules.apisupport.project.TestBase;
29 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
30
31 /**
32  * @author Martin Krauskopf
33  */

34 public class NbPlatformCustomizerSourcesTest extends TestBase {
35
36     private JFrame JavaDoc frame;
37     private NbPlatformCustomizerSources sourcesPane;
38     private JPanel JavaDoc outerPane;
39     private WeakReference JavaDoc sourcesPaneWR;
40     
41     public NbPlatformCustomizerSourcesTest(String JavaDoc testName) {
42         super(testName);
43     }
44     
45     public void testMemoryLeak_70032() throws Exception JavaDoc {
46         EventQueue.invokeAndWait(new Runnable JavaDoc() {
47             public void run() {
48                 sourcesPane = new NbPlatformCustomizerSources();
49                 sourcesPaneWR = new WeakReference JavaDoc(sourcesPane);
50                 sourcesPane.setPlatform(NbPlatform.getDefaultPlatform());
51                 
52                 // workaround for inability to GC JFrame/JDialog itself
53
outerPane = new JPanel JavaDoc();
54                 outerPane.add(sourcesPane);
55                 
56                 frame = new JFrame JavaDoc("testMemoryLeak_70032");
57                 frame.getContentPane().setLayout(new BorderLayout JavaDoc());
58                 frame.getContentPane().add(outerPane, BorderLayout.CENTER);
59                 frame.pack();
60                 // NOTE: we have to show the frame to take combobox renderers into the game
61
frame.setVisible(true);
62                 frame.getContentPane().remove(outerPane);
63                 
64                 // prevents KeyboardFocusManager.permanentFocusOwner to hold us
65
JLabel JavaDoc dummyFocusEater = new JLabel JavaDoc();
66                 frame.getContentPane().add(dummyFocusEater);
67                 dummyFocusEater.requestFocus();
68                 frame.setVisible(false);
69                 frame.dispose();
70             }
71         });
72         outerPane = null;
73         sourcesPane = null;
74         
75         assertGC("GCing sourcesPane", sourcesPaneWR);
76     }
77     
78 }
79
Popular Tags