use of org.gephi.preview.api.PreviewController in project gephi by gephi.
the class PNGExporter method execute.
@Override
public boolean execute() {
Progress.start(progress);
PreviewController ctrl = Lookup.getDefault().lookup(PreviewController.class);
PreviewModel m = ctrl.getModel(workspace);
setExportProperties(m);
ctrl.refreshPreview(workspace);
target = (G2DTarget) ctrl.getRenderTarget(RenderTarget.G2D_TARGET, workspace);
if (target instanceof LongTask) {
((LongTask) target).setProgressTicket(progress);
}
try {
target.refresh();
Progress.switchToIndeterminate(progress);
Image sourceImg = target.getImage();
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
img.getGraphics().drawImage(sourceImg, 0, 0, null);
ImageIO.write(img, "png", stream);
stream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
discardExportProperties(m);
Progress.finish(progress);
return !cancel;
}
use of org.gephi.preview.api.PreviewController in project gephi by gephi.
the class SVGExporter method execute.
@Override
public boolean execute() {
PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
controller.refreshPreview(workspace);
PreviewProperties props = controller.getModel(workspace).getProperties();
props.putValue(SVGTarget.SCALE_STROKES, scaleStrokes);
props.putValue(PreviewProperty.MARGIN, new Float((float) margin));
target = (SVGTarget) controller.getRenderTarget(RenderTarget.SVG_TARGET, workspace);
if (target instanceof LongTask) {
((LongTask) target).setProgressTicket(progress);
}
try {
controller.render(target, workspace);
// creates SVG-to-SVG transcoder
SVGTranscoder t = new SVGTranscoder();
t.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
// sets transcoder input and output
TranscoderInput input = new TranscoderInput(target.getDocument());
// performs transcoding
try {
TranscoderOutput output = new TranscoderOutput(writer);
t.transcode(input, output);
} finally {
writer.close();
props.removeSimpleValue(PreviewProperty.MARGIN);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Progress.finish(progress);
return !cancel;
}
use of org.gephi.preview.api.PreviewController in project gephi by gephi.
the class PreviewWorkspaceDuplicateProvider method duplicate.
@Override
public void duplicate(Workspace source, Workspace destination) {
PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
PreviewModel sourceModel = previewController.getModel(source);
PreviewModel destModel = previewController.getModel(destination);
destModel.setManagedRenderers(sourceModel.getManagedRenderers());
for (PreviewProperty property : sourceModel.getProperties().getProperties()) {
destModel.getProperties().putValue(property.getName(), property.getValue());
}
for (Entry<String, Object> property : sourceModel.getProperties().getSimpleValues()) {
destModel.getProperties().putValue(property.getKey(), property.getValue());
}
}
Aggregations