View Javadoc

1   /*
2    * JDiskCatalog
3    *
4    * Copyright 2007 Przemek Więch
5    *
6    * This file is part of JDiskCatalog.
7    *
8    * JDiskCatalog is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17  
18   * You should have received a copy of the GNU General Public License
19   * along with this program; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  
23  package net.sf.jdiskcatalog.view;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import net.sf.jdiskcatalog.api.Document;
29  import net.sf.jdiskcatalog.api.Node;
30  import net.sf.jdiskcatalog.api.NodeSelectionListener;
31  import net.sf.jdiskcatalog.api.View;
32  
33  
34  public class ViewManager implements NodeSelectionListener
35  {
36  	private Document document = null;
37  	private Node node = null;
38  
39  	private Map<Class<? extends View>, View> views = new HashMap<Class<? extends View>, View>();
40  
41  	public void add(View view)
42  	{
43  		views.put(view.getClass(), view);
44  		view.setNodeSelectionListener(this);
45  		view.setDocument(document);
46  		view.nodeSelected(node);
47  	}
48  
49  	public View getView(Class<? extends View> clazz)
50  	{
51  		return views.get(clazz);
52  	}
53  
54  	public void setDocument(Document document)
55  	{
56  		this.document = document;
57  		for (View view: views.values())
58  			view.setDocument(document);
59  	}
60  
61  	public void nodeSelected(Node node)
62  	{
63  		this.node = node;
64  		for (View view: views.values())
65  			view.nodeSelected(node);
66  	}
67  
68  	public void refresh()
69  	{
70  		for (View view: views.values())
71  			view.refresh();
72  	}
73  }