1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.Component; |
24 |
|
import java.awt.Graphics; |
25 |
|
import java.io.File; |
26 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
27 |
|
|
28 |
|
import jalview.bin.Cache; |
29 |
|
import jalview.bin.Jalview; |
30 |
|
import jalview.io.JalviewFileChooser; |
31 |
|
import jalview.io.JalviewFileView; |
32 |
|
import jalview.io.exceptions.ImageOutputException; |
33 |
|
import jalview.util.ImageMaker; |
34 |
|
import jalview.util.ImageMaker.TYPE; |
35 |
|
import jalview.util.MessageManager; |
36 |
|
import jalview.util.Platform; |
37 |
|
import jalview.util.StringUtils; |
38 |
|
import jalview.util.imagemaker.BitmapImageSizing; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@author |
52 |
|
|
53 |
|
|
|
|
| 47% |
Uncovered Elements: 35 (66) |
Complexity: 18 |
Complexity Density: 0.38 |
|
54 |
|
public class ImageExporter |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
62 |
|
public interface ImageWriterI |
63 |
|
{ |
64 |
|
void exportImage(Graphics g) throws Exception; |
65 |
|
} |
66 |
|
|
67 |
|
private IProgressIndicator messageBoard; |
68 |
|
|
69 |
|
private ImageWriterI imageWriter; |
70 |
|
|
71 |
|
TYPE imageType; |
72 |
|
|
73 |
|
private String title; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@param |
80 |
|
@param |
81 |
|
@param |
82 |
|
@param |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
84 |
46 |
public ImageExporter(ImageWriterI writer, IProgressIndicator statusBar,... |
85 |
|
TYPE type, String fileTitle) |
86 |
|
{ |
87 |
46 |
this.imageWriter = writer; |
88 |
46 |
this.messageBoard = statusBar; |
89 |
46 |
this.imageType = type; |
90 |
46 |
this.title = fileTitle; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
@param |
101 |
|
|
102 |
|
@param |
103 |
|
@param |
104 |
|
@param |
105 |
|
|
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0 |
public void doExport(File file, Component parent, int width, int height,... |
108 |
|
String imageSource) throws ImageOutputException |
109 |
|
{ |
110 |
0 |
doExport(file, parent, width, height, imageSource, null, |
111 |
|
BitmapImageSizing.defaultBitmapImageSizing()); |
112 |
|
} |
113 |
|
|
|
|
| 29.5% |
Uncovered Elements: 31 (44) |
Complexity: 11 |
Complexity Density: 0.34 |
|
114 |
46 |
public void doExport(File file, Component parent, int width, int height,... |
115 |
|
String imageSource, String renderer, BitmapImageSizing userBis) |
116 |
|
throws ImageOutputException |
117 |
|
{ |
118 |
46 |
final long messageId = System.currentTimeMillis(); |
119 |
46 |
setStatus( |
120 |
|
MessageManager.formatMessage( |
121 |
|
"status.exporting_alignment_as_x_file", imageType), |
122 |
|
messageId); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
46 |
if (file == null && !Jalview.isHeadlessMode()) |
128 |
|
{ |
129 |
0 |
if (Desktop.instance.isInBatchMode()) |
130 |
|
{ |
131 |
|
|
132 |
0 |
throw (new ImageOutputException( |
133 |
|
"Need an output file to render to when exporting images in batch mode!")); |
134 |
|
} |
135 |
0 |
JalviewFileChooser chooser = imageType.getFileChooser(); |
136 |
0 |
chooser.setFileView(new JalviewFileView()); |
137 |
0 |
MessageManager.formatMessage("label.create_image_of", |
138 |
|
imageType.getName(), imageSource); |
139 |
0 |
String title = "Create " + imageType.getName() |
140 |
|
+ " image from alignment"; |
141 |
0 |
chooser.setDialogTitle(title); |
142 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
143 |
0 |
int value = chooser.showSaveDialog(parent); |
144 |
0 |
if (value != JalviewFileChooser.APPROVE_OPTION) |
145 |
|
{ |
146 |
0 |
String msg = MessageManager.formatMessage( |
147 |
|
"status.cancelled_image_export_operation", imageType.name); |
148 |
0 |
setStatus(msg, messageId); |
149 |
0 |
return; |
150 |
|
} |
151 |
0 |
Cache.setProperty("LAST_DIRECTORY", |
152 |
|
chooser.getSelectedFile().getParent()); |
153 |
0 |
file = chooser.getSelectedFile(); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
46 |
String renderStyle = renderer == null |
162 |
|
? Cache.getDefault(imageType.getName() + "_RENDERING", |
163 |
|
LineartOptions.PROMPT_EACH_TIME) |
164 |
|
: renderer; |
165 |
46 |
if (Platform.isJS()) |
166 |
|
{ |
167 |
0 |
renderStyle = "Text"; |
168 |
|
} |
169 |
46 |
AtomicBoolean textSelected = new AtomicBoolean( |
170 |
|
!StringUtils.equalsIgnoreCase("lineart", renderStyle)); |
171 |
46 |
if ((imageType == TYPE.EPS || imageType == TYPE.SVG) && StringUtils |
172 |
|
.equalsIgnoreCase(LineartOptions.PROMPT_EACH_TIME, renderStyle) |
173 |
|
&& !Jalview.isHeadlessMode()) |
174 |
|
{ |
175 |
0 |
final File chosenFile = file; |
176 |
0 |
Runnable okAction = () -> { |
177 |
0 |
exportImage(chosenFile, !textSelected.get(), width, height, |
178 |
|
messageId, userBis); |
179 |
|
}; |
180 |
0 |
LineartOptions epsOption = new LineartOptions(TYPE.EPS.getName(), |
181 |
|
textSelected); |
182 |
0 |
epsOption.setResponseAction(1, () -> { |
183 |
0 |
setStatus(MessageManager.formatMessage( |
184 |
|
"status.cancelled_image_export_operation", |
185 |
|
imageType.getName()), messageId); |
186 |
|
}); |
187 |
0 |
epsOption.setResponseAction(0, okAction); |
188 |
0 |
epsOption.showDialog(); |
189 |
|
|
190 |
|
} |
191 |
|
else |
192 |
|
{ |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
46 |
exportImage(file, !textSelected.get(), width, height, messageId, |
198 |
|
userBis); |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@param |
208 |
|
@param |
209 |
|
@param |
210 |
|
@param |
211 |
|
@param |
212 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
213 |
46 |
protected void exportImage(File chosenFile, boolean asLineart, int width,... |
214 |
|
int height, long messageId, BitmapImageSizing userBis) |
215 |
|
{ |
216 |
46 |
String type = imageType.getName(); |
217 |
46 |
try |
218 |
|
{ |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
46 |
ImageMaker im = new ImageMaker(imageType, width, height, chosenFile, |
224 |
|
title, asLineart, userBis); |
225 |
46 |
imageWriter.exportImage(im.getGraphics()); |
226 |
46 |
im.writeImage(); |
227 |
46 |
setStatus( |
228 |
|
MessageManager.formatMessage("status.export_complete", type), |
229 |
|
messageId); |
230 |
|
} catch (Exception e) |
231 |
|
{ |
232 |
0 |
jalview.bin.Console.error(String.format("Error creating %s file: %s", |
233 |
|
type, e.toString()), e); |
234 |
0 |
setStatus(MessageManager.formatMessage("info.error_creating_file", |
235 |
|
type), messageId); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
@param |
243 |
|
@param |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
245 |
92 |
void setStatus(String msg, long id)... |
246 |
|
{ |
247 |
92 |
if (messageBoard != null && !Jalview.isHeadlessMode()) |
248 |
|
{ |
249 |
26 |
messageBoard.setProgressBar(msg, id); |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
} |