svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / programming / CreateHtmlPanelFunction.java @ 46041
History | View | Annotate | Download (2.04 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.image.BufferedImage; |
5 |
import java.net.URL; |
6 |
import javax.swing.ImageIcon; |
7 |
import javax.swing.JLabel; |
8 |
import org.apache.commons.lang3.Range; |
9 |
import org.gvsig.expressionevaluator.Function; |
10 |
import org.gvsig.expressionevaluator.Interpreter; |
11 |
import org.gvsig.expressionevaluator.impl.function.image.ImageFromHTMLFunction; |
12 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
13 |
import org.slf4j.Logger; |
14 |
import org.slf4j.LoggerFactory; |
15 |
|
16 |
public class CreateHtmlPanelFunction extends AbstractFunction { |
17 |
private static final Logger LOGGER = LoggerFactory.getLogger(CreateHtmlPanelFunction.class); |
18 |
|
19 |
public CreateHtmlPanelFunction() {
|
20 |
super(Function.GROUP_PROGRAMMING,
|
21 |
"CREATE_HTMLPANEL",
|
22 |
Range.is(1),
|
23 |
null,
|
24 |
"CREATE_HTMLPANEL"+ "({{with}}, height, source)", |
25 |
new String[]{ |
26 |
"width - with of the image in pixels",
|
27 |
"height - height of the image in pixels",
|
28 |
"source - HTML source or URL"
|
29 |
}, |
30 |
"JPanel",
|
31 |
false
|
32 |
); |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public boolean allowConstantFolding() { |
37 |
return true; |
38 |
} |
39 |
|
40 |
@Override
|
41 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
42 |
int width = this.getInt(args, 0); |
43 |
int height = this.getInt(args, 1); |
44 |
String source = this.getStr(args, 2); |
45 |
URL url = null; |
46 |
try {
|
47 |
url = new URL(source); |
48 |
} catch (Exception ex) { |
49 |
LOGGER.debug("Can't parse url", ex);
|
50 |
} |
51 |
BufferedImage img = ImageFromHTMLFunction.createImageFromHTML(width, height, url, source);
|
52 |
if( img == null ) { |
53 |
return null; |
54 |
} |
55 |
JLabel comp = new JLabel(new ImageIcon(img)); |
56 |
comp.setPreferredSize(new Dimension(width, height)); |
57 |
comp.setSize(new Dimension(width, height)); |
58 |
comp.setOpaque(false);
|
59 |
return comp;
|
60 |
} |
61 |
} |