1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 public class JFaceImageTag extends ImageTag {
33
34 /***
35 * @return the parent window
36 */
37 public Window getParentWindow() {
38 ApplicationWindowTag tag =
39 (ApplicationWindowTag) findAncestorWithClass(ApplicationWindowTag.class);
40 if (tag != null) {
41 return tag.getWindow();
42 }
43 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 window.getShell().setImage(image);
53 }
54
55
56
57
58 public void doTag(XMLOutput output) throws JellyTagException {
59
60
61 invokeBody(output);
62
63 Widget parent = getParentWidget();
64 Window window = null;
65 if (parent == null) {
66 window = getParentWindow();
67 if (window != null && window instanceof ApplicationWindowImpl) {
68 parent = ((ApplicationWindowImpl) window).getContents();
69 }
70 }
71
72 if (parent == null && window == null) {
73 throw new JellyTagException("This tag must be nested within a Widget or a Window");
74 }
75
76 Image image = new Image(parent.getDisplay(), getSrc());
77 if (window != null) {
78 setWindowImage(window, image);
79 } else {
80 setWidgetImage(parent, image);
81 }
82
83 }
84
85 }