KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > selection > SelectionManager


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.selection;
17
18 import java.util.Hashtable JavaDoc;
19
20 import org.columba.api.command.ICommandReference;
21 import org.columba.api.selection.ISelectionHandler;
22 import org.columba.api.selection.ISelectionListener;
23 import org.columba.api.selection.ISelectionManager;
24
25 /**
26  * Manages selection handling of a complete frame which can have many different
27  * components with a selection model.
28  * <p>
29  * It additionally wraps almost all methods of {@link SelectionHandler}. So,
30  * there's no need to directly access {@link SelectionHandler}.
31  * <p>
32  * The <code>org.columba.core.gui.frame</code> package makes highly use of
33  * this class to manage all its selection stuff.
34  * <p>
35  * SelectionHandler has an id <code>String</code> as attribute. This makes it
36  * easy to indentify the SelectionHandler.
37  *
38  * @see org.columba.core.selection.SelectionHandler
39  * @see org.columba.api.gui.frame.IFrameMediator
40  *
41  * @author fdietz, tstich
42  */

43 public class SelectionManager implements ISelectionManager {
44     /**
45      * Map for storing all selection handlers
46      *
47      */

48     private Hashtable JavaDoc selectionHandler;
49
50     /**
51      * default constructor
52      */

53     public SelectionManager() {
54         // init Map
55
selectionHandler = new Hashtable JavaDoc();
56     }
57
58     /**
59      * Add selection handler
60      *
61      * @param handler
62      */

63     public void addSelectionHandler(ISelectionHandler handler) {
64         selectionHandler.put(handler.getId(), handler);
65     }
66
67     /**
68      * @see org.columba.api.selection.ISelectionManager#registerSelectionListener(java.lang.String, org.columba.api.selection.ISelectionListener)
69      */

70     public void registerSelectionListener(String JavaDoc id, ISelectionListener l) {
71         SelectionHandler h = ((SelectionHandler) selectionHandler.get(id));
72
73         h.addSelectionListener(l);
74     }
75     
76     /**
77      * @see org.columba.api.selection.ISelectionManager#removeSelectionListener(java.lang.String, org.columba.api.selection.ISelectionListener)
78      */

79     public void removeSelectionListener(String JavaDoc id, ISelectionListener l) {
80         SelectionHandler h = ((SelectionHandler) selectionHandler.get(id));
81
82         h.removeSelectionListener(l);
83     }
84     
85
86     /**
87      * @see org.columba.api.selection.ISelectionManager#setSelection(java.lang.String, org.columba.api.command.ICommandReference)
88      */

89     public void setSelection(String JavaDoc id, ICommandReference selection) {
90         ((ISelectionHandler) selectionHandler.get(id)).setSelection(selection);
91     }
92
93     /**
94      * @see org.columba.api.selection.ISelectionManager#getSelection(java.lang.String)
95      */

96     public ICommandReference getSelection(String JavaDoc id) {
97         return ((ISelectionHandler) selectionHandler.get(id)).getSelection();
98     }
99
100     /**
101      * @see org.columba.api.selection.ISelectionManager#getHandler(java.lang.String)
102      */

103     public ISelectionHandler getHandler(String JavaDoc id) {
104         return (ISelectionHandler) selectionHandler.get(id);
105     }
106 }
Popular Tags