Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to manage "several" GUI components in the View?

 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am interested in having a Jframe , which has a panel at the center. This panel is in card layout and has 4 cards. Card 1 is flight information based on two given (combos) stations, Card 2 is flight information based on a flight name (combo selectable), Card 3 is for search and Card 4 is booking flights. All the cards have Tables to display output information and Jcombo/button for input. These operations come under a View abstraction that is independent of any logic. It manages only GUI.
The Model contains a set of TableModels, ComboModels. Although they are intended for View�s GUI components and contain equivalent models for GUI present in View, they have the boy�s ego of being independent. No word will be present regarding GUI components or View. It does not know of DataInfo or FieldInfo, but uses another private object called CommunicatorToDb to handle database specific work. CommunicatorToDb knows the language of Database. It knows DataInfo or FieldInfo.[Can I call CommunicatorToDb as a DataFacade?]
The controller is going to be specific for the logic, doing the match making between Model and View.
I have been thinking in terms of designing the model, view and controller as as Reid M. Pinchback ranch hand Member # 25669 says here .
http://www.coderanch.com/t/181296/java-developer-SCJD/certification/MVC-Pattern-Overkill
Also, I wanted to add some more independence. The developer of Controller should not look into the code of the View or Model. He should be able to know of the available gui components and models through a nice view and model implementation.
Please tell me :
1) Is the Card Layout idea is good. [I am very much interested abt it!!]
2) Can I call the name CommunicatorToDb as a Facade?
3) How to manage several Jtables and the corresponding combo/button inputs?
4) When the button is clicked, the items selected in combo have to be passed to the listener? The listeners are in the controller.
5) The idea of Reid M. Pinchback ranch hand Member # 25669 seems to be rugged and strong. My idea, as in the above paragraph, is its extension. Am I going in the right direction?
I spent more time in this. Please help me in giving right direction.
Thanks in advance,
Rajesh
[ October 08, 2003: Message edited by: Rajesh So ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,
1) Is the Card Layout idea is good. [I am very much interested abt it!!]

I used a card layout in my submission - it worked well for me. My only cards were: Configuration, Flight selection (including searches), and Flight Bookings).
I can't visualise what you are doing with cards 1 & 2, but aside from that, your usage sounds good.
You might also want to look at JTabbedPane - see which you like more.
2) Can I call the name CommunicatorToDb as a Facade?

Sounds reasonable.
3) How to manage several Jtables and the corresponding combo/button inputs?

I don't really understand what you are asking here.
I think you are asking about how you ensure that the information in your JTables is kept in sync. In which case, you might want to look at the Observer-Observable pattern. Have an observable model, and have your different views as the observers. Then whenever any view initiates an action that results in a change in the view, your model can push the changes out to all it's registered observers.
4) When the button is clicked, the items selected in combo have to be passed to the listener? The listeners are in the controller.

I like the idea of the listeners being in the controller, but it is not essential.
5) The idea of Reid M. Pinchback ranch hand Member # 25669 seems to be rugged and strong. My idea, as in the above paragraph, is its extension. Am I going in the right direction?

It sounds like you have a clear direction that will work. It may be a bit more complicated than stricly necessary, but that is OK - you will learn more doing this.
I would suggest you show some sketches of how you envisage the screens looking to some random people (family members, friends, whoever) and get them to confirm that your user interface is not too complex.
Regards, Andrew
 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew, Thank you so much for encouraging.

I can't visualize what you are doing with cards 1 & 2,

The cards currently envisaged are
Card 1: There will be two combos-origin and destination-, an OK button and a JTable. The user selects his origin and destination and clicks the button. The matching flights will be displayed in the Jtable.
Card 2: There will be a Combo, an Ok button and a JTable. The combo has all the Flight numbers. Once the user clicks the button. The flight details are displayed in the table.
Is giving both ways of searching required?? Or shall I choose only one of them?
3) How to manage several Jtables and the corresponding combo/button inputs?

Andrew, my problem is that there are going to be several cards (currently only 4) and each card has some GUI components. For example a search card will have a text field, a button and table. Managing the layout and integrity of these components is the responsibility of the View. When another object (say, Controller) uses the View, how to present the different GUI components to it? . In other words, How to make an interface for the View?
There are also some special circumstances like this: In flight Information card (Card 1), when a user clicks Ok, we won’t require the button’s value but will have to pass the items selected in the combo! How to draw an interface for the View, such that its users (Controller) can know about where to fix listener, where to get the input, where to set the Model et al? I struggled hard to get a generic interface and got lost.
I am not using the Observer/Observable. Instead, I have planned to use the Jtable’s setModel method. This method is enclosed in the View. The controller, when doing the matchmaking between View and Model, will call this method. Later whenever the model changes, it automatically reflects in the View. Class Model manages the TableModels.
Please see if my ultimate idea is right – “The developer of Controller should not look into the code of the View or Model. He should be able to know of the available gui components and models through a nice view and model interface/implementation.”
The reason for using a card layout was for scalability, so that additional screens can be added in future.
Andrew, please help me in coming up with an interface for View,so that controller can talk with it.
Thanks in advance,
Rajesh
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,
Card 1: ... two combos-origin and destination-, an OK button and a JTable. ... The matching flights will be displayed in the Jtable.
Card 2: a [Flight numbers] Combo, an Ok button and a JTable. The flight details are displayed in the table.
Is giving both ways of searching required?? Or shall I choose only one of them?

The only guaranteed required options are the Origin and Destination airports. Some people also have Carrier since it is shown in the example within the instructions. I don't recall anyone offering flight numbers before.
By the way - should your button be "OK" or "Search" or "Find" or "Select"? What will make the most sense to your users?
When another object (say, Controller) uses the View, how to present the different GUI components to it?

You might want to look at this thread where I describe how I understand the MVC pattern to work, and have included some links to the Sun site.
I don't believe it is a problem for the Controller to have some knowledge of the View. In this post Eugene Kononov gives an example of the controller having a "hook" method that the view can connect to in order to send actions to the controller.
Depending on how much you want to abstract the view from the controller, you could use the Command pattern in conjunction with the Chain Of Responsibility pattern. The Command pattern would see you develop an object which all the Views can use to pass commands to the Controller(s). This object would contain the command to run (Search, Book, ...) and any required data. The Controller would have a method that accepts that command and passes it to whichever classes can deal with (Chain of Responsibility). Personally I think that this may be too much abstraction for such a simple project, but the end decision is up to you.
Regards, Andrew
 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,
Could you please tell if my thinking is away from simplicity ??? Or Is the design making simple things complex?
Because, my intention is to make it simple and easy to scale.
Rajesh
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,
I did something very similar with my design. I used multiple screens inside a card layout, and I used Heirachial Model View Controller pattern with Command pattern and Chain Of Responsibility.
When submitting I considered this a very clean, simple and easy to extend system. However I also thought that this might not be instantly picked up by a junior programmer. So I included class diagrams in my submission to help the examiner understand how everything worked together. The fact that I got to the point where I wanted to include the diagrams says a lot :roll: .
I did get 100% for my GUI, so I guess the examiner liked what I did. So I am not going to try and disuade you from doing something similar.
Regards, Andrew
[ October 10, 2003: Message edited by: Andrew Monkhouse ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic