1 19 20 package org.netbeans.modules.j2ee.blueprints; 21 22 import java.lang.ref.WeakReference ; 23 import org.openide.util.NbBundle; 24 import org.openide.*; 25 import org.openide.windows.*; 26 27 import java.io.*; 28 import java.awt.*; 29 import java.lang.reflect.Method ; 30 import javax.swing.*; 31 import javax.accessibility.*; 32 import org.openide.ErrorManager; 33 34 38 class BluePrintsComponent extends TopComponent{ 39 static final long serialVersionUID=6021472310161712674L; 40 41 private static WeakReference component = 42 new WeakReference (null); 43 44 private JComponent panel; 45 46 private boolean initialized = false; 47 48 private BluePrintsComponent(){ 49 setLayout(new BorderLayout()); 50 setName(NbBundle.getMessage(BluePrintsComponent.class, "LBL_Tab_Title")); panel = null; 52 initialized = false; 53 } 54 55 protected String preferredID(){ 56 return "BluePrints"; } 58 59 62 63 private void doInitialize() { 64 initAccessibility(); 65 66 try{ 67 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 68 panel =(JComponent)Class.forName(NbBundle.getMessage( 69 BluePrintsComponent.class,"CLASS_content_panel"), true, cl).newInstance(); 70 }catch(Exception e){ 72 ErrorManager.getDefault().notify(e); 73 } 74 if(panel == null) 75 return; 76 77 add(panel); 79 setFocusable(true); 80 } 81 82 87 public static BluePrintsComponent findComp() { 88 BluePrintsComponent wc = (BluePrintsComponent)component.get(); 89 if (wc == null) { 90 TopComponent tc = WindowManager.getDefault().findTopComponent("BluePrints"); if (tc != null) { 92 if (tc instanceof BluePrintsComponent) { 93 wc = (BluePrintsComponent)tc; 94 component = new WeakReference (wc); 95 } else { 96 IllegalStateException exc = new IllegalStateException 98 ("Incorrect settings file. Unexpected class returned." + " Expected:" + BluePrintsComponent.class.getName() + " Returned:" + tc.getClass().getName()); ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc); 102 wc = BluePrintsComponent.createComp(); 104 } 105 } else { 106 wc = BluePrintsComponent.createComp(); 109 } 110 } 111 return wc; 112 } 113 114 117 public static BluePrintsComponent createComp() { 118 BluePrintsComponent wc = (BluePrintsComponent)component.get(); 119 if(wc == null) { 120 wc = new BluePrintsComponent(); 121 component = new WeakReference (wc); 122 } 123 return wc; 124 } 125 126 128 public int getPersistenceType() { 129 return TopComponent.PERSISTENCE_ALWAYS; 130 } 131 132 static void clearRef(){ 133 component.clear(); 134 } 135 136 private void initAccessibility(){ 137 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BluePrintsComponent.class, "ACS_BluePrints_DESC")); } 139 140 public void requestFocus(){ 141 super.requestFocus(); 142 panel.requestFocus(); 143 } 144 145 148 public void addNotify() { 149 if (!initialized) { 150 initialized = true; 151 doInitialize(); 152 } 153 super.addNotify(); 154 } 155 156 168 protected void componentShowing() { 169 if (!initialized) { 170 initialized = true; 171 doInitialize(); 172 } 173 super.componentShowing(); 174 } 175 176 } 177 178 | Popular Tags |