01: /*
02:
03: * LoadResource.java
04:
05: *
06:
07: * Created on October 20, 2006, 3:58 PM
08:
09: *
10:
11: * To change this template, choose Tools | Template Manager
12:
13: * and open the template in the editor.
14:
15: */
16:
17: package org.netbeans.modules.mobility.snippets;
18:
19: import javax.swing.text.BadLocationException;
20:
21: import javax.swing.text.JTextComponent;
22:
23: import org.openide.text.ActiveEditorDrop;
24:
25: /**
26:
27: *
28:
29: * @author bohemius
30:
31: */
32:
33: public class LoadImage implements ActiveEditorDrop {
34:
35: /** Creates a new instance of LoadResource */
36:
37: public LoadImage() {
38:
39: }
40:
41: public boolean handleTransfer(JTextComponent targetComponent) {
42:
43: StringBuffer body = new StringBuffer("");
44:
45: body
46: .append("public javax.microedition.lcdui.Image loadImage(String location) {\n");
47:
48: body.append("try {\n");
49:
50: body
51: .append("return javax.microedition.lcdui.Image.createImage (location);\n");
52:
53: body.append("}\n");
54:
55: body.append("catch (java.io.IOException e) {\n");
56:
57: body
58: .append("throw new RuntimeException(\"Unable to load Image: \"+e);\n");
59:
60: body.append("}\n");
61:
62: body.append("}\n\n");
63:
64: try {
65:
66: SnippetsPaletteUtilities.insert(body.toString(),
67: targetComponent);
68:
69: } catch (BadLocationException ble) {
70:
71: return false;
72:
73: }
74:
75: return true;
76:
77: }
78:
79: }
|