| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jelly.tags.swt.MenuTag |
|
|
| 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.jelly.JellyTagException; |
|
| 19 | import org.apache.commons.logging.Log; |
|
| 20 | import org.apache.commons.logging.LogFactory; |
|
| 21 | import org.eclipse.swt.widgets.Control; |
|
| 22 | import org.eclipse.swt.widgets.Decorations; |
|
| 23 | import org.eclipse.swt.widgets.Menu; |
|
| 24 | import org.eclipse.swt.widgets.MenuItem; |
|
| 25 | import org.eclipse.swt.widgets.Widget; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * This tag creates an SWT Menu |
|
| 29 | * </p> |
|
| 30 | * |
|
| 31 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
| 32 | * @version 1.1 |
|
| 33 | */ |
|
| 34 | public class MenuTag extends WidgetTag { |
|
| 35 | ||
| 36 | /** The Log to which logging calls will be made. */ |
|
| 37 | 0 | private static final Log log = LogFactory.getLog(MenuTag.class); |
| 38 | ||
| 39 | public MenuTag() { |
|
| 40 | 0 | super(Menu.class); |
| 41 | 0 | } |
| 42 | ||
| 43 | public MenuTag(int style) { |
|
| 44 | 0 | super(Menu.class, style); |
| 45 | 0 | } |
| 46 | ||
| 47 | // Implementation methods |
|
| 48 | //------------------------------------------------------------------------- |
|
| 49 | ||
| 50 | /** |
|
| 51 | * Provides a strategy method to allow a new child widget to be attached to |
|
| 52 | * its parent |
|
| 53 | * |
|
| 54 | * @param parent is the parent widget which is never null |
|
| 55 | * @param widget is the new child widget to be attached to the parent |
|
| 56 | */ |
|
| 57 | protected void attachWidgets(Object parent, Widget widget) { |
|
| 58 | 0 | Menu menu = (Menu) widget; |
| 59 | 0 | if (parent instanceof Decorations) { |
| 60 | 0 | Decorations shell = (Decorations) parent; |
| 61 | 0 | shell.setMenuBar(menu); |
| 62 | } |
|
| 63 | 0 | else if (parent instanceof Control) { |
| 64 | 0 | Control control = (Control) parent; |
| 65 | 0 | control.setMenu(menu); |
| 66 | } |
|
| 67 | 0 | else if (parent instanceof MenuItem) { |
| 68 | 0 | MenuItem menuItem = (MenuItem) parent; |
| 69 | 0 | menuItem.setMenu(menu); |
| 70 | } |
|
| 71 | 0 | } |
| 72 | ||
| 73 | /** |
|
| 74 | * @see org.apache.commons.jelly.tags.swt.WidgetTag#createWidget(java.lang.Class, org.eclipse.swt.widgets.Widget, int) |
|
| 75 | */ |
|
| 76 | protected Object createWidget(Class theClass, Widget parent, int style) |
|
| 77 | throws JellyTagException { |
|
| 78 | ||
| 79 | 0 | if (parent instanceof Decorations) { |
| 80 | 0 | return super.createWidget(theClass, parent, style); |
| 81 | } |
|
| 82 | else { |
|
| 83 | 0 | if (parent instanceof Menu) { |
| 84 | 0 | return new Menu((Menu) parent); |
| 85 | } |
|
| 86 | 0 | else if (parent instanceof MenuItem) { |
| 87 | 0 | return new Menu((MenuItem) parent); |
| 88 | } |
|
| 89 | 0 | else if (parent instanceof Control) { |
| 90 | 0 | return new Menu((Control) parent); |
| 91 | } |
|
| 92 | else { |
|
| 93 | 0 | throw new JellyTagException("This tag must be nested inside a <shell>, <menu>, <menuItem> or control tag"); |
| 94 | } |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||
| 98 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |