KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > parser > lib > MenuManager


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.util.explorer.parser.lib;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.objectweb.util.explorer.core.common.api.ExplorerConstants;
32 import org.objectweb.util.explorer.core.menu.api.AcceleratorDescription;
33 import org.objectweb.util.explorer.core.menu.api.ItemDescription;
34 import org.objectweb.util.explorer.core.menu.api.MenuDescription;
35 import org.objectweb.util.explorer.core.menu.api.MnemonicDescription;
36 import org.objectweb.util.explorer.core.menu.lib.BasicAcceleratorDescription;
37 import org.objectweb.util.explorer.core.menu.lib.BasicItemDescription;
38 import org.objectweb.util.explorer.core.menu.lib.BasicMenuDescription;
39 import org.objectweb.util.explorer.core.menu.lib.BasicMnemonicDescription;
40 import org.objectweb.util.explorer.explorerConfig.Accelerator;
41 import org.objectweb.util.explorer.explorerConfig.Item;
42 import org.objectweb.util.explorer.explorerConfig.Menu;
43 import org.objectweb.util.explorer.explorerConfig.Mnemonic;
44 import org.objectweb.util.explorer.explorerConfig.Node;
45
46 /**
47  * This component manages the "menu" XML element.
48  *
49  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
50  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
51  *
52  * @version 0.1
53  */

54 public class MenuManager
55      extends AbstractNodeParser
56 {
57
58     //==================================================================
59
//
60
// Internal States.
61
//
62
// ==================================================================
63

64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     /**
77      * Provides the <code>AcceleratorDescription</code> according to the
78      * given accelerator definition.
79      * @param accelerator The accelerator definition
80      * @return The corresponding accelerator description.
81      */

82     protected AcceleratorDescription getAcceleratorDescription(Accelerator accelerator){
83         AcceleratorDescription acceleratorDesc = null;
84         if(accelerator!=null){
85             acceleratorDesc = new BasicAcceleratorDescription();
86             acceleratorDesc.setAcceleratorCharacter(accelerator.getXmlchar().charAt(0));
87             acceleratorDesc.setCtrlKey(accelerator.getCtrl().equals("true"));
88             acceleratorDesc.setAltKey(accelerator.getAlt().equals("true"));
89             acceleratorDesc.setShiftKey(accelerator.getShift().equals("true"));
90             acceleratorDesc.setMetaKey(accelerator.getMeta().equals("true"));
91         }
92         return acceleratorDesc;
93     }
94     
95     /**
96      * Provides the <code>MnemonicDescription</code> according to the
97      * given mnemonic definition.
98      * @param mnemonic The mnemonic definition
99      * @return The corresponding mnemonic description.
100      */

101     protected MnemonicDescription getMnemonicDescription(Mnemonic mnemonic){
102         MnemonicDescription mnemonicDesc = null;
103         if(mnemonicDesc!=null){
104             mnemonicDesc = new BasicMnemonicDescription();
105             mnemonicDesc.setMnemonicCharacter(mnemonic.getXmlchar().charAt(0));
106         }
107         return mnemonicDesc;
108     }
109     
110     /**
111      * Provides the <code>ItemDescription</code> according to the
112      * given item definition.
113      * @param item The item definition
114      * @return The corresponding item description.
115      */

116     protected ItemDescription getItemDescription(Item item){
117         ItemDescription itemDesc = null;
118         if(item!=null){
119             itemDesc = new BasicItemDescription();
120             itemDesc.setLabel(item.getLabel());
121             itemDesc.setTreeChildVisible(item.getTreeChildVisible().equals("true"));
122             itemDesc.setTypeChildVisible(item.getTypeChildVisible().equals("true"));
123             itemDesc.setCodeDescription(ParserUtils.getCodeDescription(item.getCode()));
124             itemDesc.setIconDescription(ParserUtils.getIconDescription(item.getIcon()));
125             itemDesc.setMnemonicDescription(getMnemonicDescription(item.getMnemonic()));
126             itemDesc.setAcceleratorDescription(getAcceleratorDescription(item.getAccelerator()));
127         }
128         return itemDesc;
129     }
130     
131     /**
132      * Feeds the given <code>MenuDescription</code> with the given list of items.
133      * @param The list of items to add.
134      * @param menuDesc The <code>MenuDescription</code> to feed.
135      */

136     protected void feedMenuDescription(List JavaDoc elements, MenuDescription menuDesc){
137         if(elements!=null && !elements.isEmpty()){
138             Iterator JavaDoc it = elements.iterator();
139             while(it.hasNext()){
140                 menuDesc.addMenuElement(getItemDescription((Item)it.next()));
141             }
142         }
143     }
144     
145     /**
146      * Provides the <code>MenuDescription</code> according to the
147      * given menu definition.
148      * @param menu The menu definition
149      * @return The corresponding Menu configuration.
150      */

151     protected MenuDescription getMenuDescription(Menu menu){
152         MenuDescription menuDesc = null;
153         if(menu!=null){
154             menuDesc = new BasicMenuDescription();
155             menuDesc.setInheritTreeMenu(menu.getInheritTreeMenu().equals("true"));
156             menuDesc.setInheritTypeMenu(menu.getInheritTypeMenu().equals("true"));
157             feedMenuDescription(menu.getItemList(), menuDesc);
158         }
159         return menuDesc;
160     }
161         
162     // ==================================================================
163
//
164
// Public methods for NodeParser interface.
165
//
166
// ==================================================================
167

168     /* (non-Javadoc)
169      * @see org.objectweb.util.explorer.parser.api.NodeParser#parseNode(java.lang.Object, org.objectweb.util.explorer.explorerConfig.Node)
170      */

171     public void parseNode(Object JavaDoc key, Node node) {
172         MenuDescription menuDesc = getMenuDescription(node.getMenu());
173         if(menuDesc!=null){
174             getFeeder().feed(ExplorerConstants.MENU_PROPERTY, key, menuDesc);
175         }
176     }
177
178 }
179
180
181
Popular Tags