3
3
import java .awt .BorderLayout ;
4
4
import java .awt .Container ;
5
5
import java .awt .Dimension ;
6
+ import java .awt .Graphics ;
6
7
import java .awt .Image ;
7
8
import java .awt .image .BufferedImage ;
8
9
import java .awt .print .Printable ;
27
28
import org .cytoscape .view .presentation .RenderingEngine ;
28
29
import org .cytoscape .work .swing .DialogTaskManager ;
29
30
31
+ import com .jogamp .common .util .awt .AWTEDTExecutor ;
32
+ import com .jogamp .nativewindow .awt .AWTPrintLifecycle ;
33
+
30
34
/**
31
35
* This class represents a Cy3DRenderingEngine, responsible for
32
36
* creating a rendering of a {@link CyNetwork}.
@@ -37,6 +41,7 @@ class Cy3DRenderingEngine implements RenderingEngine<CyNetwork> {
37
41
private final VisualLexicon visualLexicon ;
38
42
39
43
private GLJPanel panel ;
44
+ private Properties props ;
40
45
41
46
42
47
public Cy3DRenderingEngine (
@@ -51,6 +56,7 @@ public Cy3DRenderingEngine(
51
56
52
57
this .networkView = viewModel ;
53
58
this .visualLexicon = visualLexicon ;
59
+ this .props = new Properties ();
54
60
55
61
setUpCanvas (component , inputComponent , configuration , eventBusProvider , taskFactoryListener , taskManager );
56
62
}
@@ -108,7 +114,7 @@ public VisualLexicon getVisualLexicon() {
108
114
109
115
@ Override
110
116
public Properties getProperties () {
111
- return null ;
117
+ return props ; // can't return null or (File > Print) won't work
112
118
}
113
119
114
120
@ Override
@@ -135,7 +141,20 @@ public <V> Icon createIcon(VisualProperty<V> vp, V value, int width, int height)
135
141
}
136
142
137
143
@ Override
138
- public void printCanvas (java .awt .Graphics printCanvas ) {
144
+ public void printCanvas (final Graphics printCanvas ) {
145
+ double scaleX = (double )panel .getWidth () / (double )panel .getSurfaceWidth ();
146
+ double scaleY = (double )panel .getHeight () / (double )panel .getSurfaceHeight ();
147
+
148
+ AWTPrintLifecycle .Context ctx = AWTPrintLifecycle .Context .setupPrint (panel , scaleX , scaleY , 0 , -1 , -1 );
149
+ try {
150
+ AWTEDTExecutor .singleton .invoke (true , new Runnable () {
151
+ public void run () {
152
+ panel .print (printCanvas );
153
+ }
154
+ });
155
+ } finally {
156
+ ctx .releasePrint ();
157
+ }
139
158
}
140
159
141
160
@ Override
0 commit comments