1 19 package org.netbeans.modules.timers; 20 21 import java.awt.GridBagConstraints ; 22 import java.awt.GridBagLayout ; 23 import org.openide.ErrorManager; 24 import org.openide.util.NbBundle; 25 import org.openide.util.Utilities; 26 import org.openide.windows.TopComponent; 27 import org.openide.windows.WindowManager; 28 29 33 public class TimeComponent extends TopComponent { 34 35 private static final String PREFERRED_ID = "timers"; static final String ICON_PATH = "org/netbeans/modules/timers/resources/timer.png"; private static TimeComponent INSTANCE; 38 39 42 public TimeComponent() { 43 setName ("timers"); setDisplayName (NbBundle.getMessage ( TimeComponent.class, "LBL_TimeComponent" )); setIcon(Utilities.loadImage(ICON_PATH)); 46 47 setLayout(new GridBagLayout ()); 48 49 GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 50 51 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 52 gridBagConstraints.weightx = 1.0; 53 gridBagConstraints.weighty = 1.0; 54 55 add(new TimeComponentPanel(), gridBagConstraints); 56 } 57 58 public @Override String preferredID () { 59 return PREFERRED_ID; 60 } 61 62 63 public @Override int getPersistenceType () { 64 return PERSISTENCE_ALWAYS; 65 } 66 67 72 public static synchronized TimeComponent getDefault() { 73 if (INSTANCE == null) { 74 INSTANCE = new TimeComponent(); 75 } 76 return INSTANCE; 77 } 78 79 public static synchronized TimeComponent findInstance() { 80 TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); 81 if (win == null) { 82 ErrorManager.getDefault().log(ErrorManager.WARNING, 83 "Cannot find TimeComponent component. It will not be located properly in the window system."); 84 return getDefault(); 85 } 86 if (win instanceof TimeComponent) { 87 return (TimeComponent)win; 88 } 89 ErrorManager.getDefault().log(ErrorManager.WARNING, 90 "There seem to be multiple components with the '" + PREFERRED_ID + 91 "' ID. That is a potential source of errors and unexpected behavior."); 92 return getDefault(); 93 } 94 95 } 96 | Popular Tags |