Clover coverage report - AdWT - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:14:10 CET
file stats: LOC: 277   Methods: 15
NCLOC: 130   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ToolBarServiceProvider.java 0% 0% 0% 0%
coverage
 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.Hashtable;
 12   
 import java.util.Iterator;
 13   
 import java.util.Vector;
 14   
 
 15   
 import javax.swing.Action;
 16   
 import javax.swing.Icon;
 17   
 import javax.swing.JButton;
 18   
 import javax.swing.JToolBar;
 19   
 
 20   
 import org.apache.log4j.Logger;
 21   
 import org.ejtools.adwt.action.CommandAction;
 22   
 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
 23   
 
 24   
 /**
 25   
  * Description of the Class
 26   
  *
 27   
  * @author    Laurent Etiemble
 28   
  * @version   $Revision: 1.5 $
 29   
  * @todo      Javadoc to complete
 30   
  */
 31   
 public class ToolBarServiceProvider extends CustomBeanContextServiceProvider implements ToolBarService
 32   
 {
 33   
    /** Description of the Field */
 34   
    private Hashtable bars = new Hashtable();
 35   
    /** Description of the Field */
 36   
    private boolean bigIcons = false;
 37   
    /** Description of the Field */
 38   
    private ToolBarService service = null;
 39   
    /** Description of the Field */
 40   
    private JToolBar toolBar = new JToolBar();
 41   
    /** Description of the Field */
 42   
    private static Logger logger = Logger.getLogger(ToolBarServiceProvider.class);
 43   
 
 44   
 
 45   
    /** Constructor for the ToolBarServiceProvider object */
 46  0
    public ToolBarServiceProvider()
 47   
    {
 48  0
       this.service = this;
 49   
    }
 50   
 
 51   
 
 52   
    /**
 53   
     * Gets the container attribute of the ToolBarServiceProvider object
 54   
     *
 55   
     * @return   The container value
 56   
     */
 57  0
    public Container getContainer()
 58   
    {
 59  0
       return this.toolBar;
 60   
    }
 61   
 
 62   
 
 63   
    /**
 64   
     * Gets the currentServiceSelectors attribute of the ApplicationServiceProvider object
 65   
     *
 66   
     * @param bcs           Description of Parameter
 67   
     * @param serviceClass  Description of Parameter
 68   
     * @return              The currentServiceSelectors value
 69   
     */
 70  0
    public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass)
 71   
    {
 72  0
       return new Vector().iterator();
 73   
    }
 74   
 
 75   
 
 76   
    /**
 77   
     * Gets the service attribute of the ApplicationServiceProvider object
 78   
     *
 79   
     * @param bcs              Description of Parameter
 80   
     * @param requestor        Description of Parameter
 81   
     * @param serviceClass     Description of Parameter
 82   
     * @param serviceSelector  Description of Parameter
 83   
     * @return                 The service value
 84   
     */
 85  0
    public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector)
 86   
    {
 87  0
       return service;
 88   
    }
 89   
 
 90   
 
 91   
    /**
 92   
     * Description of the Method
 93   
     *
 94   
     * @param action  Description of Parameter
 95   
     */
 96  0
    public void register(CommandAction action)
 97   
    {
 98  0
       String menu = action.getMenu();
 99  0
       JToolBarWrapper bar = (JToolBarWrapper) this.bars.get(menu);
 100   
 
 101  0
       if (bar == null)
 102   
       {
 103  0
          bar = new JToolBarWrapper();
 104  0
          bar.setFloatable(false);
 105   
 
 106  0
          this.bars.put(menu, bar);
 107   
 
 108  0
          if (this.toolBar.getComponentCount() > 0)
 109   
          {
 110  0
             this.toolBar.addSeparator();
 111   
          }
 112   
 
 113  0
          this.toolBar.add(bar);
 114   
       }
 115   
 
 116  0
       JButton button = bar.add(action);
 117   
 
 118  0
       Object o = null;
 119  0
       if (this.bigIcons)
 120   
       {
 121  0
          o = action.getValue(CommandAction.ICON);
 122   
       }
 123   
       else
 124   
       {
 125  0
          o = action.getValue(Action.SMALL_ICON);
 126   
       }
 127  0
       if (o != null)
 128   
       {
 129  0
          button.setIcon((Icon) o);
 130   
       }
 131  0
       if (action.getValue(CommandAction.TOOLTIP) != null)
 132   
       {
 133  0
          button.setToolTipText((String) action.getValue(CommandAction.TOOLTIP));
 134   
       }
 135   
 
 136  0
       toolBar.validate();
 137  0
       logger.debug("Button registered");
 138   
    }
 139   
 
 140   
 
 141   
    /**
 142   
     * Description of the Method
 143   
     *
 144   
     * @param bcs        Description of Parameter
 145   
     * @param requestor  Description of Parameter
 146   
     * @param service    Description of Parameter
 147   
     */
 148  0
    public void releaseService(BeanContextServices bcs, Object requestor, Object service) { }
 149   
 
 150   
 
 151   
    /**
 152   
     * Sets the bigIcons.
 153   
     *
 154   
     * @param bigIcons  The bigIcons to set
 155   
     */
 156  0
    public void setBigIcons(boolean bigIcons)
 157   
    {
 158  0
       if (this.bars.size() > 0)
 159   
       {
 160  0
          throw new IllegalStateException("Cannot change icon size if buttons are registered");
 161   
       }
 162  0
       this.bigIcons = bigIcons;
 163   
    }
 164   
 
 165   
 
 166   
    /**
 167   
     * Description of the Method
 168   
     *
 169   
     * @param action  Description of Parameter
 170   
     */
 171  0
    public void unregister(CommandAction action)
 172   
    {
 173  0
       String menu = action.getMenu();
 174  0
       JToolBarWrapper bar = (JToolBarWrapper) this.bars.get(menu);
 175   
 
 176  0
       if (bar == null)
 177   
       {
 178  0
          return;
 179   
       }
 180   
 
 181  0
       bar.remove(action);
 182  0
       toolBar.validate();
 183  0
       logger.debug("Button unregistered");
 184   
    }
 185   
 
 186   
 
 187   
    /**
 188   
     * @return   The serviceClass value
 189   
     */
 190  0
    protected Class[] getServiceClass()
 191   
    {
 192  0
       return new Class[]{ToolBarService.class};
 193   
    }
 194   
 
 195   
 
 196   
    /**
 197   
     * Description of the Class
 198   
     *
 199   
     * @author    laurent
 200   
     * @version   $Revision: 1.5 $
 201   
     */
 202   
    protected class JToolBarWrapper extends JToolBar
 203   
    {
 204   
       /** Description of the Field */
 205   
       protected Hashtable buttons = new Hashtable();
 206   
 
 207   
 
 208   
       /** Constructor for JToolBarWrapper. */
 209  0
       public JToolBarWrapper()
 210   
       {
 211  0
          super();
 212  0
          this.setBorder(null);
 213   
       }
 214   
 
 215   
 
 216   
       /**
 217   
        * Constructor for JToolBarWrapper.
 218   
        *
 219   
        * @param orientation
 220   
        */
 221  0
       public JToolBarWrapper(int orientation)
 222   
       {
 223  0
          super(orientation);
 224   
       }
 225   
 
 226   
 
 227   
       /**
 228   
        * Constructor for JToolBarWrapper.
 229   
        *
 230   
        * @param name
 231   
        */
 232  0
       public JToolBarWrapper(String name)
 233   
       {
 234  0
          super(name);
 235   
       }
 236   
 
 237   
 
 238   
       /**
 239   
        * Constructor for JToolBarWrapper.
 240   
        *
 241   
        * @param name
 242   
        * @param orientation
 243   
        */
 244  0
       public JToolBarWrapper(String name, int orientation)
 245   
       {
 246  0
          super(name, orientation);
 247   
       }
 248   
 
 249   
 
 250   
       /**
 251   
        * Description of the Method
 252   
        *
 253   
        * @param action  Description of Parameter
 254   
        * @return        Description of the Returned Value
 255   
        */
 256  0
       public JButton add(Action action)
 257   
       {
 258  0
          JButton button = super.add(action);
 259  0
          this.buttons.put(action, button);
 260  0
          return button;
 261   
       }
 262   
 
 263   
 
 264   
       /**
 265   
        * Description of the Method
 266   
        *
 267   
        * @param action  Description of Parameter
 268   
        */
 269  0
       public void remove(Action action)
 270   
       {
 271  0
          JButton button = (JButton) this.buttons.get(action);
 272  0
          this.remove(button);
 273   
       }
 274   
    }
 275   
 }
 276   
 
 277