Coverage report

  %line %branch
org.apache.commons.jelly.tags.swt.SwtTagLibrary$2
0% 
0% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.jelly.tags.swt;
 17  
 
 18  
 import org.apache.commons.beanutils.ConvertUtils;
 19  
 import org.apache.commons.jelly.JellyException;
 20  
 import org.apache.commons.jelly.Tag;
 21  
 import org.apache.commons.jelly.TagLibrary;
 22  
 import org.apache.commons.jelly.impl.TagFactory;
 23  
 import org.apache.commons.jelly.tags.swt.converters.ColorConverter;
 24  
 import org.apache.commons.jelly.tags.swt.converters.PointConverter;
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.eclipse.swt.SWT;
 28  
 import org.eclipse.swt.custom.CTabFolder;
 29  
 import org.eclipse.swt.custom.CTabItem;
 30  
 import org.eclipse.swt.custom.ScrolledComposite;
 31  
 import org.eclipse.swt.custom.TableTree;
 32  
 import org.eclipse.swt.custom.TableTreeItem;
 33  
 import org.eclipse.swt.graphics.Color;
 34  
 import org.eclipse.swt.graphics.Point;
 35  
 import org.eclipse.swt.layout.FillLayout;
 36  
 import org.eclipse.swt.layout.GridData;
 37  
 import org.eclipse.swt.layout.GridLayout;
 38  
 import org.eclipse.swt.layout.RowData;
 39  
 import org.eclipse.swt.layout.RowLayout;
 40  
 import org.eclipse.swt.widgets.Button;
 41  
 import org.eclipse.swt.widgets.Canvas;
 42  
 import org.eclipse.swt.widgets.Caret;
 43  
 import org.eclipse.swt.widgets.ColorDialog;
 44  
 import org.eclipse.swt.widgets.Combo;
 45  
 import org.eclipse.swt.widgets.Composite;
 46  
 import org.eclipse.swt.widgets.CoolBar;
 47  
 import org.eclipse.swt.widgets.CoolItem;
 48  
 import org.eclipse.swt.widgets.Decorations;
 49  
 import org.eclipse.swt.widgets.DirectoryDialog;
 50  
 import org.eclipse.swt.widgets.FileDialog;
 51  
 import org.eclipse.swt.widgets.FontDialog;
 52  
 import org.eclipse.swt.widgets.Group;
 53  
 import org.eclipse.swt.widgets.Label;
 54  
 import org.eclipse.swt.widgets.List;
 55  
 import org.eclipse.swt.widgets.MenuItem;
 56  
 import org.eclipse.swt.widgets.MessageBox;
 57  
 import org.eclipse.swt.widgets.ProgressBar;
 58  
 import org.eclipse.swt.widgets.Sash;
 59  
 import org.eclipse.swt.widgets.Scale;
 60  
 import org.eclipse.swt.widgets.Shell;
 61  
 import org.eclipse.swt.widgets.Slider;
 62  
 import org.eclipse.swt.widgets.TabFolder;
 63  
 import org.eclipse.swt.widgets.TabItem;
 64  
 import org.eclipse.swt.widgets.Table;
 65  
 import org.eclipse.swt.widgets.TableColumn;
 66  
 import org.eclipse.swt.widgets.TableItem;
 67  
 import org.eclipse.swt.widgets.Text;
 68  
 import org.eclipse.swt.widgets.ToolBar;
 69  
 import org.eclipse.swt.widgets.ToolItem;
 70  
 import org.eclipse.swt.widgets.Tracker;
 71  
 import org.eclipse.swt.widgets.Tree;
 72  
 import org.eclipse.swt.widgets.TreeItem;
 73  
 import org.xml.sax.Attributes;
 74  
 
 75  
 /**
 76  
  * A Jelly custom tag library that creates SWT user interfaces
 77  
  *
 78  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 79  
  * @version 1.1
 80  
  */
 81  
 public class SwtTagLibrary extends TagLibrary {
 82  
 
 83  
     /** The Log to which logging calls will be made. */
 84  
     private static final Log log = LogFactory.getLog(SwtTagLibrary.class);
 85  
 
 86  
     static {
 87  
         // register the various beanutils Converters from Strings to various SWT types
 88  
         ConvertUtils.register( new PointConverter(), Point.class );
 89  
         ConvertUtils.register( new ColorConverter(), Color.class );
 90  
     }
 91  
 
 92  
     public SwtTagLibrary() {
 93  
         // widgets
 94  
         registerWidgetTag( "button", Button.class, SWT.BORDER | SWT.PUSH | SWT.CENTER );
 95  
         registerWidgetTag( "canvas", Canvas.class );
 96  
         registerWidgetTag( "caret", Caret.class );
 97  
         registerWidgetTag( "combo", Combo.class, SWT.DROP_DOWN );
 98  
         registerWidgetTag( "composite", Composite.class );
 99  
          registerWidgetTag( "scrolledComposite", ScrolledComposite.class, SWT.H_SCROLL | SWT.V_SCROLL);
 100  
         registerWidgetTag( "coolBar", CoolBar.class, SWT.VERTICAL );
 101  
         registerWidgetTag( "coolItem", CoolItem.class );
 102  
         registerWidgetTag( "decorations", Decorations.class );
 103  
         registerWidgetTag( "group", Group.class );
 104  
         registerWidgetTag( "label", Label.class, SWT.HORIZONTAL | SWT.SHADOW_IN );
 105  
         registerWidgetTag( "list", List.class );
 106  
         registerMenuTag( "menu", SWT.DEFAULT );
 107  
         registerMenuTag( "menuBar", SWT.BAR );
 108  
         registerWidgetTag( "menuSeparator", MenuItem.class, SWT.SEPARATOR );
 109  
         registerWidgetTag( "menuItem", MenuItem.class );
 110  
         registerWidgetTag( "messageBox", MessageBox.class );
 111  
         registerWidgetTag( "progressBar", ProgressBar.class, SWT.HORIZONTAL );
 112  
         registerWidgetTag( "sash", Sash.class );
 113  
         registerWidgetTag( "scale", Scale.class );
 114  
         registerWidgetTag( "shell", Shell.class, SWT.BORDER | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.TITLE );
 115  
         registerWidgetTag( "slider", Slider.class );
 116  
         registerWidgetTag( "tabFolder", TabFolder.class );
 117  
         registerWidgetTag( "tabItem", TabItem.class );
 118  
         registerWidgetTag( "table", Table.class, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION );
 119  
         registerWidgetTag( "tableColumn", TableColumn.class );
 120  
         registerWidgetTag( "tableItem", TableItem.class );
 121  
         registerWidgetTag( "text", Text.class );
 122  
         registerWidgetTag( "toolBar", ToolBar.class, SWT.VERTICAL );
 123  
         registerWidgetTag( "toolItem", ToolItem.class );
 124  
         registerWidgetTag( "tracker", Tracker.class );
 125  
         registerWidgetTag( "tree", Tree.class, SWT.MULTI );
 126  
         registerWidgetTag( "treeItem", TreeItem.class );
 127  
 
 128  
         // custom widgets
 129  
         registerWidgetTag( "cTabFolder", CTabFolder.class );
 130  
         registerWidgetTag( "cTabItem", CTabItem.class );
 131  
         registerWidgetTag( "tableTree", TableTree.class );
 132  
         registerWidgetTag( "tableTreeItem", TableTreeItem.class );
 133  
 
 134  
         // layouts
 135  
         registerLayoutTag("fillLayout", FillLayout.class);
 136  
         registerLayoutTag("gridLayout", GridLayout.class);
 137  
         registerLayoutTag("rowLayout", RowLayout.class);
 138  
 
 139  
         // layout data objects
 140  
         registerLayoutDataTag( "gridData", GridData.class );
 141  
         registerLayoutDataTag( "rowData", RowData.class );
 142  
 
 143  
         // dialogs
 144  
         registerDialogTag( "colorDialog", ColorDialog.class );
 145  
         registerDialogTag( "directoryDialog", DirectoryDialog.class );
 146  
         registerDialogTag( "fileDialog", FileDialog.class );
 147  
         registerDialogTag( "fontDialog", FontDialog.class );
 148  
 
 149  
         // events
 150  
         registerTag("onEvent", OnEventTag.class);
 151  
 
 152  
         // other tags
 153  
         registerTag("color", ColorTag.class);
 154  
         registerTag("colour", FontTag.class);
 155  
         registerTag("font", FontTag.class);
 156  
         registerTag("gc", GCTag.class);
 157  
         registerTag("image", ImageTag.class);
 158  
 
 159  
     }
 160  
 
 161  
     /**
 162  
      * Register a layout tag for the given name
 163  
      */
 164  
     protected void registerLayoutTag(String name, final Class layoutClass) {
 165  
         registerTagFactory(
 166  
             name,
 167  
             new TagFactory() {
 168  
                 /**
 169  
                  * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
 170  
                  */
 171  
                 public Tag createTag(String name, Attributes attributes)
 172  
                     throws JellyException {
 173  
                     return new LayoutTag(layoutClass);
 174  
                 }
 175  
             }
 176  
         );
 177  
     }
 178  
 
 179  
     /**
 180  
      * Register a layout data tag for the given name
 181  
      */
 182  
     protected void registerLayoutDataTag(String name, final Class layoutDataClass) {
 183  
         registerTagFactory(
 184  
             name,
 185  
             new TagFactory() {
 186  
                 /**
 187  
                  * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
 188  
                  */
 189  0
                 public Tag createTag(String name, Attributes attributes)
 190  
                     throws JellyException {
 191  0
                     return new LayoutDataTag(layoutDataClass);
 192  
                 }
 193  
             }
 194  
         );
 195  
     }
 196  
 
 197  
     /**
 198  
      * Register a widget tag for the given name
 199  
      */
 200  
     protected void registerWidgetTag(String name, Class widgetClass) {
 201  
         registerWidgetTag(name, widgetClass, SWT.NULL);
 202  
     }
 203  
 
 204  
     /**
 205  
      * Register a widget tag for the given name
 206  
      */
 207  
     protected void registerWidgetTag(String name, final Class widgetClass, class="keyword">final int style) {
 208  
         registerTagFactory(
 209  
             name,
 210  
             new TagFactory() {
 211  
                 /**
 212  
                  * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
 213  
                  */
 214  
                 public Tag createTag(String name, Attributes attributes)
 215  
                     throws JellyException {
 216  
                     return new WidgetTag(widgetClass, style);
 217  
                 }
 218  
             }
 219  
         );
 220  
     }
 221  
 
 222  
     /**
 223  
      * Register a registerDialogTag tag for the given name
 224  
      */
 225  
     protected void registerDialogTag(String name, Class widgetClass) {
 226  
         registerDialogTag(name, widgetClass, SWT.NULL);
 227  
     }
 228  
 
 229  
     /**
 230  
        * Register a dialog tag for the given name
 231  
        */
 232  
     protected void registerDialogTag(String name, final Class widgetClass, class="keyword">final int style) {
 233  
           registerTagFactory(
 234  
               name,
 235  
               new TagFactory() {
 236  
                   /**
 237  
                    * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
 238  
                    */
 239  
                   public Tag createTag(String name, Attributes attributes)
 240  
                       throws JellyException {
 241  
                       return new DialogTag(widgetClass, style);
 242  
                   }
 243  
               }
 244  
           );
 245  
       }
 246  
 
 247  
     /**
 248  
      * Register a menu tag for the given name and style
 249  
      */
 250  
     protected void registerMenuTag(String name, final int style) {
 251  
         registerTagFactory(
 252  
             name,
 253  
             new TagFactory() {
 254  
                 /**
 255  
                  * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
 256  
                  */
 257  
                 public Tag createTag(String name, Attributes attributes)
 258  
                     throws JellyException {
 259  
                     return new MenuTag(style);
 260  
                 }
 261  
             }
 262  
         );
 263  
     }
 264  
 
 265  
 
 266  
 
 267  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.