 |
 |
cocoa-java app init tasks
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2002
Location: oakland, CA
Status:
Offline
|
|
Bear with the beginner.
I've got an application where I want to perform some tasks after the MainMenu.nib loads but before I create the main application window (prep data for display in the application window/get user input).
It's clear how this works in a document based application using 'windowControllerWillLoadNib' but my app isn't document based so how can I do the same from my primary 'appController' class?
Should I create an init() method within a static initialization block of 'appController' that will get executed when MainMenu.nib instantiates 'appController'?
|
|
gw
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2002
Location: oakland, CA
Status:
Offline
|
|
As you may have guessed the static init block doesn't work for things like creating non-static NSWindowControllers so I guess I'm looking for a way to call my custom init() methods without having the user do anything.
|
|
gw
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
override this method:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">public void awakeFromNib()
{
//blah, blah, blah
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2002
Location: oakland, CA
Status:
Offline
|
|
brilliant! thanks.
So awakeFromNib() can be used by any class that is instantiated by a nib file?
The reason I ask is that I can't find anything in the cocoa-java API and it seems to be a pretty useful. (I only find it in the obj-C NSNibLoading.h file)
Related question. When PB creates a new document-based app, where is the connection that creates a new empty document after the app launches? I'm just trying to replicate the behavior starting with a regular app, but I can't find anything that links the MainMenu.nib to somDocumentController.java class that in turn would load the someDocument.nib. Is it functionality that apple buries in the nib files when a document-based app is created?
|
|
gw
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">So awakeFromNib() can be used by any class that is instantiated by a nib file?
The reason I ask is that I can't find anything in the cocoa-java API and it seems to be a pretty useful. (I only find it in the obj-C NSNibLoading.h file)
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Yep, any time a class is instantiated from a nib file, that class has awakeFromNib() called off of it if it exists.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
Related question. When PB creates a new document-based app, where is the connection that creates a new empty document after the app launches? I'm just trying to replicate the behavior starting with a regular app, but I can't find anything that links the MainMenu.nib to somDocumentController.java class that in turn would load the someDocument.nib. Is it functionality that apple buries in the nib files when a document-based app is created?</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">It's not buried in the nib file at all. A lot of it is done by the NDocumentController and NSDocument. Additionally, I believe NSApplication handles opening and such; just look at the methods implemented by NSApp's delegate. In the case of a Document-based app, your delegate would be your NSDocumentController (which you generally don't have to touch). I'm not sure why'd you want to replicate the behavior when NSDocument et al gives it all to you for free (one of Cocoa's main intents). Look at some of the docs on Document-based apps to get a better feel for what's going on.
HTH
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2002
Location: oakland, CA
Status:
Offline
|
|
thanks.
Repeated digging in the documentation is making the world of cocoa much clearer.
|
|
gw
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2001
Location: Boston, MA
Status:
Offline
|
|
Another way to do this is just uncheck "Visible at launch time" on your main window's attribute in Interface Builder. You can then set up your UI or do whatever before you display your main window in the applicationDidFinishLaunching method. Then all you do is tell your window to makeKeyAndOrderFront.
It's worked for me, but awakeFromNib is the better alternative for more complex, multi-windowed Cocoa-based applications
<small>[ 06-11-2002, 08:30 AM: Message edited by: SoClose ]</small>
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|