Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > cocoa-java app init tasks

cocoa-java app init tasks
Thread Tools
Fresh-Faced Recruit
Join Date: May 2002
Location: oakland, CA
Status: Offline
Reply With Quote
Jun 3, 2002, 05:08 PM
 
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
Reply With Quote
Jun 3, 2002, 05:54 PM
 
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
Reply With Quote
Jun 3, 2002, 11:29 PM
 
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
Reply With Quote
Jun 4, 2002, 01:36 PM
 
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
Reply With Quote
Jun 5, 2002, 06:12 PM
 
</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
Reply With Quote
Jun 7, 2002, 12:34 AM
 
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
Reply With Quote
Jun 11, 2002, 07:29 AM
 
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>
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2