1 19 20 package org.netbeans.modules.javadoc.comments; 21 22 import java.io.*; 23 import java.awt.BorderLayout ; 24 import java.lang.ref.Reference ; 25 import java.lang.ref.SoftReference ; 26 27 import org.openide.windows.TopComponent; 28 import org.openide.util.HelpCtx; 29 import org.openide.util.NbBundle; 30 import org.openide.nodes.Node; 31 import org.openide.loaders.DataObject; 32 33 37 public final class AutoCommentTopComponent 38 extends TopComponent 39 implements Externalizable 40 { 41 42 static final String AUTO_COMMENT_HELP_CTX_KEY = "javadoc.auto.comment"; 44 45 private static Reference acTopComponent; 46 47 48 private transient AutoCommentPanel acPanel; 49 50 static final long serialVersionUID =3696398508351593122L; 51 52 53 private AutoCommentTopComponent() { 54 putClientProperty("TabPolicy", "HideWhenAlone"); setLayout( new BorderLayout () ); 57 add( acPanel = new AutoCommentPanel(), BorderLayout.CENTER ); 58 } 59 60 void setAutoCommenter( AutoCommenter aCommenter ) { 61 acPanel.setAutoCommenter( aCommenter ); 62 Node[] nodes = aCommenter.nodes; 64 String className = null; 65 if (nodes.length > 1 ) { 66 className = NbBundle.getMessage(AutoCommentTopComponent.class, "CTL_AUTOCOMMENT_MultipleSources"); } else if (nodes.length == 1) { 68 DataObject dobj = (DataObject) nodes[0].getLookup().lookup(DataObject.class); 69 if (dobj != null) { 70 className = dobj.getNodeDelegate().getDisplayName(); 71 } else { 72 className = nodes[0].getDisplayName(); 73 } 74 } else { 75 className = ""; } 77 setName(NbBundle.getMessage(AutoCommentTopComponent.class, "CTL_AUTOCOMMENT_WindowTitle") + " - " + className); } 79 80 protected void componentActivated() { 81 super.componentActivated(); 82 acPanel.activate(); 83 } 84 85 protected void componentDeactivated() { 86 super.componentDeactivated(); 87 if (this.isOpened()) { 88 acPanel.deactivate(); 89 } 90 } 91 92 protected void componentClosed() { 93 acPanel.deactivate(); 94 acPanel.setAutoCommenter(null); 95 super.componentClosed(); 96 } 97 98 public int getPersistenceType() { 99 return TopComponent.PERSISTENCE_NEVER; 100 } 101 102 protected String preferredID() { 103 return "AutoCommentTopComponent"; } 105 106 public static AutoCommentTopComponent getDefault() { 107 AutoCommentTopComponent actp; 108 if (acTopComponent == null || (actp = (AutoCommentTopComponent) acTopComponent.get()) == null) { 109 110 actp = new AutoCommentTopComponent(); 111 actp.getAccessibleContext().setAccessibleName(ResourceUtils.getBundledString("ACS_AutoCommentPanelA11yName")); actp.getAccessibleContext().setAccessibleDescription(ResourceUtils.getBundledString("ACS_AutoCommentPanelA11yDesc")); actp.setName(ResourceUtils.getBundledString ("CTL_AUTOCOMMENT_WindowTitle") ); acTopComponent = new SoftReference (actp); 115 } else { 116 actp = (AutoCommentTopComponent) acTopComponent.get(); 117 } 118 119 return actp; 120 } 121 122 public HelpCtx getHelpCtx () { 123 return new HelpCtx (AUTO_COMMENT_HELP_CTX_KEY); 124 } 125 126 128 129 protected Object writeReplace() { 130 return new Resolvable(); 131 } 132 133 static class Resolvable implements java.io.Serializable { 134 135 static final long serialVersionUID =8143238035030034549L; 136 private Object readResolve() { 137 AutoCommentTopComponent actp = getDefault(); 138 actp.setAutoCommenter( new AutoCommenter()); 139 return actp; 140 } 141 } 142 } 143 | Popular Tags |