package Templates.API_Support.Window_System_API; import org.openide.util.NbBundle; import org.openide.windows.*; import org.apache.log4j.*; /** * An openable window available to the IDE's window manager. * @author __USER__ */ public class __NAME__ extends TopComponent /* or CloneableTopComponent */ { private static Logger log = Logger.getLogger("LOGGER_Name"); /* Specifies a hint to the window system for generating a unique ID. There's no guarantee that this hint does anything. * It's generally just useful so you can recognize the name of the component if you are tracking down problems by looking * at the contents of the platform's $userdir/config/Windows2Local folder. ****************************************************************************************************************************************/ private static final String PREFF_ID = "mytab"; /* Specifies the actual ID of the instance. ****************************************************************************************************************************************/ private static String tcID = PREFF_ID; /* Specifies the mode where the component will be docked. Possibilities are: explorer, output, navigator, properties, and editor. ****************************************************************************************************************************************/ private static final String MODE = "editor"; // REMEMBER: You should have a public default constructor! // This is for externalization. If you have a nondefault // constructor for normal creation of the component, leave // in a default constructor that will put the component into // a consistent but unconfigured state, and make sure readExternal // initializes it properly. Or, be creative with writeReplace(). public __NAME__() { initComponents(); //setCloseOperation(CLOSE_LAST); // or CLOSE_EACH : This has been deprecated // Display name of this window (not needed if you use the DataObject constructor): setName(NbBundle.getMessage(__NAME__.class, "LBL_component_name")); // You may set the icon, but often it is better to set the icon for an associated mode instead: // setIcon(Utilities.loadImage("__PACKAGE_AND_NAME_SLASHES__Icon.gif", true)); // Use the Component Inspector to set tool-tip text. This will be saved // automatically. Other JComponent properties you may need to save yuorself. // At any time you can affect the node selection: // setActivatedNodes(new Node[] {...}); } public static synchronized void activate() { TopComponent comp = getInstance(); comp.open(); comp.requestActive(); } /* Ensures a singleton instance of __NAME__. Without this, a new __NAME__ would be created whenever the OpenAction menu item is invoked. ****************************************************************************************************************************************/ public static synchronized __NAME__ getInstance() { TopComponent c; c = WindowManager.getDefault().findTopComponent(tcID); if(c == null) { // create new one c = new __NAME__(); tcID = WindowManager.getDefault().findTopComponentID(c); } return (__NAME__)c; } /* Overrides the open() method to force the new component be docked in the MODE mode. * Forcing the component to be docked in the MODE mode is only necessary if the ID changes. ****************************************************************************************************************************************/ public void open() { Mode m = WindowManager.getDefault().findMode(MODE); m.dockInto(this); super.open(); } /* Overrides the preferredID method. ****************************************************************************************************************************************/ protected String preferredID() { return PREFF_ID; } /* public HelpCtx getHelpCtx() { return new HelpCtx(__NAME__.class); } */ /* // If you are using CloneableTopComponent, probably you should override: protected CloneableTopComponent createClonedObject() { return new __NAME__(); } protected boolean closeLast() { // You might want to prompt the user first and maybe return false: return true; } */ // APPEARANCE /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents setLayout(new java.awt.BorderLayout()); }//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables // PERSISTENCE private static final long serialVersionUID = 1L; /* Overrides the getPersistenceType() method. * PERSISTENCE_NEVER: The system will not try to serialize your component. This is suitable for transient windows that the user would * not generally wish to save across IDE restarts, as well as for windows containing data which cannot by its nature be persisted correctly. * PERSISTENCE_ONLY_OPENED: The system will only try to serialize your component if it was open at the time. This is suitable for many * types of windows that should be saved if visible, but for which there is no compelling reason to keep information about the window state when closed. * PERSISTENCE_ALWAYS: The system will always try to serialize your component. This is suitable for many types of windows that should * be saved even if closed. You can close and reopen such components anytime even after IDE restart. Such components are often * singletons and have an action that enables you to open/reopen a component. ****************************************************************************************************************************************/ public int getPersistenceType() { return PERSISTENCE_ONLY_OPENED; } /* // If you wish to keep any state between IDE restarts, put it here: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); setSomeState((SomeType)in.readObject()); } public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(getSomeState()); } */ /* // The above assumes that the SomeType is safely serializable, e.g. String or Date. // If it is some class of your own that might change incompatibly, use e.g.: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); NbMarshalledObject read = (NbMarshalledObject)in.readObject(); if (read != null) { try { setSomeState((SomeType)read.get()); } catch (Exception e) { ErrorManager.getDefault().notify(e); // If the problem would make this component inconsistent, use: // throw new SafeException(e); } } } public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); Object toWrite; try { toWrite = new NbMarshalledObject(getSomeState()); } catch (Exception e) { ErrorManager.getDefault().notify(e); toWrite = null; // Again you may prefer to use: // throw new SafeException(e); } out.writeObject(toWrite); } */ /* // Use this to discard the component after restarts (make it nonpersistent): private Object readResolve() throws ObjectStreamException { return null; // If you wish to conditionally discard it, make readExternal set // or clear some flag acc. to the condition, then use: // return discardFlag ? null : this; // Singleton component using private static __NAME__ theInstance: // if (theInstance == null) theInstance = this; // return theInstance; } */ // ACTIONS /* // If you wish to have extra actions appear in the window's // popup menu, they can go here: public Action[] getActions() { Action[] supe = super.getActions(); Action[] mine = new Action[supe.length + 1]; System.arraycopy(supe, 0, mine, 0, supe.length); mine[supe.length] = SystemAction.get(SomeActionOfMine.class); return mine; } */ /* // To update Find, Copy, etc. actions, add to constructor: ActionMap map = getActionMap(); Action findBinding = new MyFindAction(this); map.put(((CallbackSystemAction)SystemAction.get(FindAction.class)).getActionMapKey(), findBinding); */ /* // If you want UndoAction and RedoAction to be enabled on this component: public UndoRedo getUndoRedo() { return new MyUndoRedo(this); } */ // Printing, saving, compiling, etc.: use cookies on some appropriate node and // use this node as the node selection. }