• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSApplication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSApplication


  • Subject: Re: NSApplication
  • From: Dustin Voss <email@hidden>
  • Date: Wed, 26 Nov 2003 20:38:31 -0800

On 26 Nov, 2003, at 2:18 PM, Brian Dent wrote:

can someone plz show me how to use an applicationdidfinishlaunching to display a progress bar in a panel.
i need it in a cocoa-JAVA app, i dont want told to look at the c docs, i dont know c, i have never used c.
i am building it in project builder, with interface builder, so i cant look at anything but what i have written myself.
why is it so hard to find help with using java!!!!

In theory, Apple's Java reference documentation is about as complete as their Objective-C documentation. The conceptual documentation (where you would learn about delegates) is written as for Objective-C, but if something is different for Java, they mention it, and if they don't mention it, then there's usually no difference. In practice, there are places they missed. A site called "Learning Cocoa in Java" (http://www.whiningdog.net/articles/LCIJ) might help with that.

I also recommend the following:
* "Cocoa-Java Tutorial" (http://developer.apple.com/documentation/Cocoa/Conceptual/ JavaTutorial/index.html).
* "Cocoa Core Concepts" (http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaCoreConcepts/index.html).
* "Application Architecture -- Typical Usage Patterns" (http://developer.apple.com/documentation/Cocoa/Conceptual/ AppArchitecture/Concepts/DocumentArchitecture.html#//apple_ref/doc/uid/ 20000921/1058324)

But to answer your question, for multi-NIB apps, you would not use applicationDidFinishLaunching() for this purpose. Usually, you would not do it programmatically at all. You would just use IB to put the progress indicator in the panel and connect it to an outlet of the panel's controller.

But if you did want to add a progress indicator to a panel programmatically, perhaps to hide or show it, you'd do it in the action method of a menu or button, or in the NIB owner's awakeFromNib() method.

In a one-NIB app, the situation can be different. The default NIB owner is NSApplication, which doesn't have a delegate method for awakeFromNib(). I think the nearest thing is, indeed, applicationDidFinishLaunching(). Here's how you use it to add a progress indicator to the panel:

1. Create an application delegate class. It should have the following:
public NSPanel myPanel; /* IBOutlet */
public abstract void applicationDidFinishLaunching(NSNotification aNotification)
{}

2. Open your NIB file and select the "Classes" tab. Choose the "Read Files..." menu item and open your application delegate class file. This will let IB know about it. Then select it from the class list and choose the "Instantiate" menu item to create the delegate in your NIB file. Control-drag from the delegate icon to your panel to connect the "myPanel" outlet, and control-drag from the "File's Owner" icon to the delegate icon to connect the "delegate" outlet. This will tell the app what its delegate is.

3. Now you just need to implement applicationDidFinishLaunching(). This delegate method will get called after the NIB is loaded and awakened. To create an NSProgressIndicator and add it to the panel, you will first need to decide where the progress indicator should go, and what size it should be. That is the frame rectangle. Once you decide that, create the progress indicator with the NSProgressIndicator(frameRect) constructor. Set the style, min and max values, etc. to whatever you like.

4. I assume that you don't want to put the progress indicator inside of a split view, tab view, or box. If you do, you'll have to create another IBOutlet for the parent view, connect the parent view to that outlet, and make your frame rectangle relative to the parent view, not the panel. But if my assumption holds, place the progress indicator inside the panel with the following:
myPanel.contentView().addSubview(theProgressIndicator);

By the way, I don't use this recipe. This recipe leaves NSApplication as the NIB's owner. I use an application controller that handles app-wide initialization and menu items, and I prefer that that the controller owns the main NIB, in the same way that a window controller might own a window's NIB.

In my main NIB file, I use the "Custom Subclass" inspector on the "File's Owner" icon to change the owner from an NSApplication to my app controller. I also rewrite the main() function to create my controller and use it as the owner when loading the main NIB.

I have to add code to main(), and I have to rewire the application menu, but this does allow me to use awakeFromNib() to customize the main NIB.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >NSApplication (From: Brian Dent <email@hidden>)

  • Prev by Date: Re: Need a dictionary of words in English
  • Next by Date: Re: tabbing between controls
  • Previous by thread: Re: NSApplication
  • Next by thread: Re: NSApplication
  • Index(es):
    • Date
    • Thread