KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > NBGlassPaneAccessSupport


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * InplaceEditingSupport.java
22  *
23  * Created on May 24, 2006, 3:08 AM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.Component JavaDoc;
32 import java.awt.LayoutManager JavaDoc;
33 import javax.swing.JFrame JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35
36 /**
37  *
38  * @author girix
39  */

40 public class NBGlassPaneAccessSupport {
41     
42     private static JPanel JavaDoc NB_GLASS_PANE = null;
43     private static JPanel JavaDoc glass ;
44     private static LayoutManager JavaDoc previousLayout;
45     private static JFrame JavaDoc NBFRAME;
46     
47     private static JPanel JavaDoc _getGlassPane(Component JavaDoc leaf){
48         if(NB_GLASS_PANE == null){
49             //get fresh glass pane
50
Component JavaDoc current = leaf;
51             while( (current != null) && !(current instanceof JFrame JavaDoc) )
52                 current = current.getParent();
53             if(current == null)
54                 return null;
55             NB_GLASS_PANE = (JPanel JavaDoc) ((JFrame JavaDoc) current).getGlassPane();
56             NBFRAME = (JFrame JavaDoc) current;
57             return NB_GLASS_PANE;
58         }else{
59             //check if the glass pane is still valid
60
if(NB_GLASS_PANE.getParent() instanceof JFrame JavaDoc){
61                 //has frame as root. So valid just return.
62
return NB_GLASS_PANE;
63             }else{
64                 //parent is not a frame. Obtain glass pane again.
65
NB_GLASS_PANE = null;
66                 return _getGlassPane(leaf);
67             }
68         }
69     }
70     
71     
72     public static JPanel JavaDoc getNBGlassPane(Component JavaDoc leaf){
73         glass = _getGlassPane(leaf);
74         if(glass == null)
75             return null;
76         previousLayout = glass.getLayout();
77         glass.setLayout(null);
78         return glass;
79     }
80     
81     public static JPanel JavaDoc getCleanNBGlassPane(Component JavaDoc leaf){
82         forceDisposeNBGlassPane();
83         return getNBGlassPane(leaf);
84     }
85     
86     public static void disposeNBGlassPane(){
87         if(glass == null)
88             return;
89         glass.setVisible(false);
90         for(Component JavaDoc comp: glass.getComponents()){
91             glass.remove(comp);
92         }
93         glass.setLayout(previousLayout);
94     }
95     
96     public static void forceDisposeNBGlassPane(){
97         JPanel JavaDoc glass = NB_GLASS_PANE;
98         if(glass == null)
99             return;
100         glass.setVisible(false);
101         for(Component JavaDoc comp: glass.getComponents()){
102             glass.remove(comp);
103         }
104         glass.setLayout(previousLayout);
105     }
106     
107     public static JPanel JavaDoc getCurrentShowingPane(){
108         return glass;
109     }
110     
111     public static JFrame JavaDoc getNBFRAME(Component JavaDoc leaf){
112         if(NBFRAME != null)
113             return NBFRAME;
114         _getGlassPane(leaf);
115         return NBFRAME;
116     }
117     
118 }
119
Popular Tags