View Javadoc

1   /*
2    * Trip Tracker, a real-time position tracking system for the Internet.
3    * Copyright (C) 2006  Team Trip Tracker
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or (at your
8    * option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but
11   * WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License along
16   * with this program; if not, write to the Free Software Foundation, Inc.,
17   * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  
20  package triptracker.client.ui;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /***
26   * An abstract {@link FormManager} class to handle adding, removal and
27   * displaying of forms. This class implements basic logic for form management
28   * and calls addComponent, removeComponent and showComponent so that the
29   * sub-class can modify its component container when needed. This class exists
30   * as convenience for creating form manager objects.
31   * <p>
32   * Extend this class to create a FormManager and override the addComponent,
33   * removeComponent and showComponent methods for simplified form component
34   * management. If you implement the FormManager interface, you have to write all
35   * the form management logic, which can cause code duplication where more than
36   * one form manager class exists.
37   */
38  public abstract class AbstractFormManager implements FormManager {
39  	/*** List of currently registered forms. */
40  	protected List<Form> forms = new ArrayList<Form>();
41  	
42  	/*** The currently activated form. */
43  	protected Form currentForm = null;
44  
45  	/***
46  	 * {@inheritDoc}
47  	 */
48  	public void register(Form form) {
49  		forms.add(form);
50  		addComponent(form);
51  
52  	    if (currentForm == null) {
53  	    	currentForm = form;
54  	    }		
55  	}
56  	
57  	/***
58  	 * {@inheritDoc}
59  	 */
60  	public void deregister(Form form) {
61  	    if (currentForm == form) {
62  	    	currentForm = null;
63  	    }
64  	    
65  		forms.remove(form);
66  		removeComponent(form);
67  	}
68  
69  	/***
70  	 * {@inheritDoc}
71  	 */
72  	public void showForm(Form form) {
73  //		currentForm.updateModel(model);
74  		currentForm = form;
75  		currentForm.refreshView();
76  		
77  		showComponent(form);
78  	}	
79  
80  	/***
81  	 * Invoked as a result of a form calling register. Sub-classes must
82  	 * override this method in order to provide adding of components to their
83  	 * component container.
84  	 * 
85  	 * @param form form to add to container
86  	 * @see #register(Form)
87  	 */
88  	public abstract void addComponent(Form form);
89  	
90  	/***
91  	 * Invoked as a result of a form calling deregister. Sub-classes must 
92  	 * override this method in order to provide removal of components from their
93  	 * component container.
94  	 * 
95  	 * @param form form to remove from container
96  	 * @see #deregister(Form)
97  	 */
98  	public abstract void removeComponent(Form form);
99  	
100 	/***
101 	 * Invoked as a result of a call to showForm. Sub-classes must override
102 	 * this method in order to implement show the appropriate forms when needed.
103 	 * 
104 	 * @param form form to display
105 	 * @see #showForm(Form)
106 	 */
107 	public abstract void showComponent(Form form);
108 }