1 19 20 package org.netbeans.modules.welcome; 21 22 import java.lang.ref.WeakReference ; 23 import org.netbeans.modules.welcome.content.ContentPanel; 24 import org.openide.util.NbBundle; 25 import org.openide.windows.*; 26 import java.awt.*; 27 import javax.swing.*; 28 import org.netbeans.modules.welcome.content.ContentFactory; 29 import org.openide.ErrorManager; 30 import org.openide.nodes.Node; 31 32 36 public class WelcomeComponent extends TopComponent { 37 static final long serialVersionUID=6021472310161712674L; 38 private static WeakReference <WelcomeComponent> component = 39 new WeakReference <WelcomeComponent>(null); 40 private JComponent content; 41 42 private boolean initialized = false; 43 44 private WelcomeComponent(){ 45 setLayout(new BorderLayout()); 46 setName(NbBundle.getMessage(WelcomeComponent.class, "LBL_Tab_Title")); content = null; 48 initialized = false; 49 } 50 51 protected String preferredID(){ 52 return "WelcomeComponent"; } 54 55 58 59 private void doInitialize() { 60 initAccessibility(); 61 62 content = ContentFactory.createContentPane(); 63 if( null == content ) 64 return; 65 66 add( content, BorderLayout.CENTER ); 67 setFocusable( false ); 68 } 69 70 75 public static WelcomeComponent findComp() { 76 WelcomeComponent wc = component.get(); 77 if (wc == null) { 78 TopComponent tc = WindowManager.getDefault().findTopComponent("Welcome"); if (tc != null) { 80 if (tc instanceof WelcomeComponent) { 81 wc = (WelcomeComponent)tc; 82 component = new WeakReference <WelcomeComponent>(wc); 83 } else { 84 IllegalStateException exc = new IllegalStateException 86 ("Incorrect settings file. Unexpected class returned." + " Expected:" + WelcomeComponent.class.getName() + " Returned:" + tc.getClass().getName()); ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc); 90 wc = WelcomeComponent.createComp(); 92 } 93 } else { 94 wc = WelcomeComponent.createComp(); 97 } 98 } 99 return wc; 100 } 101 102 105 public static WelcomeComponent createComp() { 106 WelcomeComponent wc = (WelcomeComponent)component.get(); 107 if(wc == null) { 108 wc = new WelcomeComponent(); 109 component = new WeakReference <WelcomeComponent>(wc); 110 } 111 return wc; 112 } 113 114 116 public int getPersistenceType() { 117 return TopComponent.PERSISTENCE_NEVER; 118 } 119 120 private void initAccessibility(){ 121 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WelcomeComponent.class, "ACS_Welcome_DESC")); } 123 124 127 public void addNotify() { 128 if (!initialized) { 129 initialized = true; 130 doInitialize(); 131 } 132 super.addNotify(); 133 } 134 135 147 protected void componentShowing() { 148 if (!initialized) { 149 initialized = true; 150 doInitialize(); 151 } 152 super.componentShowing(); 153 setActivatedNodes( new Node[] {} ); 154 } 155 156 private static boolean firstTimeOpen = true; 157 protected void componentOpened() { 158 super.componentOpened(); 159 if( firstTimeOpen ) { 160 firstTimeOpen = false; 161 if( !WelcomeOptions.getDefault().isShowOnStartup() ) { 162 close(); 163 } 164 } 165 } 166 167 protected void componentActivated() { 168 super.componentActivated(); 169 focusAnyContentPanel( content ); 170 } 171 172 private boolean focusAnyContentPanel( Container comp ) { 173 Component[] children = comp.getComponents(); 174 for( int i=0; i<children.length; i++ ) { 175 if( children[i] instanceof ContentPanel ) { 176 ((ContentPanel)children[i]).switchFocus(); 177 return true; 178 } else if( children[i] instanceof Container 179 && focusAnyContentPanel( (Container)children[i] ) ) { 180 return true; 181 } 182 } 183 return false; 184 } 185 } 186 187 | Popular Tags |