|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MenuBarServiceProvider.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.adwt.service;
|
|
| 8 |
|
|
| 9 |
import java.awt.Container;
|
|
| 10 |
import java.beans.beancontext.BeanContextServices;
|
|
| 11 |
import java.util.Iterator;
|
|
| 12 |
import java.util.ResourceBundle;
|
|
| 13 |
import java.util.Vector;
|
|
| 14 |
|
|
| 15 |
import javax.swing.JMenu;
|
|
| 16 |
import javax.swing.JMenuBar;
|
|
| 17 |
import javax.swing.JMenuItem;
|
|
| 18 |
|
|
| 19 |
import org.ejtools.adwt.AwtToolkit;
|
|
| 20 |
import org.ejtools.adwt.action.CommandAction;
|
|
| 21 |
import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
|
|
| 22 |
|
|
| 23 |
/**
|
|
| 24 |
* Description of the Class
|
|
| 25 |
*
|
|
| 26 |
* @author Laurent Etiemble
|
|
| 27 |
* @version $Revision: 1.5 $
|
|
| 28 |
* @todo Javadoc to complete
|
|
| 29 |
*/
|
|
| 30 |
public class MenuBarServiceProvider extends CustomBeanContextServiceProvider implements MenuBarService |
|
| 31 |
{
|
|
| 32 |
/** Description of the Field */
|
|
| 33 |
protected Vector listeners = new Vector(); |
|
| 34 |
/** Description of the Field */
|
|
| 35 |
protected JMenuBar menuBar = new JMenuBar(); |
|
| 36 |
/** Description of the Field */
|
|
| 37 |
protected Vector requestors = new Vector(); |
|
| 38 |
/** Description of the Field */
|
|
| 39 |
protected MenuBarService service = null; |
|
| 40 |
|
|
| 41 |
|
|
| 42 |
/** Constructor for the MenuBarServiceProvider object */
|
|
| 43 | 0 |
public MenuBarServiceProvider()
|
| 44 |
{
|
|
| 45 | 0 |
this.service = this; |
| 46 |
} |
|
| 47 |
|
|
| 48 |
|
|
| 49 |
/**
|
|
| 50 |
* Adds a feature to the MenuBarListener attribute of the MenuBarServiceProvider object
|
|
| 51 |
*
|
|
| 52 |
* @param mbsl The feature to be added to the MenuBarListener attribute
|
|
| 53 |
*/
|
|
| 54 | 0 |
public void addMenuBarListener(MenuBarService.Listener mbsl) |
| 55 |
{
|
|
| 56 | 0 |
this.listeners.add(mbsl);
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
|
|
| 60 |
/**
|
|
| 61 |
* Gets the container attribute of the MenuBarServiceProvider object
|
|
| 62 |
*
|
|
| 63 |
* @return The container value
|
|
| 64 |
*/
|
|
| 65 | 0 |
public Container getContainer()
|
| 66 |
{
|
|
| 67 | 0 |
return this.menuBar; |
| 68 |
} |
|
| 69 |
|
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Gets the currentServiceSelectors attribute of the ApplicationServiceProvider object
|
|
| 73 |
*
|
|
| 74 |
* @param bcs Description of Parameter
|
|
| 75 |
* @param serviceClass Description of Parameter
|
|
| 76 |
* @return The currentServiceSelectors value
|
|
| 77 |
*/
|
|
| 78 | 0 |
public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass)
|
| 79 |
{
|
|
| 80 | 0 |
return new Vector().iterator(); |
| 81 |
} |
|
| 82 |
|
|
| 83 |
|
|
| 84 |
/**
|
|
| 85 |
* Gets the service attribute of the ApplicationServiceProvider object
|
|
| 86 |
*
|
|
| 87 |
* @param bcs Description of Parameter
|
|
| 88 |
* @param requestor Description of Parameter
|
|
| 89 |
* @param serviceClass Description of Parameter
|
|
| 90 |
* @param serviceSelector Description of Parameter
|
|
| 91 |
* @return The service value
|
|
| 92 |
*/
|
|
| 93 | 0 |
public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector)
|
| 94 |
{
|
|
| 95 |
// Check if the requestor has already a service
|
|
| 96 | 0 |
if (!requestors.contains(requestor))
|
| 97 |
{
|
|
| 98 | 0 |
requestors.add(requestor); |
| 99 |
} |
|
| 100 | 0 |
return service;
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
|
|
| 104 |
/**
|
|
| 105 |
* Description of the Method
|
|
| 106 |
*
|
|
| 107 |
* @param action Description of Parameter
|
|
| 108 |
*/
|
|
| 109 | 0 |
public void register(CommandAction action) |
| 110 |
{
|
|
| 111 | 0 |
String menuName = action.getMenu(); |
| 112 | 0 |
ResourceBundle res = action.getResourceBundle(); |
| 113 | 0 |
JMenu parent = findMenu(menuName); |
| 114 |
|
|
| 115 | 0 |
if (parent == null) |
| 116 |
{
|
|
| 117 | 0 |
parent = addMenu(res, menuName); |
| 118 |
} |
|
| 119 |
|
|
| 120 | 0 |
addMenuItem(action, parent); |
| 121 |
} |
|
| 122 |
|
|
| 123 |
|
|
| 124 |
/**
|
|
| 125 |
* Description of the Method
|
|
| 126 |
*
|
|
| 127 |
* @param bcs Description of Parameter
|
|
| 128 |
* @param requestor Description of Parameter
|
|
| 129 |
* @param service Description of Parameter
|
|
| 130 |
*/
|
|
| 131 | 0 |
public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } |
| 132 |
|
|
| 133 |
|
|
| 134 |
/**
|
|
| 135 |
* Description of the Method
|
|
| 136 |
*
|
|
| 137 |
* @param mbsl Description of Parameter
|
|
| 138 |
*/
|
|
| 139 | 0 |
public void removeMenuBarListener(MenuBarService.Listener mbsl) |
| 140 |
{
|
|
| 141 | 0 |
this.listeners.remove(mbsl);
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
|
|
| 145 |
/**
|
|
| 146 |
* Description of the Method
|
|
| 147 |
*
|
|
| 148 |
* @param action Description of Parameter
|
|
| 149 |
*/
|
|
| 150 | 0 |
public void unregister(CommandAction action) |
| 151 |
{
|
|
| 152 | 0 |
String menuName = action.getMenu(); |
| 153 | 0 |
JMenu parent = findMenu(menuName); |
| 154 |
|
|
| 155 | 0 |
if (parent == null) |
| 156 |
{
|
|
| 157 | 0 |
return;
|
| 158 |
} |
|
| 159 |
|
|
| 160 | 0 |
removeMenuItem(action, parent); |
| 161 |
} |
|
| 162 |
|
|
| 163 |
|
|
| 164 |
/**
|
|
| 165 |
* Adds a feature to the Menu attribute of the MenuBarServiceProvider object
|
|
| 166 |
*
|
|
| 167 |
* @param menuName The feature to be added to the Menu attribute
|
|
| 168 |
* @param res The feature to be added to the Menu attribute
|
|
| 169 |
* @return Description of the Returned Value
|
|
| 170 |
*/
|
|
| 171 | 0 |
protected JMenu addMenu(ResourceBundle res, String menuName)
|
| 172 |
{
|
|
| 173 | 0 |
JMenu menu = new JMenu(res.getString(menuName));
|
| 174 | 0 |
menu.setFont(AwtToolkit.FONT); |
| 175 | 0 |
menu.setName(menuName); |
| 176 | 0 |
try
|
| 177 |
{
|
|
| 178 | 0 |
menu.setMnemonic(Integer.parseInt(res.getString(menuName + ".mnemonic")));
|
| 179 |
} |
|
| 180 |
catch (Exception e)
|
|
| 181 |
{
|
|
| 182 |
} |
|
| 183 | 0 |
this.menuBar.add(menu);
|
| 184 |
|
|
| 185 | 0 |
this.update();
|
| 186 |
|
|
| 187 | 0 |
return menu;
|
| 188 |
} |
|
| 189 |
|
|
| 190 |
|
|
| 191 |
/**
|
|
| 192 |
* Adds a feature to the MenuItem attribute of the MenuBarServiceProvider object
|
|
| 193 |
*
|
|
| 194 |
* @param action The feature to be added to the MenuItem attribute
|
|
| 195 |
* @param menu The feature to be added to the MenuItem attribute
|
|
| 196 |
*/
|
|
| 197 | 0 |
protected void addMenuItem(CommandAction action, JMenu menu) |
| 198 |
{
|
|
| 199 | 0 |
JMenuItem item = action.getMenuItem(); |
| 200 |
|
|
| 201 | 0 |
if (action.getMenuLayout() == MenuBarService.SEPARATOR_BEFORE)
|
| 202 |
{
|
|
| 203 | 0 |
if (menu.getItemCount() > 0)
|
| 204 |
{
|
|
| 205 | 0 |
menu.addSeparator(); |
| 206 |
} |
|
| 207 |
} |
|
| 208 |
|
|
| 209 | 0 |
JMenuItem addedItem = menu.add(item); |
| 210 | 0 |
addedItem.setFont(AwtToolkit.FONT); |
| 211 |
|
|
| 212 | 0 |
if (action.getValue(CommandAction.TOOLTIP) != null) |
| 213 |
{
|
|
| 214 | 0 |
addedItem.setToolTipText((String) action.getValue(CommandAction.TOOLTIP)); |
| 215 |
} |
|
| 216 |
|
|
| 217 | 0 |
if (action.getMenuLayout() == MenuBarService.SEPARATOR_AFTER)
|
| 218 |
{
|
|
| 219 | 0 |
menu.addSeparator(); |
| 220 |
} |
|
| 221 |
} |
|
| 222 |
|
|
| 223 |
|
|
| 224 |
/**
|
|
| 225 |
* Description of the Method
|
|
| 226 |
*
|
|
| 227 |
* @param menuName Description of Parameter
|
|
| 228 |
* @return Description of the Returned Value
|
|
| 229 |
*/
|
|
| 230 | 0 |
protected JMenu findMenu(String menuName)
|
| 231 |
{
|
|
| 232 | 0 |
for (int i = 0; i < menuBar.getMenuCount(); i++) |
| 233 |
{
|
|
| 234 | 0 |
JMenu menu = menuBar.getMenu(i); |
| 235 | 0 |
if (menu.getName().equals(menuName))
|
| 236 |
{
|
|
| 237 | 0 |
return menu;
|
| 238 |
} |
|
| 239 |
} |
|
| 240 |
|
|
| 241 | 0 |
return null; |
| 242 |
} |
|
| 243 |
|
|
| 244 |
|
|
| 245 |
/**
|
|
| 246 |
* @return The serviceClass value
|
|
| 247 |
*/
|
|
| 248 | 0 |
protected Class[] getServiceClass()
|
| 249 |
{
|
|
| 250 | 0 |
return new Class[]{MenuBarService.class}; |
| 251 |
} |
|
| 252 |
|
|
| 253 |
|
|
| 254 |
/**
|
|
| 255 |
* Description of the Method
|
|
| 256 |
*
|
|
| 257 |
* @param action Description of Parameter
|
|
| 258 |
* @param menu Description of Parameter
|
|
| 259 |
*/
|
|
| 260 | 0 |
protected void removeMenuItem(CommandAction action, JMenu menu) |
| 261 |
{
|
|
| 262 | 0 |
JMenuItem item = action.getMenuItem(); |
| 263 |
|
|
| 264 | 0 |
menu.remove(item); |
| 265 |
} |
|
| 266 |
|
|
| 267 |
|
|
| 268 |
/** Description of the Method */
|
|
| 269 | 0 |
protected void update() |
| 270 |
{
|
|
| 271 | 0 |
for (int i = 0; i < this.listeners.size(); i++) |
| 272 |
{
|
|
| 273 | 0 |
MenuBarService.Listener o = (MenuBarService.Listener) this.listeners.elementAt(i);
|
| 274 | 0 |
o.update(this.menuBar);
|
| 275 |
} |
|
| 276 |
} |
|
| 277 |
} |
|
| 278 |
|
|
| 279 |
|
|
||||||||||