%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.jface.JFaceImageTag |
|
|
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.jface; |
|
17 | ||
18 | import org.apache.commons.jelly.JellyTagException; |
|
19 | import org.apache.commons.jelly.XMLOutput; |
|
20 | import org.apache.commons.jelly.tags.jface.window.ApplicationWindowImpl; |
|
21 | import org.apache.commons.jelly.tags.jface.window.ApplicationWindowTag; |
|
22 | import org.apache.commons.jelly.tags.swt.ImageTag; |
|
23 | import org.eclipse.jface.window.Window; |
|
24 | import org.eclipse.swt.graphics.Image; |
|
25 | import org.eclipse.swt.widgets.Widget; |
|
26 | ||
27 | /** |
|
28 | * Implementation of SWT ImageTag |
|
29 | * |
|
30 | * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a> |
|
31 | */ |
|
32 | 0 | public class JFaceImageTag extends ImageTag { |
33 | ||
34 | /** |
|
35 | * @return the parent window |
|
36 | */ |
|
37 | public Window getParentWindow() { |
|
38 | 0 | ApplicationWindowTag tag = |
39 | (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class); |
|
40 | 0 | if (tag != null) { |
41 | 0 | return tag.getWindow(); |
42 | } |
|
43 | 0 | return null; |
44 | } |
|
45 | ||
46 | /** |
|
47 | * Set default image Window |
|
48 | * @param window |
|
49 | * @param image |
|
50 | */ |
|
51 | private void setWindowImage(Window window, Image image) { |
|
52 | 0 | window.getShell().setImage(image); |
53 | 0 | } |
54 | ||
55 | /* |
|
56 | * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) |
|
57 | */ |
|
58 | public void doTag(XMLOutput output) throws JellyTagException { |
|
59 | ||
60 | // invoke by body just in case some nested tag configures me |
|
61 | 0 | invokeBody(output); |
62 | ||
63 | 0 | Widget parent = getParentWidget(); |
64 | 0 | Window window = null; |
65 | 0 | if (parent == null) { |
66 | 0 | window = getParentWindow(); |
67 | 0 | if (window != null && window instanceof ApplicationWindowImpl) { |
68 | 0 | parent = ((ApplicationWindowImpl) window).getContents(); |
69 | } |
|
70 | } |
|
71 | ||
72 | 0 | if (parent == null && window == class="keyword">null) { |
73 | 0 | throw new JellyTagException("This tag must be nested within a Widget or a Window"); |
74 | } |
|
75 | ||
76 | 0 | Image image = new Image(parent.getDisplay(), getSrc()); |
77 | 0 | if (window != null) { |
78 | 0 | setWindowImage(window, image); |
79 | } else { |
|
80 | 0 | setWidgetImage(parent, image); |
81 | } |
|
82 | ||
83 | 0 | } |
84 | ||
85 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |