Lines 45-50
Link Here
|
45 |
import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin; |
45 |
import org.eclipse.gmf.runtime.diagram.ui.render.internal.DiagramUIRenderPlugin; |
46 |
import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil; |
46 |
import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil; |
47 |
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageExporter; |
47 |
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.image.ImageExporter; |
|
|
48 |
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage; |
49 |
import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImageConverter; |
48 |
import org.eclipse.gmf.runtime.notation.Diagram; |
50 |
import org.eclipse.gmf.runtime.notation.Diagram; |
49 |
import org.eclipse.swt.graphics.Image; |
51 |
import org.eclipse.swt.graphics.Image; |
50 |
import org.eclipse.swt.graphics.ImageData; |
52 |
import org.eclipse.swt.graphics.ImageData; |
Lines 196-202
Link Here
|
196 |
* @return appropriate diagram generator |
198 |
* @return appropriate diagram generator |
197 |
*/ |
199 |
*/ |
198 |
protected DiagramGenerator getDiagramGenerator(DiagramEditPart diagramEP, ImageFileFormat format) { |
200 |
protected DiagramGenerator getDiagramGenerator(DiagramEditPart diagramEP, ImageFileFormat format) { |
199 |
if (format.equals(ImageFileFormat.SVG)) { |
201 |
if (format.equals(ImageFileFormat.SVG) || format.equals(ImageFileFormat.PDF)) { |
200 |
return new DiagramSVGGenerator(diagramEP); |
202 |
return new DiagramSVGGenerator(diagramEP); |
201 |
} else { |
203 |
} else { |
202 |
return new DiagramImageGenerator(diagramEP); |
204 |
return new DiagramImageGenerator(diagramEP); |
Lines 227-236
Link Here
|
227 |
ImageFileFormat format, IProgressMonitor monitor) |
229 |
ImageFileFormat format, IProgressMonitor monitor) |
228 |
throws CoreException { |
230 |
throws CoreException { |
229 |
boolean found = false; |
231 |
boolean found = false; |
230 |
if (format.equals(ImageFileFormat.SVG)) { |
232 |
if (format.equals(ImageFileFormat.SVG) |
|
|
233 |
|| format.equals(ImageFileFormat.PDF)) { |
231 |
gen.createSWTImageDescriptorForParts(editParts, imageRect); |
234 |
gen.createSWTImageDescriptorForParts(editParts, imageRect); |
232 |
monitor.worked(1); |
235 |
monitor.worked(1); |
233 |
saveSVGToFile(destination, (DiagramSVGGenerator) gen, monitor); |
236 |
saveToFile(destination, (DiagramSVGGenerator) gen, format, monitor); |
234 |
found = true; |
237 |
found = true; |
235 |
} else if (format.equals(ImageFileFormat.JPEG) |
238 |
} else if (format.equals(ImageFileFormat.JPEG) |
236 |
|| format.equals(ImageFileFormat.PNG)) { |
239 |
|| format.equals(ImageFileFormat.PNG)) { |
Lines 304-309
Link Here
|
304 |
refreshLocal(destination); |
307 |
refreshLocal(destination); |
305 |
} |
308 |
} |
306 |
|
309 |
|
|
|
310 |
|
307 |
/** |
311 |
/** |
308 |
* Saves an SVG DOM to a file. |
312 |
* Saves an SVG DOM to a file. |
309 |
* |
313 |
* |
Lines 317-353
Link Here
|
317 |
* if this method fails |
321 |
* if this method fails |
318 |
*/ |
322 |
*/ |
319 |
protected void saveSVGToFile(IPath destination, |
323 |
protected void saveSVGToFile(IPath destination, |
320 |
DiagramSVGGenerator generator, IProgressMonitor monitor) |
324 |
DiagramSVGGenerator generator, IProgressMonitor monitor) |
321 |
throws CoreException { |
325 |
throws CoreException { |
322 |
|
326 |
saveToFile(destination, generator, ImageFileFormat.SVG, monitor); |
323 |
IStatus fileModificationStatus = createFile(destination); |
327 |
} |
324 |
if (!fileModificationStatus.isOK()) { |
|
|
325 |
// can't write to the file |
326 |
return; |
327 |
} |
328 |
|
328 |
|
329 |
monitor.worked(1); |
329 |
|
|
|
330 |
/** |
331 |
* Saves an SVG or PDF files. |
332 |
* |
333 |
* @param destination |
334 |
* the destination file, including path and file name |
335 |
* @param generator |
336 |
* the svg generator for a diagram, used to write |
337 |
* @param format |
338 |
* currently supports SVG or PDF |
339 |
* @param monitor |
340 |
* the progress monitor |
341 |
* @exception CoreException |
342 |
* if this method fails |
343 |
*/ |
344 |
protected void saveToFile(IPath destination, |
345 |
DiagramSVGGenerator generator, ImageFileFormat format, IProgressMonitor monitor) |
346 |
throws CoreException { |
330 |
|
347 |
|
331 |
try { |
348 |
IStatus fileModificationStatus = createFile(destination); |
|
|
349 |
if (!fileModificationStatus.isOK()) { |
350 |
// can't write to the file |
351 |
return; |
352 |
} |
353 |
monitor.worked(1); |
332 |
|
354 |
|
333 |
FileOutputStream os = new FileOutputStream(destination.toOSString()); |
355 |
try { |
334 |
monitor.worked(1); |
356 |
FileOutputStream os = new FileOutputStream(destination.toOSString()); |
|
|
357 |
monitor.worked(1); |
335 |
|
358 |
|
336 |
generator.stream(os); |
359 |
if (format == ImageFileFormat.PDF) { |
337 |
monitor.worked(1); |
360 |
SVGImageConverter.exportToPDF((SVGImage) generator.getRenderedImage(), os); |
|
|
361 |
} else if (format == ImageFileFormat.SVG) { |
362 |
generator.stream(os); |
363 |
} else { |
364 |
throw new IllegalArgumentException( |
365 |
"Unexpected format: " + format.getName()); //$NON-NLS-1$ |
366 |
} |
367 |
monitor.worked(1); |
338 |
|
368 |
|
339 |
os.close(); |
369 |
os.close(); |
340 |
monitor.worked(1); |
370 |
monitor.worked(1); |
341 |
refreshLocal(destination); |
371 |
refreshLocal(destination); |
342 |
} catch (IOException ex) { |
372 |
} catch (IOException ex) { |
343 |
Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex |
373 |
Log.error(DiagramUIRenderPlugin.getInstance(), IStatus.ERROR, ex |
344 |
.getMessage(), ex); |
374 |
.getMessage(), ex); |
345 |
IStatus status = |
375 |
IStatus status = new Status(IStatus.ERROR, |
346 |
new Status(IStatus.ERROR, "exportToFile", IStatus.OK, //$NON-NLS-1$ |
376 |
"exportToFile", IStatus.OK, //$NON-NLS-1$ |
347 |
ex.getMessage(), null); |
377 |
ex.getMessage(), null); |
348 |
throw new CoreException(status); |
378 |
throw new CoreException(status); |
349 |
} |
379 |
} |
350 |
} |
380 |
} |
|
|
381 |
|
382 |
|
383 |
|
351 |
|
384 |
|
352 |
/** |
385 |
/** |
353 |
* create a file in the workspace if the destination is in a project in the |
386 |
* create a file in the workspace if the destination is in a project in the |