-
Notifications
You must be signed in to change notification settings - Fork 2
/
wsAccess.js
69 lines (61 loc) · 2.3 KB
/
wsAccess.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function applicationStarted(pluginWorkspaceAccess) {
var imageHandler = {
editImage: function(editContext){return null;},
editImage: function(url){return false;},
canHandleFileType: function(type){return type.equals("cgm")},
clearCache: function(){},
getImageLayoutInformation: function(cp, rc){
image = getCGMImage(pluginWorkspaceAccess, cp, rc);
return new Packages.ro.sync.exml.workspace.api.images.handlers.ImageLayoutInformation(0, 0, image.getWidth(null), image.getHeight(null));
},
getImage: function(cp, rc){
return getCGMImage(pluginWorkspaceAccess, cp, rc);
}
}
/**
* This line overrides the oXygen default CGM image handler.
*
* Uncomment to activate this feature.
*/
//pluginWorkspaceAccess.getImageUtilities().addImageHandler(new JavaAdapter(Packages.ro.sync.exml.workspace.api.images.handlers.EditImageHandler, imageHandler));
}
function getCGMImage(pluginWorkspaceAccess, cp, rc){
var cgmPanel = new Packages.net.sf.jcgm.core.CGMPanel();
cgmPanel.setSize(800, 600);
cgmPanel.open(cp.getUrl());
// Create a new bufferedImage with imagePanel size
var image = new Packages.java.awt.image.BufferedImage(800, 600, Packages.java.awt.image.BufferedImage.TYPE_INT_RGB);
// Create a graphics context from the new image
var graphics = image.createGraphics();
graphics.setColor(Packages.java.awt.Color.WHITE);
graphics.fillRect(0, 0, 800, 600);
var paintComponentMethod = getPaintMethod(cgmPanel.getClass());
paintComponentMethod.setAccessible(true);
paintComponentMethod.invoke(cgmPanel, graphics);
return image;
}
/**
* Looks inside the provided class to find the "paint" method.
*
* @param clazz The class with public "paint" method.
* @return The "paint" method.
*/
function getPaintMethod(clazz) {
var paint = null;
while (paint == null && clazz != null) {
try {
var declMethods = clazz.getDeclaredMethods();
for(i=0;i<declMethods.length;i++){
if(declMethods[i].getName().equals("paint")){
paint = declMethods[i];
}
}
} catch (e) {
// No such method.
}
clazz = clazz.getSuperclass();
}
return paint;
}
function applicationClosing(pluginWorkspaceAccess) {
}