Project

General

Profile

Download (2.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.element;
10

    
11
import java.net.URI;
12

    
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.browser.Browser;
15
import org.eclipse.swt.events.ControlEvent;
16
import org.eclipse.swt.events.ControlListener;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.ui.forms.widgets.TableWrapData;
19

    
20

    
21

    
22
/**
23
 * <p>BrowserElement class.</p>
24
 *
25
 * @author n.hoffmann
26
 */
27
public class BrowserElement extends AbstractCdmFormElement implements ControlListener{
28

    
29
	private Browser browser;
30

    
31
	private String imageUriString;
32

    
33
	/**
34
	 * <p>Constructor for BrowserElement.</p>
35
	 *
36
	 * @param style a int.
37
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
38
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
39
	 * @param imageUri a {@link java.net.URI} object.
40
	 */
41
	protected BrowserElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
42
		super(formFactory, parentElement);
43
		formFactory.createLabel(getLayoutComposite(), "");
44

    
45
		browser = new Browser(getLayoutComposite(), SWT.NONE);
46
		addControl(browser);
47

    
48
		getLayoutComposite().setLayoutData(LayoutConstants.FILL());
49

    
50

    
51
		layoutBrowser();
52

    
53
		showBrowser();
54
		browser.addControlListener(this);
55

    
56
		this.setImageUri(imageUri);
57
	}
58

    
59
	private void layoutBrowser() {
60
		TableWrapData layoutData = LayoutConstants.FILL();
61
		layoutData.heightHint = 1000;
62

    
63
		browser.setLayoutData(layoutData);
64
	}
65

    
66
	private void showBrowser() {
67

    
68
		String html = "";
69
		html = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>";
70
		html += "<img width=\"" + calculateWidth() + "\" src=\"" + getImageUriString() + "\" />";
71
		html += "</BODY></HTML>";
72

    
73
		browser.setText(html);
74
	}
75

    
76
	/**
77
	 * <p>calculateWidth</p>
78
	 *
79
	 * @return a int.
80
	 */
81
	public int calculateWidth() {
82
		Rectangle boundaries = browser.getBounds();
83
		return boundaries.width;
84
	}
85

    
86
	@Override
87
    public void controlMoved(ControlEvent e) {
88
		showBrowser();
89
	}
90

    
91
	@Override
92
    public void controlResized(ControlEvent e) {
93
		showBrowser();
94
	}
95

    
96
	/**
97
	 * <p>setImageUri</p>
98
	 *
99
	 * @param imageUri the imageUri to set
100
	 */
101
	public void setImageUri(URI imageUri) {
102
		setImageUriString(imageUri != null ? imageUri.toString() : "");
103
	}
104

    
105
	/**
106
	 * <p>Setter for the field <code>imageUriString</code>.</p>
107
	 *
108
	 * @param imageUriString a {@link java.lang.String} object.
109
	 */
110
	public void setImageUriString(String imageUriString){
111
		this.imageUriString = imageUriString;
112
		showBrowser();
113
	}
114

    
115
	/**
116
	 * <p>Getter for the field <code>imageUriString</code>.</p>
117
	 *
118
	 * @return the imageUri
119
	 */
120
	public String getImageUriString() {
121
		return imageUriString;
122
	}
123
}
(7-7/53)