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 > Help with multiple window application

Help with multiple window application
Thread Tools
Wes
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
Jul 14, 2004, 01:04 AM
 
Is there a simple-ish way to create a multiple window app with multiple window controllers that can communicate with each other? I have read Apple's documentation on document-based applications, and understood very little. Plus, in the program I am writing I have no need to open or save files off of the hard drive (or print etc...), but I do need multiple windows and being able to have those different windows controlled by separate controllers would save me a lot of headaches. I have this one window thing down pretty well, but multiple controllers throw me. Ideas?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 14, 2004, 02:10 AM
 
You're going to have to explain more fully, because with just the requirement "multiple window controllers communicate with each other," I would say to create several custom window controllers and have them either keep references to each other, use the responder chain or send notifications — the same way any other objects communicate with each other. But I reckon you must have some more specific problem in mind than this.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jul 14, 2004, 11:11 AM
 
Wes,

When I first started learning Cocoa/ObjC I struggled with what you're describing. Take a look at /Developer/Examples/InterfaceBuilder/SimpleMultiWindow or a dated example on my .mac site:

http://homepage.mac.com/stevewoodward/FileSharing4.html

TwoWindow.zip may be enough to get you started. But there are several ways to attack the problem. In the case of one window calling another you could just use setParentController, but if they're all called separately then you need a "centralized" method of communication, such as notification centers.

Steve W
( Last edited by techtrucker; Jul 14, 2004 at 11:32 AM. )
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
Earth Mk. II
Mac Elite
Join Date: Feb 2001
Location: Washington, DC
Status: Offline
Reply With Quote
Jul 14, 2004, 06:38 PM
 
The "right way" to do that would be to use notification centers, and perhaps a more general controller class or two depending on what type of data you want to share between window controllers and what you want that data's life span to be. (the other controllers can also handle things like data verification and persistence in a centralized way)

Alternatively, you could try to make each window controller hold a reference to each other window controller. This would be easier to set up initially, but will be major pain in your ass to maintain, especially if the application's complexity grows (and trust me - it will).
/Earth\ Mk\.\ I{2}/
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jul 15, 2004, 08:16 AM
 
Earth Mk. II is right about notification centers. The application I'm working on right now is rather complex and I am basically doing what he cautions against, havng the window controllers hold references to other window controllers. Im my case it's not too bad, but I can see where it could become unweildy. This app is basically a database app where one window will be a "browse" window with a table view, and will call up a second window to let the user edit the data for the selected row. (Long story why I can't let the users edit the data in the table directly). So I've got Window 1a calling up Window 1B, Window 2A calling up Window2B, etc. The two windows need to communicate data back and forth and I do that by having them reference each other's controllers and heavy use of accessor methods.
So it really depends on the needs of your specific application, if you could clue us in on the details maybe we can steer you in the right direction.

Steve W
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
djohnson
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Jul 15, 2004, 09:45 AM
 
Ahh but Notifications are slow. I am guessing you want window A to call a function in window B, etc. Why not just setup an outlet? IE:

IBOutlet id windowAConn;

In IB, just have a new outlet and connect it to the other window controller. I have done this in many projects... SetiLogger X uses multiple windows and they can all talk to each other. Email me at djohnson(at)tfworld.com for more info and some code examples.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 15, 2004, 02:31 PM
 
Originally posted by djohnson:
Ahh but Notifications are slow. I am guessing you want window A to call a function in window B, etc. Why not just setup an outlet? IE:

IBOutlet id windowAConn;

In IB, just have a new outlet and connect it to the other window controller.
It's not very elegant, though. I mean, it works, but it requires a lot of classes to be exposed to each other, and anytime that class hierarchy changes in any way, you're going to have to reconfigure everything.

I suppose if algorithm speed is that important, yeah, notifications would be a problem, but that's only if the window controllers need to send each other messages hundreds of times a second.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jul 15, 2004, 04:34 PM
 
In a two window situation I let window A and B reference each other. Anything more than that and I usually go with a notification center. I haven't seen any performance hits, but I'm not passing a lot of data back and forth. Not exactly subscribing to the MVC school of thought, but I'm trying...

Steve W
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
11011001
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Jul 15, 2004, 08:06 PM
 
I ran into this problem with a very complex Java program that we had to write for an assignment. We ended up using property change listeners to solve this problem.

For Java is there anything like notification centers? How would one approach this problem in Java?
     
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jul 16, 2004, 08:53 AM
 
A long time ago I went looking for something like notification centers in Java and had bookmarked this but never used it:

http://www.amug.org/~glguerin/sw/not.../overview.html

Steve W
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 16, 2004, 10:05 AM
 
That looks more similar to CFUserNotification than NSNotification.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Earth Mk. II
Mac Elite
Join Date: Feb 2001
Location: Washington, DC
Status: Offline
Reply With Quote
Jul 16, 2004, 11:41 AM
 
Originally posted by 11011001:
I ran into this problem with a very complex Java program that we had to write for an assignment. We ended up using property change listeners to solve this problem.

For Java is there anything like notification centers? How would one approach this problem in Java?
I suspect that NSNotificationCenter works rather cleanly because of selectors, and I don't know if there's anything equivalent to those in Java.

If there is, you could set up a hashtable with a key for each observed notification, then an array of observing objects (along with the method to perform) as the associated object.

When a message is passed into the center, check it's name against the table - if there's a hit perform all the requested objects in the array, if not.. ignore it.

It would be a very basic implementation of the concept. But it should work, provided there's a way to perform arbitrary methods on java objects.

[EDIT]

you might want to check out Apple's NSNotificationCenter (Java) documentation and see what you can grok from it.
( Last edited by Earth Mk. II; Jul 16, 2004 at 11:46 AM. )
/Earth\ Mk\.\ I{2}/
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 04:43 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,